From e80a3fa76a9645b4a90127deab5b271d8c5bcf85 Mon Sep 17 00:00:00 2001 From: David Howden Date: Mon, 2 Apr 2018 11:06:41 +1000 Subject: [PATCH] update to use new io.Seek consts, require min go1.7 --- .travis.yml | 2 +- cmd/check/main.go | 3 ++- flac.go | 3 +-- id.go | 7 +++---- id3v1.go | 3 +-- mp4.go | 5 ++--- ogg.go | 13 ++++++------- sum.go | 15 +++++++-------- tag.go | 3 +-- 9 files changed, 24 insertions(+), 30 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8408fb7..3a81bf9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ language: go go: - - 1.4 + - 1.7 - tip \ No newline at end of file diff --git a/cmd/check/main.go b/cmd/check/main.go index f8370ef..6f4c2af 100644 --- a/cmd/check/main.go +++ b/cmd/check/main.go @@ -10,6 +10,7 @@ package main import ( "flag" "fmt" + "io" "net/url" "os" "path/filepath" @@ -175,7 +176,7 @@ func (p *processor) do(ch <-chan string) { } if *sum { - _, err = tf.Seek(0, os.SEEK_SET) + _, err = tf.Seek(0, io.SeekStart) if err != nil { fmt.Println("DIED:", path, "error seeking back to 0:", err) return diff --git a/flac.go b/flac.go index 3221be2..c370467 100644 --- a/flac.go +++ b/flac.go @@ -7,7 +7,6 @@ package tag import ( "errors" "io" - "os" ) // blockType is a type which represents an enumeration of valid FLAC blocks @@ -80,7 +79,7 @@ func (m *metadataFLAC) readFLACMetadataBlock(r io.ReadSeeker) (last bool, err er err = m.readPictureBlock(r) default: - _, err = r.Seek(int64(blockLen), os.SEEK_CUR) + _, err = r.Seek(int64(blockLen), io.SeekCurrent) } return } diff --git a/id.go b/id.go index 4670192..2410356 100644 --- a/id.go +++ b/id.go @@ -3,7 +3,6 @@ package tag import ( "fmt" "io" - "os" ) // Identify identifies the format and file type of the data in the ReadSeeker. @@ -13,7 +12,7 @@ func Identify(r io.ReadSeeker) (format Format, fileType FileType, err error) { return } - _, err = r.Seek(-11, os.SEEK_CUR) + _, err = r.Seek(-11, io.SeekCurrent) if err != nil { err = fmt.Errorf("could not seek back to original position: %v", err) return @@ -59,7 +58,7 @@ func Identify(r io.ReadSeeker) (format Format, fileType FileType, err error) { return format, MP3, nil } - n, err := r.Seek(-128, os.SEEK_END) + n, err := r.Seek(-128, io.SeekEnd) if err != nil { return } @@ -69,7 +68,7 @@ func Identify(r io.ReadSeeker) (format Format, fileType FileType, err error) { return } - _, err = r.Seek(-n, os.SEEK_CUR) + _, err = r.Seek(-n, io.SeekCurrent) if err != nil { return } diff --git a/id3v1.go b/id3v1.go index c203eb1..3703a7d 100644 --- a/id3v1.go +++ b/id3v1.go @@ -7,7 +7,6 @@ package tag import ( "errors" "io" - "os" "strconv" "strings" ) @@ -44,7 +43,7 @@ var ErrNotID3v1 = errors.New("invalid ID3v1 header") // ReadID3v1Tags reads ID3v1 tags from the io.ReadSeeker. Returns ErrNotID3v1 // if there are no ID3v1 tags, otherwise non-nil error if there was a problem. func ReadID3v1Tags(r io.ReadSeeker) (Metadata, error) { - _, err := r.Seek(-128, os.SEEK_END) + _, err := r.Seek(-128, io.SeekEnd) if err != nil { return nil, err } diff --git a/mp4.go b/mp4.go index 239bcae..a6e3472 100644 --- a/mp4.go +++ b/mp4.go @@ -10,7 +10,6 @@ import ( "errors" "fmt" "io" - "os" "strconv" ) @@ -113,7 +112,7 @@ func (m metadataMP4) readAtoms(r io.ReadSeeker) error { } if !ok { - _, err := r.Seek(int64(size-8), os.SEEK_CUR) + _, err := r.Seek(int64(size-8), io.SeekCurrent) if err != nil { return err } @@ -246,7 +245,7 @@ func readCustomAtom(r io.ReadSeeker, size uint32) (string, uint32, error) { case "data": // Found the "data" atom, rewind dataSize = subSize + 8 // will need to re-read "data" + size (4 + 4) - _, err := r.Seek(-8, os.SEEK_CUR) + _, err := r.Seek(-8, io.SeekCurrent) if err != nil { return "", 0, err } diff --git a/ogg.go b/ogg.go index 81f257d..bc26d4a 100644 --- a/ogg.go +++ b/ogg.go @@ -7,7 +7,6 @@ package tag import ( "errors" "io" - "os" ) const ( @@ -30,7 +29,7 @@ func ReadOGGTags(r io.ReadSeeker) (Metadata, error) { // Skip 22 bytes of Page header to read page_segments length byte at position 26 // See http://www.xiph.org/ogg/doc/framing.html - _, err = r.Seek(22, os.SEEK_CUR) + _, err = r.Seek(22, io.SeekCurrent) if err != nil { return nil, err } @@ -41,7 +40,7 @@ func ReadOGGTags(r io.ReadSeeker) (Metadata, error) { } // Seek and discard the segments - _, err = r.Seek(int64(nS), os.SEEK_CUR) + _, err = r.Seek(int64(nS), io.SeekCurrent) if err != nil { return nil, err } @@ -57,7 +56,7 @@ func ReadOGGTags(r io.ReadSeeker) (Metadata, error) { // Seek and discard 29 bytes from common and identification header // See http://www.xiph.org/vorbis/doc/Vorbis_I_spec.html#x1-610004.2 - _, err = r.Seek(29, os.SEEK_CUR) + _, err = r.Seek(29, io.SeekCurrent) if err != nil { return nil, err } @@ -73,7 +72,7 @@ func ReadOGGTags(r io.ReadSeeker) (Metadata, error) { } // Skip page 2 header, same as line 30 - _, err = r.Seek(22, os.SEEK_CUR) + _, err = r.Seek(22, io.SeekCurrent) if err != nil { return nil, err } @@ -83,7 +82,7 @@ func ReadOGGTags(r io.ReadSeeker) (Metadata, error) { return nil, err } - _, err = r.Seek(int64(nS), os.SEEK_CUR) + _, err = r.Seek(int64(nS), io.SeekCurrent) if err != nil { return nil, err } @@ -98,7 +97,7 @@ func ReadOGGTags(r io.ReadSeeker) (Metadata, error) { } // Seek and discard 6 bytes from common header - _, err = r.Seek(6, os.SEEK_CUR) + _, err = r.Seek(6, io.SeekCurrent) if err != nil { return nil, err } diff --git a/sum.go b/sum.go index bc51658..97b27a7 100644 --- a/sum.go +++ b/sum.go @@ -7,7 +7,6 @@ import ( "fmt" "hash" "io" - "os" ) // Sum creates a checksum of the audio file data provided by the io.ReadSeeker which is metadata @@ -18,7 +17,7 @@ func Sum(r io.ReadSeeker) (string, error) { return "", err } - _, err = r.Seek(-11, os.SEEK_CUR) + _, err = r.Seek(-11, io.SeekCurrent) if err != nil { return "", fmt.Errorf("could not seek back to original position: %v", err) } @@ -75,7 +74,7 @@ func SumAtoms(r io.ReadSeeker) (string, error) { switch name { case "meta": // next_item_id (int32) - _, err := r.Seek(4, os.SEEK_CUR) + _, err := r.Seek(4, io.SeekCurrent) if err != nil { return "", err } @@ -93,7 +92,7 @@ func SumAtoms(r io.ReadSeeker) (string, error) { return hashSum(h), nil } - _, err = r.Seek(int64(size-8), os.SEEK_CUR) + _, err = r.Seek(int64(size-8), io.SeekCurrent) if err != nil { return "", fmt.Errorf("error reading '%v' tag: %v", name, err) } @@ -101,12 +100,12 @@ func SumAtoms(r io.ReadSeeker) (string, error) { } func sizeToEndOffset(r io.ReadSeeker, offset int64) (int64, error) { - n, err := r.Seek(-128, os.SEEK_END) + n, err := r.Seek(-128, io.SeekEnd) if err != nil { return 0, fmt.Errorf("error seeking end offset (%d bytes): %v", offset, err) } - _, err = r.Seek(-n, os.SEEK_CUR) + _, err = r.Seek(-n, io.SeekCurrent) if err != nil { return 0, fmt.Errorf("error seeking back to original position: %v", err) } @@ -142,7 +141,7 @@ func SumID3v2(r io.ReadSeeker) (string, error) { return "", fmt.Errorf("error reading ID3v2 header: %v", err) } - _, err = r.Seek(int64(header.Size), os.SEEK_CUR) + _, err = r.Seek(int64(header.Size), io.SeekCurrent) if err != nil { return "", fmt.Errorf("error seeking to end of ID3V2 header: %v", err) } @@ -211,7 +210,7 @@ func skipFLACMetadataBlock(r io.ReadSeeker) (last bool, err error) { return } - _, err = r.Seek(int64(blockLen), os.SEEK_CUR) + _, err = r.Seek(int64(blockLen), io.SeekCurrent) return } diff --git a/tag.go b/tag.go index 1e2f97a..edffac1 100644 --- a/tag.go +++ b/tag.go @@ -18,7 +18,6 @@ import ( "errors" "fmt" "io" - "os" ) // ErrNoTagsFound is the error returned by ReadFrom when the metadata format @@ -34,7 +33,7 @@ func ReadFrom(r io.ReadSeeker) (Metadata, error) { return nil, err } - _, err = r.Seek(-11, os.SEEK_CUR) + _, err = r.Seek(-11, io.SeekCurrent) if err != nil { return nil, fmt.Errorf("could not seek back to original position: %v", err) }