From c119c3eeeb2578424fdaef4745cd744f6ccd5a5e Mon Sep 17 00:00:00 2001 From: upperstream Date: Sat, 9 Jul 2016 17:16:33 +0900 Subject: [PATCH 1/5] Add tests for ID3v1 and ID3v1.1. --- .gitignore | 1 + id3v1_test.go | 39 +++++++++++++++++++++++++++++ id3v1_test/NOTICE.txt | 3 +++ id3v1_test/sample_ms932_v1.1.mp3 | Bin 0 -> 344 bytes id3v1_test/sample_ms932_v1.mp3 | Bin 0 -> 344 bytes id3v1_test/sample_usascii_v1.1.mp3 | Bin 0 -> 344 bytes id3v1_test/sample_usascii_v1.mp3 | Bin 0 -> 344 bytes id3v1_test/sample_utf8_v1.1.mp3 | Bin 0 -> 344 bytes id3v1_test/sample_utf8_v1.mp3 | Bin 0 -> 344 bytes 9 files changed, 43 insertions(+) create mode 100644 .gitignore create mode 100644 id3v1_test.go create mode 100644 id3v1_test/NOTICE.txt create mode 100644 id3v1_test/sample_ms932_v1.1.mp3 create mode 100644 id3v1_test/sample_ms932_v1.mp3 create mode 100644 id3v1_test/sample_usascii_v1.1.mp3 create mode 100644 id3v1_test/sample_usascii_v1.mp3 create mode 100644 id3v1_test/sample_utf8_v1.1.mp3 create mode 100644 id3v1_test/sample_utf8_v1.mp3 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c650540 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/id3v1_testdata.go diff --git a/id3v1_test.go b/id3v1_test.go new file mode 100644 index 0000000..f0faad4 --- /dev/null +++ b/id3v1_test.go @@ -0,0 +1,39 @@ +// This file is subject to the CC0 1.0 Universal (CC0 1.0) Public Domain Dedication +// license. Its contents can be found at: +// http://creativecommons.org/publicdomain/zero/1.0 + +package tag + +import ( + "bytes" + "testing" +) + +//go:generate go-bindata -o id3v1_testdata.go -pkg tag -ignore .txt id3v1_test + +func TestReadID3v1Tags(t *testing.T) { + for _, name := range []string{ + "id3v1_test/sample_usascii_v1.mp3", + "id3v1_test/sample_ms932_v1.mp3", + "id3v1_test/sample_utf8_v1.mp3"} { + doTest(name, 0, 30, t) + } + for _, name := range []string{ + "id3v1_test/sample_usascii_v1.1.mp3", + "id3v1_test/sample_ms932_v1.1.mp3", + "id3v1_test/sample_utf8_v1.1.mp3"} { + doTest(name, 1, 28, t) + } +} + +func doTest(name string, track int, length int, t *testing.T) { + mp3 := MustAsset(name) + metadata, _ := ReadID3v1Tags(bytes.NewReader(mp3)) + if actual, total := metadata.Track(); actual != track || total != 0 { + t.Errorf("Track number for %s is (%d, %d) where (%d, 0) is expected.", name, actual, total, track) + } + comment := metadata.Raw()["comment"].(string) + if actual := len(comment); actual != length { + t.Errorf("Comment length for %s is %d where %d is expected", name, actual, length) + } +} diff --git a/id3v1_test/NOTICE.txt b/id3v1_test/NOTICE.txt new file mode 100644 index 0000000..f7e01d8 --- /dev/null +++ b/id3v1_test/NOTICE.txt @@ -0,0 +1,3 @@ +All files in this directory are subject to the CC0 1.0 Universal (CC0 1.0) +Public Domain Dedication license. Its contents can be found at: +http://creativecommons.org/publicdomain/zero/1.0 diff --git a/id3v1_test/sample_ms932_v1.1.mp3 b/id3v1_test/sample_ms932_v1.1.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..927f4b987089ca9687bb54833602304dfa7b37ff GIT binary patch literal 344 zcmezWSR#difq`)ekN^T^4-o0&=<8~%XKATt8cHnq4>ZRZ-5g>yBdG(KlSTz|LLA+j zLz*Wymo;}cooSA1c5Y5@?gse{29RVO8>5?3o1K~?n$xk#Hg`AYH#fj!K(wKyr9p6F hZb43}f=gmaqC$CQNrr-Nu%)q)g0YFInK=Wa3;-;OV!Z$W literal 0 HcmV?d00001 diff --git a/id3v1_test/sample_ms932_v1.mp3 b/id3v1_test/sample_ms932_v1.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..13493cfb3d913ff12f34d8256d591b3d6f142815 GIT binary patch literal 344 zcmezWSR#difq`)ekN^T^4-o0&=<8~%XKATt8cHnq4>ZRZ-5g>yBdG(KlSTz|LLA+j zLz*Wymo;}cooSA1c5Y5@?p8noNV1NN(aovNPR$X`=`aPzvd!Ji`OOV584zt~X=xCg im|KvOs^F4XlBiIgS(2gP8*FK8q+o1fYG!U>DFXmWv1cs+ literal 0 HcmV?d00001 diff --git a/id3v1_test/sample_usascii_v1.1.mp3 b/id3v1_test/sample_usascii_v1.1.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..3eb86df2ad27d9b8be51392ec8beed2e5c83b46f GIT binary patch literal 344 zcmezWSR#difq`)ekN^T^4-o0&=<8~%XKATt8cHnq4>ZRZ-5g>yBdG(KlSTz|LLA+L z6LSl4QWZinOL9^{zCs01S;wN1%;FMMDIgCfo0C+Uiy_HiXlZExRpF9YlBiIgS(2d; S8m#LW?Cj~OU}nz1C<6eN^iZRZ-5g>yBdG(KlSTz|LLA+L z6LSl4QWZinOMoN>fXX@+m1Gu|;FQftD$T`^R4}x(G=S=NNi0cJD9ZRZ-5g>yBdG(KlSTz|LLA*6 zH*I~~y!mnS^vBJsA2+Uh+_e93(~`%{9Y8M7j~KFx9yjlK+}!rKY4PKxo!DeoKW?7z sxOo9kuc4)-L2zPjK~AcIOJYf)LV0FMhC*nFn}vdrv5BdfIRm2%01cpk4gdfE literal 0 HcmV?d00001 diff --git a/id3v1_test/sample_utf8_v1.mp3 b/id3v1_test/sample_utf8_v1.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..d3aa4d59efc9078067aaf8aec0aa6eeccb6668e1 GIT binary patch literal 344 zcmezWSR#difq`)ekN^T^4-o0&=<8~%XKATt8cHnq4>ZRZ-5g>yBdG(KlSTz|LLA*6 zH*I~~y!mnS^vBJsA2+Uh+_e93(~`%{9YC&vf&zx@qQ}j99yhl=Zd&}fX(u+>)sLGe tJZ@e9)N5#IX%L*4Tac5g;F4I9s8F6+lA#b9;%1>>WNcz;W^Q3A0{}qyfj$5L literal 0 HcmV?d00001 From ae005145bc400841e1e279742faa5f863af0dc6c Mon Sep 17 00:00:00 2001 From: upperstream Date: Sat, 9 Jul 2016 17:49:28 +0900 Subject: [PATCH 2/5] Fix: Track() for ID3v1.1 picked a wrong byte for the track number delimeter in the comment field. This results in neither the track number nor the comment being set properly. --- id3v1.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/id3v1.go b/id3v1.go index 8e66e22..00ad891 100644 --- a/id3v1.go +++ b/id3v1.go @@ -75,16 +75,16 @@ func ReadID3v1Tags(r io.ReadSeeker) (Metadata, error) { return nil, err } - commentBytes, err := readBytes(r, 29) + commentBytes, err := readBytes(r, 30) if err != nil { return nil, err } var comment string var track int - if commentBytes[27] == 0 { + if commentBytes[28] == 0 { comment = strings.TrimSpace(string(commentBytes[:28])) - track = int(commentBytes[28]) + track = int(commentBytes[29]) } var genre string From abfb4860c42f2c149e8c7471efe6c5d01eb4859c Mon Sep 17 00:00:00 2001 From: upperstream Date: Sat, 9 Jul 2016 18:02:50 +0900 Subject: [PATCH 3/5] Fix: metadataID3v1 did not set the value for "comment" key unless the tag is ID3v1.1. --- id3v1.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/id3v1.go b/id3v1.go index 00ad891..c203eb1 100644 --- a/id3v1.go +++ b/id3v1.go @@ -85,6 +85,8 @@ func ReadID3v1Tags(r io.ReadSeeker) (Metadata, error) { if commentBytes[28] == 0 { comment = strings.TrimSpace(string(commentBytes[:28])) track = int(commentBytes[29]) + } else { + comment = strings.TrimSpace(string(commentBytes)) } var genre string From f16224df21fdc2f401b5cfbc24d72d3832f21a61 Mon Sep 17 00:00:00 2001 From: upperstream Date: Mon, 11 Jul 2016 23:16:30 +0900 Subject: [PATCH 4/5] Add generated source file containing test data. --- .gitignore | 1 - id3v1_test.go | 5 +- id3v1_test/id3v1_testdata.go | 352 +++++++++++++++++++++++++++++++++++ 3 files changed, 355 insertions(+), 3 deletions(-) delete mode 100644 .gitignore create mode 100644 id3v1_test/id3v1_testdata.go diff --git a/.gitignore b/.gitignore deleted file mode 100644 index c650540..0000000 --- a/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/id3v1_testdata.go diff --git a/id3v1_test.go b/id3v1_test.go index f0faad4..ec0295b 100644 --- a/id3v1_test.go +++ b/id3v1_test.go @@ -5,11 +5,12 @@ package tag import ( + "./id3v1_test" "bytes" "testing" ) -//go:generate go-bindata -o id3v1_testdata.go -pkg tag -ignore .txt id3v1_test +//go:generate go-bindata -o id3v1_test/id3v1_testdata.go -pkg id3v1_test -ignore .txt -ignore .go id3v1_test func TestReadID3v1Tags(t *testing.T) { for _, name := range []string{ @@ -27,7 +28,7 @@ func TestReadID3v1Tags(t *testing.T) { } func doTest(name string, track int, length int, t *testing.T) { - mp3 := MustAsset(name) + mp3 := id3v1_test.MustAsset(name) metadata, _ := ReadID3v1Tags(bytes.NewReader(mp3)) if actual, total := metadata.Track(); actual != track || total != 0 { t.Errorf("Track number for %s is (%d, %d) where (%d, 0) is expected.", name, actual, total, track) diff --git a/id3v1_test/id3v1_testdata.go b/id3v1_test/id3v1_testdata.go new file mode 100644 index 0000000..7b8a722 --- /dev/null +++ b/id3v1_test/id3v1_testdata.go @@ -0,0 +1,352 @@ +// Code generated by go-bindata. +// sources: +// id3v1_test/sample_ms932_v1.1.mp3 +// id3v1_test/sample_ms932_v1.mp3 +// id3v1_test/sample_usascii_v1.1.mp3 +// id3v1_test/sample_usascii_v1.mp3 +// id3v1_test/sample_utf8_v1.1.mp3 +// id3v1_test/sample_utf8_v1.mp3 +// DO NOT EDIT! + +package id3v1_test + +import ( + "bytes" + "compress/gzip" + "fmt" + "io" + "io/ioutil" + "os" + "path/filepath" + "strings" + "time" +) + +func bindataRead(data []byte, name string) ([]byte, error) { + gz, err := gzip.NewReader(bytes.NewBuffer(data)) + if err != nil { + return nil, fmt.Errorf("Read %q: %v", name, err) + } + + var buf bytes.Buffer + _, err = io.Copy(&buf, gz) + clErr := gz.Close() + + if err != nil { + return nil, fmt.Errorf("Read %q: %v", name, err) + } + if clErr != nil { + return nil, err + } + + return buf.Bytes(), nil +} + +type asset struct { + bytes []byte + info os.FileInfo +} + +type bindataFileInfo struct { + name string + size int64 + mode os.FileMode + modTime time.Time +} + +func (fi bindataFileInfo) Name() string { + return fi.name +} +func (fi bindataFileInfo) Size() int64 { + return fi.size +} +func (fi bindataFileInfo) Mode() os.FileMode { + return fi.mode +} +func (fi bindataFileInfo) ModTime() time.Time { + return fi.modTime +} +func (fi bindataFileInfo) IsDir() bool { + return false +} +func (fi bindataFileInfo) Sys() interface{} { + return nil +} + +var _id3v1_testSample_ms932_v11Mp3 = []byte("\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\xfa\xff\x58\x22\x85\x81\x81\x81\x71\x09\x03\x18\x30\x7b\x80\x48\x1f\x47\x5f\x57\x63\x3d\x4b\x4b\x3d\xd3\x50\x62\x01\xc8\x1c\x63\x74\x73\x88\xd6\x8d\x6a\x4e\x1a\x15\xcc\x09\x71\x74\x6f\x0e\x69\x9e\xdc\x5c\xd6\xdc\xdd\x74\xa6\x39\xae\xd9\xb9\x39\xbd\xb9\x9b\x01\x09\x20\xc9\x3a\x36\x46\x37\xa7\x36\x3b\x35\x47\x34\xa7\x63\x93\x6d\xee\x6e\xce\x6f\x6e\x40\xd6\x6b\x68\x69\x69\x10\x9c\x98\x5b\x90\x93\xaa\xe0\x92\x58\x92\xa8\x50\x9e\x59\x92\xa1\xe0\x1b\x6c\x69\x6c\xa4\x60\x6c\x62\x6a\x66\xce\xc0\x28\x03\x08\x00\x00\xff\xff\x9d\x69\xa1\x40\x58\x01\x00\x00") + +func id3v1_testSample_ms932_v11Mp3Bytes() ([]byte, error) { + return bindataRead( + _id3v1_testSample_ms932_v11Mp3, + "id3v1_test/sample_ms932_v1.1.mp3", + ) +} + +func id3v1_testSample_ms932_v11Mp3() (*asset, error) { + bytes, err := id3v1_testSample_ms932_v11Mp3Bytes() + if err != nil { + return nil, err + } + + info := bindataFileInfo{name: "id3v1_test/sample_ms932_v1.1.mp3", size: 344, mode: os.FileMode(438), modTime: time.Unix(1468246151, 0)} + a := &asset{bytes: bytes, info: info} + return a, nil +} + +var _id3v1_testSample_ms932_v1Mp3 = []byte("\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\xfa\xff\x58\x22\x85\x81\x81\x81\x71\x09\x03\x18\x30\x7b\x80\x48\x1f\x47\x5f\x57\x63\x3d\x4b\x4b\x3d\xd3\x50\x62\x01\xc8\x1c\x63\x74\x73\x88\xd6\x8d\x6a\x4e\x1a\x15\xcc\x09\x71\x74\x6f\x0e\x69\x9e\xdc\x5c\xd6\xdc\xdd\x74\xa6\x39\xae\xd9\xb9\x39\xbd\xb9\x5b\x01\x09\x20\xc9\x3a\x36\x46\x37\xa7\x36\x3b\x35\x47\x34\xa7\x63\x93\x6d\xee\x6e\xce\x6f\x6e\x40\xd6\x6b\x68\x69\x69\x10\x9c\x98\x5b\x90\x93\xaa\xe0\x92\x58\x92\xa8\x50\x9e\x59\x92\xa1\xe0\x1b\x6c\x69\x6c\xa4\x60\x6c\x62\x6a\x66\x6e\x61\x29\x03\x08\x00\x00\xff\xff\xfa\x22\x50\xe2\x58\x01\x00\x00") + +func id3v1_testSample_ms932_v1Mp3Bytes() ([]byte, error) { + return bindataRead( + _id3v1_testSample_ms932_v1Mp3, + "id3v1_test/sample_ms932_v1.mp3", + ) +} + +func id3v1_testSample_ms932_v1Mp3() (*asset, error) { + bytes, err := id3v1_testSample_ms932_v1Mp3Bytes() + if err != nil { + return nil, err + } + + info := bindataFileInfo{name: "id3v1_test/sample_ms932_v1.mp3", size: 344, mode: os.FileMode(438), modTime: time.Unix(1468246151, 0)} + a := &asset{bytes: bytes, info: info} + return a, nil +} + +var _id3v1_testSample_usascii_v11Mp3 = []byte("\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\xfa\xff\x58\x22\x85\x81\x81\x81\x71\x09\x03\x18\x30\x7b\x80\x48\x1f\x47\x5f\x57\x63\x3d\x4b\x4b\x3d\xd3\x50\x62\x01\xc8\x1c\x63\x74\x73\x88\xd6\x8d\x6a\x4e\x1a\x15\xcc\x09\x71\x74\x0f\x4e\xcc\x2d\xc8\x49\x55\x08\xc9\x2c\xc9\x49\x65\xc0\x00\x50\x59\xc7\xa2\x92\xcc\xe2\x12\x9c\xb2\x39\x49\xa5\xb9\x98\x7a\x0d\x2d\x2d\x0d\xa0\x2a\x5c\x12\x4b\x12\x15\xca\x33\x4b\x32\x14\x42\x83\x75\x1d\x83\x9d\x3d\x3d\x15\xcc\xcc\x19\x18\x65\x00\x01\x00\x00\xff\xff\x0b\x7f\x35\x28\x58\x01\x00\x00") + +func id3v1_testSample_usascii_v11Mp3Bytes() ([]byte, error) { + return bindataRead( + _id3v1_testSample_usascii_v11Mp3, + "id3v1_test/sample_usascii_v1.1.mp3", + ) +} + +func id3v1_testSample_usascii_v11Mp3() (*asset, error) { + bytes, err := id3v1_testSample_usascii_v11Mp3Bytes() + if err != nil { + return nil, err + } + + info := bindataFileInfo{name: "id3v1_test/sample_usascii_v1.1.mp3", size: 344, mode: os.FileMode(438), modTime: time.Unix(1468246151, 0)} + a := &asset{bytes: bytes, info: info} + return a, nil +} + +var _id3v1_testSample_usascii_v1Mp3 = []byte("\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\xfa\xff\x58\x22\x85\x81\x81\x81\x71\x09\x03\x18\x30\x7b\x80\x48\x1f\x47\x5f\x57\x63\x3d\x4b\x4b\x3d\xd3\x50\x62\x01\xc8\x1c\x63\x74\x73\x88\xd6\x8d\x6a\x4e\x1a\x15\xcc\x09\x71\x74\x0f\x4e\xcc\x2d\xc8\x49\x55\x08\xc9\x2c\x01\x92\x18\x00\x2a\xeb\x58\x54\x92\x59\x5c\x82\x53\x36\x27\xa9\x34\x17\x53\xaf\xa1\xa5\xa5\x01\x54\x85\x4b\x62\x49\xa2\x42\x79\x66\x49\x86\x42\x68\xb0\xae\x63\xb0\xb3\xa7\xa7\x82\x99\xb9\x85\xa5\x0c\x20\x00\x00\xff\xff\x2f\x76\xcd\x7e\x58\x01\x00\x00") + +func id3v1_testSample_usascii_v1Mp3Bytes() ([]byte, error) { + return bindataRead( + _id3v1_testSample_usascii_v1Mp3, + "id3v1_test/sample_usascii_v1.mp3", + ) +} + +func id3v1_testSample_usascii_v1Mp3() (*asset, error) { + bytes, err := id3v1_testSample_usascii_v1Mp3Bytes() + if err != nil { + return nil, err + } + + info := bindataFileInfo{name: "id3v1_test/sample_usascii_v1.mp3", size: 344, mode: os.FileMode(438), modTime: time.Unix(1468246151, 0)} + a := &asset{bytes: bytes, info: info} + return a, nil +} + +var _id3v1_testSample_utf8_v11Mp3 = []byte("\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\xfa\xff\x58\x22\x85\x81\x81\x81\x71\x09\x03\x18\x30\x7b\x80\x48\x1f\x47\x5f\x57\x63\x3d\x4b\x4b\x3d\xd3\x50\x62\x01\xc8\x1c\x63\x74\x73\x88\xd6\x8d\x6a\x4e\x1a\x15\xcc\x09\x71\x74\x7f\xdc\xb4\xf5\x71\xf3\xe6\xc7\xcd\xd3\x1f\x37\xaf\x7e\xdc\xb8\xee\x71\xd3\xfe\xc7\x4d\x4b\x1e\x37\x77\x00\xb9\x40\x33\x31\x64\x17\x3d\x6e\xde\xf3\xb8\xb9\xed\x71\xd3\xe2\xc7\x4d\x3b\xb1\xc9\xae\x7e\xdc\x3c\xe1\x71\xf3\x02\xa0\x5e\x43\x4b\x4b\x83\xe0\xc4\xdc\x82\x9c\x54\x05\x97\xc4\x92\x44\x85\xf2\xcc\x92\x0c\x85\xd0\x10\x37\x0b\x05\x23\x63\x13\x53\x33\x73\x06\x46\x19\x40\x00\x00\x00\xff\xff\x0c\x8a\xd5\x94\x58\x01\x00\x00") + +func id3v1_testSample_utf8_v11Mp3Bytes() ([]byte, error) { + return bindataRead( + _id3v1_testSample_utf8_v11Mp3, + "id3v1_test/sample_utf8_v1.1.mp3", + ) +} + +func id3v1_testSample_utf8_v11Mp3() (*asset, error) { + bytes, err := id3v1_testSample_utf8_v11Mp3Bytes() + if err != nil { + return nil, err + } + + info := bindataFileInfo{name: "id3v1_test/sample_utf8_v1.1.mp3", size: 344, mode: os.FileMode(438), modTime: time.Unix(1468246151, 0)} + a := &asset{bytes: bytes, info: info} + return a, nil +} + +var _id3v1_testSample_utf8_v1Mp3 = []byte("\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\xfa\xff\x58\x22\x85\x81\x81\x81\x71\x09\x03\x18\x30\x7b\x80\x48\x1f\x47\x5f\x57\x63\x3d\x4b\x4b\x3d\xd3\x50\x62\x01\xc8\x1c\x63\x74\x73\x88\xd6\x8d\x6a\x4e\x1a\x15\xcc\x09\x71\x74\x7f\xdc\xb4\xf5\x71\xf3\xe6\xc7\xcd\xd3\x1f\x37\xaf\x7e\xdc\xb8\xee\x71\xd3\xfe\xc7\x4d\x4b\x1e\x37\x77\x00\xb9\x0a\x0a\x0a\x18\xb2\x8b\x1e\x37\xef\x79\xdc\xdc\xf6\xb8\x69\xf1\xe3\xa6\x9d\xd8\x64\x57\x3f\x6e\x9e\xf0\xb8\x79\x01\x50\xaf\xa1\xa5\xa5\x41\x70\x62\x6e\x41\x4e\xaa\x82\x4b\x62\x49\xa2\x42\x79\x66\x49\x86\x42\x68\x88\x9b\x85\x82\x91\xb1\x89\xa9\x99\xb9\x85\xa5\x0c\x20\x00\x00\xff\xff\x90\xde\x3d\x7d\x58\x01\x00\x00") + +func id3v1_testSample_utf8_v1Mp3Bytes() ([]byte, error) { + return bindataRead( + _id3v1_testSample_utf8_v1Mp3, + "id3v1_test/sample_utf8_v1.mp3", + ) +} + +func id3v1_testSample_utf8_v1Mp3() (*asset, error) { + bytes, err := id3v1_testSample_utf8_v1Mp3Bytes() + if err != nil { + return nil, err + } + + info := bindataFileInfo{name: "id3v1_test/sample_utf8_v1.mp3", size: 344, mode: os.FileMode(438), modTime: time.Unix(1468246151, 0)} + a := &asset{bytes: bytes, info: info} + return a, nil +} + +// Asset loads and returns the asset for the given name. +// It returns an error if the asset could not be found or +// could not be loaded. +func Asset(name string) ([]byte, error) { + cannonicalName := strings.Replace(name, "\\", "/", -1) + if f, ok := _bindata[cannonicalName]; ok { + a, err := f() + if err != nil { + return nil, fmt.Errorf("Asset %s can't read by error: %v", name, err) + } + return a.bytes, nil + } + return nil, fmt.Errorf("Asset %s not found", name) +} + +// MustAsset is like Asset but panics when Asset would return an error. +// It simplifies safe initialization of global variables. +func MustAsset(name string) []byte { + a, err := Asset(name) + if err != nil { + panic("asset: Asset(" + name + "): " + err.Error()) + } + + return a +} + +// AssetInfo loads and returns the asset info for the given name. +// It returns an error if the asset could not be found or +// could not be loaded. +func AssetInfo(name string) (os.FileInfo, error) { + cannonicalName := strings.Replace(name, "\\", "/", -1) + if f, ok := _bindata[cannonicalName]; ok { + a, err := f() + if err != nil { + return nil, fmt.Errorf("AssetInfo %s can't read by error: %v", name, err) + } + return a.info, nil + } + return nil, fmt.Errorf("AssetInfo %s not found", name) +} + +// AssetNames returns the names of the assets. +func AssetNames() []string { + names := make([]string, 0, len(_bindata)) + for name := range _bindata { + names = append(names, name) + } + return names +} + +// _bindata is a table, holding each asset generator, mapped to its name. +var _bindata = map[string]func() (*asset, error){ + "id3v1_test/sample_ms932_v1.1.mp3": id3v1_testSample_ms932_v11Mp3, + "id3v1_test/sample_ms932_v1.mp3": id3v1_testSample_ms932_v1Mp3, + "id3v1_test/sample_usascii_v1.1.mp3": id3v1_testSample_usascii_v11Mp3, + "id3v1_test/sample_usascii_v1.mp3": id3v1_testSample_usascii_v1Mp3, + "id3v1_test/sample_utf8_v1.1.mp3": id3v1_testSample_utf8_v11Mp3, + "id3v1_test/sample_utf8_v1.mp3": id3v1_testSample_utf8_v1Mp3, +} + +// AssetDir returns the file names below a certain +// directory embedded in the file by go-bindata. +// For example if you run go-bindata on data/... and data contains the +// following hierarchy: +// data/ +// foo.txt +// img/ +// a.png +// b.png +// then AssetDir("data") would return []string{"foo.txt", "img"} +// AssetDir("data/img") would return []string{"a.png", "b.png"} +// AssetDir("foo.txt") and AssetDir("notexist") would return an error +// AssetDir("") will return []string{"data"}. +func AssetDir(name string) ([]string, error) { + node := _bintree + if len(name) != 0 { + cannonicalName := strings.Replace(name, "\\", "/", -1) + pathList := strings.Split(cannonicalName, "/") + for _, p := range pathList { + node = node.Children[p] + if node == nil { + return nil, fmt.Errorf("Asset %s not found", name) + } + } + } + if node.Func != nil { + return nil, fmt.Errorf("Asset %s not found", name) + } + rv := make([]string, 0, len(node.Children)) + for childName := range node.Children { + rv = append(rv, childName) + } + return rv, nil +} + +type bintree struct { + Func func() (*asset, error) + Children map[string]*bintree +} +var _bintree = &bintree{nil, map[string]*bintree{ + "id3v1_test": &bintree{nil, map[string]*bintree{ + "sample_ms932_v1.1.mp3": &bintree{id3v1_testSample_ms932_v11Mp3, map[string]*bintree{}}, + "sample_ms932_v1.mp3": &bintree{id3v1_testSample_ms932_v1Mp3, map[string]*bintree{}}, + "sample_usascii_v1.1.mp3": &bintree{id3v1_testSample_usascii_v11Mp3, map[string]*bintree{}}, + "sample_usascii_v1.mp3": &bintree{id3v1_testSample_usascii_v1Mp3, map[string]*bintree{}}, + "sample_utf8_v1.1.mp3": &bintree{id3v1_testSample_utf8_v11Mp3, map[string]*bintree{}}, + "sample_utf8_v1.mp3": &bintree{id3v1_testSample_utf8_v1Mp3, map[string]*bintree{}}, + }}, +}} + +// RestoreAsset restores an asset under the given directory +func RestoreAsset(dir, name string) error { + data, err := Asset(name) + if err != nil { + return err + } + info, err := AssetInfo(name) + if err != nil { + return err + } + err = os.MkdirAll(_filePath(dir, filepath.Dir(name)), os.FileMode(0755)) + if err != nil { + return err + } + err = ioutil.WriteFile(_filePath(dir, name), data, info.Mode()) + if err != nil { + return err + } + err = os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime()) + if err != nil { + return err + } + return nil +} + +// RestoreAssets restores an asset under the given directory recursively +func RestoreAssets(dir, name string) error { + children, err := AssetDir(name) + // File + if err != nil { + return RestoreAsset(dir, name) + } + // Dir + for _, child := range children { + err = RestoreAssets(dir, filepath.Join(name, child)) + if err != nil { + return err + } + } + return nil +} + +func _filePath(dir, name string) string { + cannonicalName := strings.Replace(name, "\\", "/", -1) + return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...) +} + From 29306b74879c11fa6d1797f0cf0c757db974f212 Mon Sep 17 00:00:00 2001 From: upperstream Date: Sun, 17 Jul 2016 00:19:26 +0900 Subject: [PATCH 5/5] Move ID3v1 test data under `internal` directory * A relative path import is not used * Applications cannot access test data any longer --- id3v1_test.go | 17 +- id3v1_test/id3v1_testdata.go | 352 ----------------- .../id3v1_test}/NOTICE.txt | 0 internal/id3v1_test/id3v1_testdata.go | 354 ++++++++++++++++++ .../id3v1_test}/sample_ms932_v1.1.mp3 | Bin .../id3v1_test}/sample_ms932_v1.mp3 | Bin .../id3v1_test}/sample_usascii_v1.1.mp3 | Bin .../id3v1_test}/sample_usascii_v1.mp3 | Bin .../id3v1_test}/sample_utf8_v1.1.mp3 | Bin .../id3v1_test}/sample_utf8_v1.mp3 | Bin 10 files changed, 363 insertions(+), 360 deletions(-) delete mode 100644 id3v1_test/id3v1_testdata.go rename {id3v1_test => internal/id3v1_test}/NOTICE.txt (100%) create mode 100644 internal/id3v1_test/id3v1_testdata.go rename {id3v1_test => internal/id3v1_test}/sample_ms932_v1.1.mp3 (100%) rename {id3v1_test => internal/id3v1_test}/sample_ms932_v1.mp3 (100%) rename {id3v1_test => internal/id3v1_test}/sample_usascii_v1.1.mp3 (100%) rename {id3v1_test => internal/id3v1_test}/sample_usascii_v1.mp3 (100%) rename {id3v1_test => internal/id3v1_test}/sample_utf8_v1.1.mp3 (100%) rename {id3v1_test => internal/id3v1_test}/sample_utf8_v1.mp3 (100%) diff --git a/id3v1_test.go b/id3v1_test.go index ec0295b..44fc933 100644 --- a/id3v1_test.go +++ b/id3v1_test.go @@ -5,24 +5,25 @@ package tag import ( - "./id3v1_test" "bytes" "testing" + + "github.com/dhowden/tag/internal/id3v1_test" ) -//go:generate go-bindata -o id3v1_test/id3v1_testdata.go -pkg id3v1_test -ignore .txt -ignore .go id3v1_test +//go:generate go-bindata -o internal/id3v1_test/id3v1_testdata.go -pkg id3v1_test -ignore .txt -ignore .go internal/id3v1_test func TestReadID3v1Tags(t *testing.T) { for _, name := range []string{ - "id3v1_test/sample_usascii_v1.mp3", - "id3v1_test/sample_ms932_v1.mp3", - "id3v1_test/sample_utf8_v1.mp3"} { + "internal/id3v1_test/sample_usascii_v1.mp3", + "internal/id3v1_test/sample_ms932_v1.mp3", + "internal/id3v1_test/sample_utf8_v1.mp3"} { doTest(name, 0, 30, t) } for _, name := range []string{ - "id3v1_test/sample_usascii_v1.1.mp3", - "id3v1_test/sample_ms932_v1.1.mp3", - "id3v1_test/sample_utf8_v1.1.mp3"} { + "internal/id3v1_test/sample_usascii_v1.1.mp3", + "internal/id3v1_test/sample_ms932_v1.1.mp3", + "internal/id3v1_test/sample_utf8_v1.1.mp3"} { doTest(name, 1, 28, t) } } diff --git a/id3v1_test/id3v1_testdata.go b/id3v1_test/id3v1_testdata.go deleted file mode 100644 index 7b8a722..0000000 --- a/id3v1_test/id3v1_testdata.go +++ /dev/null @@ -1,352 +0,0 @@ -// Code generated by go-bindata. -// sources: -// id3v1_test/sample_ms932_v1.1.mp3 -// id3v1_test/sample_ms932_v1.mp3 -// id3v1_test/sample_usascii_v1.1.mp3 -// id3v1_test/sample_usascii_v1.mp3 -// id3v1_test/sample_utf8_v1.1.mp3 -// id3v1_test/sample_utf8_v1.mp3 -// DO NOT EDIT! - -package id3v1_test - -import ( - "bytes" - "compress/gzip" - "fmt" - "io" - "io/ioutil" - "os" - "path/filepath" - "strings" - "time" -) - -func bindataRead(data []byte, name string) ([]byte, error) { - gz, err := gzip.NewReader(bytes.NewBuffer(data)) - if err != nil { - return nil, fmt.Errorf("Read %q: %v", name, err) - } - - var buf bytes.Buffer - _, err = io.Copy(&buf, gz) - clErr := gz.Close() - - if err != nil { - return nil, fmt.Errorf("Read %q: %v", name, err) - } - if clErr != nil { - return nil, err - } - - return buf.Bytes(), nil -} - -type asset struct { - bytes []byte - info os.FileInfo -} - -type bindataFileInfo struct { - name string - size int64 - mode os.FileMode - modTime time.Time -} - -func (fi bindataFileInfo) Name() string { - return fi.name -} -func (fi bindataFileInfo) Size() int64 { - return fi.size -} -func (fi bindataFileInfo) Mode() os.FileMode { - return fi.mode -} -func (fi bindataFileInfo) ModTime() time.Time { - return fi.modTime -} -func (fi bindataFileInfo) IsDir() bool { - return false -} -func (fi bindataFileInfo) Sys() interface{} { - return nil -} - -var _id3v1_testSample_ms932_v11Mp3 = []byte("\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\xfa\xff\x58\x22\x85\x81\x81\x81\x71\x09\x03\x18\x30\x7b\x80\x48\x1f\x47\x5f\x57\x63\x3d\x4b\x4b\x3d\xd3\x50\x62\x01\xc8\x1c\x63\x74\x73\x88\xd6\x8d\x6a\x4e\x1a\x15\xcc\x09\x71\x74\x6f\x0e\x69\x9e\xdc\x5c\xd6\xdc\xdd\x74\xa6\x39\xae\xd9\xb9\x39\xbd\xb9\x9b\x01\x09\x20\xc9\x3a\x36\x46\x37\xa7\x36\x3b\x35\x47\x34\xa7\x63\x93\x6d\xee\x6e\xce\x6f\x6e\x40\xd6\x6b\x68\x69\x69\x10\x9c\x98\x5b\x90\x93\xaa\xe0\x92\x58\x92\xa8\x50\x9e\x59\x92\xa1\xe0\x1b\x6c\x69\x6c\xa4\x60\x6c\x62\x6a\x66\xce\xc0\x28\x03\x08\x00\x00\xff\xff\x9d\x69\xa1\x40\x58\x01\x00\x00") - -func id3v1_testSample_ms932_v11Mp3Bytes() ([]byte, error) { - return bindataRead( - _id3v1_testSample_ms932_v11Mp3, - "id3v1_test/sample_ms932_v1.1.mp3", - ) -} - -func id3v1_testSample_ms932_v11Mp3() (*asset, error) { - bytes, err := id3v1_testSample_ms932_v11Mp3Bytes() - if err != nil { - return nil, err - } - - info := bindataFileInfo{name: "id3v1_test/sample_ms932_v1.1.mp3", size: 344, mode: os.FileMode(438), modTime: time.Unix(1468246151, 0)} - a := &asset{bytes: bytes, info: info} - return a, nil -} - -var _id3v1_testSample_ms932_v1Mp3 = []byte("\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\xfa\xff\x58\x22\x85\x81\x81\x81\x71\x09\x03\x18\x30\x7b\x80\x48\x1f\x47\x5f\x57\x63\x3d\x4b\x4b\x3d\xd3\x50\x62\x01\xc8\x1c\x63\x74\x73\x88\xd6\x8d\x6a\x4e\x1a\x15\xcc\x09\x71\x74\x6f\x0e\x69\x9e\xdc\x5c\xd6\xdc\xdd\x74\xa6\x39\xae\xd9\xb9\x39\xbd\xb9\x5b\x01\x09\x20\xc9\x3a\x36\x46\x37\xa7\x36\x3b\x35\x47\x34\xa7\x63\x93\x6d\xee\x6e\xce\x6f\x6e\x40\xd6\x6b\x68\x69\x69\x10\x9c\x98\x5b\x90\x93\xaa\xe0\x92\x58\x92\xa8\x50\x9e\x59\x92\xa1\xe0\x1b\x6c\x69\x6c\xa4\x60\x6c\x62\x6a\x66\x6e\x61\x29\x03\x08\x00\x00\xff\xff\xfa\x22\x50\xe2\x58\x01\x00\x00") - -func id3v1_testSample_ms932_v1Mp3Bytes() ([]byte, error) { - return bindataRead( - _id3v1_testSample_ms932_v1Mp3, - "id3v1_test/sample_ms932_v1.mp3", - ) -} - -func id3v1_testSample_ms932_v1Mp3() (*asset, error) { - bytes, err := id3v1_testSample_ms932_v1Mp3Bytes() - if err != nil { - return nil, err - } - - info := bindataFileInfo{name: "id3v1_test/sample_ms932_v1.mp3", size: 344, mode: os.FileMode(438), modTime: time.Unix(1468246151, 0)} - a := &asset{bytes: bytes, info: info} - return a, nil -} - -var _id3v1_testSample_usascii_v11Mp3 = []byte("\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\xfa\xff\x58\x22\x85\x81\x81\x81\x71\x09\x03\x18\x30\x7b\x80\x48\x1f\x47\x5f\x57\x63\x3d\x4b\x4b\x3d\xd3\x50\x62\x01\xc8\x1c\x63\x74\x73\x88\xd6\x8d\x6a\x4e\x1a\x15\xcc\x09\x71\x74\x0f\x4e\xcc\x2d\xc8\x49\x55\x08\xc9\x2c\xc9\x49\x65\xc0\x00\x50\x59\xc7\xa2\x92\xcc\xe2\x12\x9c\xb2\x39\x49\xa5\xb9\x98\x7a\x0d\x2d\x2d\x0d\xa0\x2a\x5c\x12\x4b\x12\x15\xca\x33\x4b\x32\x14\x42\x83\x75\x1d\x83\x9d\x3d\x3d\x15\xcc\xcc\x19\x18\x65\x00\x01\x00\x00\xff\xff\x0b\x7f\x35\x28\x58\x01\x00\x00") - -func id3v1_testSample_usascii_v11Mp3Bytes() ([]byte, error) { - return bindataRead( - _id3v1_testSample_usascii_v11Mp3, - "id3v1_test/sample_usascii_v1.1.mp3", - ) -} - -func id3v1_testSample_usascii_v11Mp3() (*asset, error) { - bytes, err := id3v1_testSample_usascii_v11Mp3Bytes() - if err != nil { - return nil, err - } - - info := bindataFileInfo{name: "id3v1_test/sample_usascii_v1.1.mp3", size: 344, mode: os.FileMode(438), modTime: time.Unix(1468246151, 0)} - a := &asset{bytes: bytes, info: info} - return a, nil -} - -var _id3v1_testSample_usascii_v1Mp3 = []byte("\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\xfa\xff\x58\x22\x85\x81\x81\x81\x71\x09\x03\x18\x30\x7b\x80\x48\x1f\x47\x5f\x57\x63\x3d\x4b\x4b\x3d\xd3\x50\x62\x01\xc8\x1c\x63\x74\x73\x88\xd6\x8d\x6a\x4e\x1a\x15\xcc\x09\x71\x74\x0f\x4e\xcc\x2d\xc8\x49\x55\x08\xc9\x2c\x01\x92\x18\x00\x2a\xeb\x58\x54\x92\x59\x5c\x82\x53\x36\x27\xa9\x34\x17\x53\xaf\xa1\xa5\xa5\x01\x54\x85\x4b\x62\x49\xa2\x42\x79\x66\x49\x86\x42\x68\xb0\xae\x63\xb0\xb3\xa7\xa7\x82\x99\xb9\x85\xa5\x0c\x20\x00\x00\xff\xff\x2f\x76\xcd\x7e\x58\x01\x00\x00") - -func id3v1_testSample_usascii_v1Mp3Bytes() ([]byte, error) { - return bindataRead( - _id3v1_testSample_usascii_v1Mp3, - "id3v1_test/sample_usascii_v1.mp3", - ) -} - -func id3v1_testSample_usascii_v1Mp3() (*asset, error) { - bytes, err := id3v1_testSample_usascii_v1Mp3Bytes() - if err != nil { - return nil, err - } - - info := bindataFileInfo{name: "id3v1_test/sample_usascii_v1.mp3", size: 344, mode: os.FileMode(438), modTime: time.Unix(1468246151, 0)} - a := &asset{bytes: bytes, info: info} - return a, nil -} - -var _id3v1_testSample_utf8_v11Mp3 = []byte("\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\xfa\xff\x58\x22\x85\x81\x81\x81\x71\x09\x03\x18\x30\x7b\x80\x48\x1f\x47\x5f\x57\x63\x3d\x4b\x4b\x3d\xd3\x50\x62\x01\xc8\x1c\x63\x74\x73\x88\xd6\x8d\x6a\x4e\x1a\x15\xcc\x09\x71\x74\x7f\xdc\xb4\xf5\x71\xf3\xe6\xc7\xcd\xd3\x1f\x37\xaf\x7e\xdc\xb8\xee\x71\xd3\xfe\xc7\x4d\x4b\x1e\x37\x77\x00\xb9\x40\x33\x31\x64\x17\x3d\x6e\xde\xf3\xb8\xb9\xed\x71\xd3\xe2\xc7\x4d\x3b\xb1\xc9\xae\x7e\xdc\x3c\xe1\x71\xf3\x02\xa0\x5e\x43\x4b\x4b\x83\xe0\xc4\xdc\x82\x9c\x54\x05\x97\xc4\x92\x44\x85\xf2\xcc\x92\x0c\x85\xd0\x10\x37\x0b\x05\x23\x63\x13\x53\x33\x73\x06\x46\x19\x40\x00\x00\x00\xff\xff\x0c\x8a\xd5\x94\x58\x01\x00\x00") - -func id3v1_testSample_utf8_v11Mp3Bytes() ([]byte, error) { - return bindataRead( - _id3v1_testSample_utf8_v11Mp3, - "id3v1_test/sample_utf8_v1.1.mp3", - ) -} - -func id3v1_testSample_utf8_v11Mp3() (*asset, error) { - bytes, err := id3v1_testSample_utf8_v11Mp3Bytes() - if err != nil { - return nil, err - } - - info := bindataFileInfo{name: "id3v1_test/sample_utf8_v1.1.mp3", size: 344, mode: os.FileMode(438), modTime: time.Unix(1468246151, 0)} - a := &asset{bytes: bytes, info: info} - return a, nil -} - -var _id3v1_testSample_utf8_v1Mp3 = []byte("\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\xfa\xff\x58\x22\x85\x81\x81\x81\x71\x09\x03\x18\x30\x7b\x80\x48\x1f\x47\x5f\x57\x63\x3d\x4b\x4b\x3d\xd3\x50\x62\x01\xc8\x1c\x63\x74\x73\x88\xd6\x8d\x6a\x4e\x1a\x15\xcc\x09\x71\x74\x7f\xdc\xb4\xf5\x71\xf3\xe6\xc7\xcd\xd3\x1f\x37\xaf\x7e\xdc\xb8\xee\x71\xd3\xfe\xc7\x4d\x4b\x1e\x37\x77\x00\xb9\x0a\x0a\x0a\x18\xb2\x8b\x1e\x37\xef\x79\xdc\xdc\xf6\xb8\x69\xf1\xe3\xa6\x9d\xd8\x64\x57\x3f\x6e\x9e\xf0\xb8\x79\x01\x50\xaf\xa1\xa5\xa5\x41\x70\x62\x6e\x41\x4e\xaa\x82\x4b\x62\x49\xa2\x42\x79\x66\x49\x86\x42\x68\x88\x9b\x85\x82\x91\xb1\x89\xa9\x99\xb9\x85\xa5\x0c\x20\x00\x00\xff\xff\x90\xde\x3d\x7d\x58\x01\x00\x00") - -func id3v1_testSample_utf8_v1Mp3Bytes() ([]byte, error) { - return bindataRead( - _id3v1_testSample_utf8_v1Mp3, - "id3v1_test/sample_utf8_v1.mp3", - ) -} - -func id3v1_testSample_utf8_v1Mp3() (*asset, error) { - bytes, err := id3v1_testSample_utf8_v1Mp3Bytes() - if err != nil { - return nil, err - } - - info := bindataFileInfo{name: "id3v1_test/sample_utf8_v1.mp3", size: 344, mode: os.FileMode(438), modTime: time.Unix(1468246151, 0)} - a := &asset{bytes: bytes, info: info} - return a, nil -} - -// Asset loads and returns the asset for the given name. -// It returns an error if the asset could not be found or -// could not be loaded. -func Asset(name string) ([]byte, error) { - cannonicalName := strings.Replace(name, "\\", "/", -1) - if f, ok := _bindata[cannonicalName]; ok { - a, err := f() - if err != nil { - return nil, fmt.Errorf("Asset %s can't read by error: %v", name, err) - } - return a.bytes, nil - } - return nil, fmt.Errorf("Asset %s not found", name) -} - -// MustAsset is like Asset but panics when Asset would return an error. -// It simplifies safe initialization of global variables. -func MustAsset(name string) []byte { - a, err := Asset(name) - if err != nil { - panic("asset: Asset(" + name + "): " + err.Error()) - } - - return a -} - -// AssetInfo loads and returns the asset info for the given name. -// It returns an error if the asset could not be found or -// could not be loaded. -func AssetInfo(name string) (os.FileInfo, error) { - cannonicalName := strings.Replace(name, "\\", "/", -1) - if f, ok := _bindata[cannonicalName]; ok { - a, err := f() - if err != nil { - return nil, fmt.Errorf("AssetInfo %s can't read by error: %v", name, err) - } - return a.info, nil - } - return nil, fmt.Errorf("AssetInfo %s not found", name) -} - -// AssetNames returns the names of the assets. -func AssetNames() []string { - names := make([]string, 0, len(_bindata)) - for name := range _bindata { - names = append(names, name) - } - return names -} - -// _bindata is a table, holding each asset generator, mapped to its name. -var _bindata = map[string]func() (*asset, error){ - "id3v1_test/sample_ms932_v1.1.mp3": id3v1_testSample_ms932_v11Mp3, - "id3v1_test/sample_ms932_v1.mp3": id3v1_testSample_ms932_v1Mp3, - "id3v1_test/sample_usascii_v1.1.mp3": id3v1_testSample_usascii_v11Mp3, - "id3v1_test/sample_usascii_v1.mp3": id3v1_testSample_usascii_v1Mp3, - "id3v1_test/sample_utf8_v1.1.mp3": id3v1_testSample_utf8_v11Mp3, - "id3v1_test/sample_utf8_v1.mp3": id3v1_testSample_utf8_v1Mp3, -} - -// AssetDir returns the file names below a certain -// directory embedded in the file by go-bindata. -// For example if you run go-bindata on data/... and data contains the -// following hierarchy: -// data/ -// foo.txt -// img/ -// a.png -// b.png -// then AssetDir("data") would return []string{"foo.txt", "img"} -// AssetDir("data/img") would return []string{"a.png", "b.png"} -// AssetDir("foo.txt") and AssetDir("notexist") would return an error -// AssetDir("") will return []string{"data"}. -func AssetDir(name string) ([]string, error) { - node := _bintree - if len(name) != 0 { - cannonicalName := strings.Replace(name, "\\", "/", -1) - pathList := strings.Split(cannonicalName, "/") - for _, p := range pathList { - node = node.Children[p] - if node == nil { - return nil, fmt.Errorf("Asset %s not found", name) - } - } - } - if node.Func != nil { - return nil, fmt.Errorf("Asset %s not found", name) - } - rv := make([]string, 0, len(node.Children)) - for childName := range node.Children { - rv = append(rv, childName) - } - return rv, nil -} - -type bintree struct { - Func func() (*asset, error) - Children map[string]*bintree -} -var _bintree = &bintree{nil, map[string]*bintree{ - "id3v1_test": &bintree{nil, map[string]*bintree{ - "sample_ms932_v1.1.mp3": &bintree{id3v1_testSample_ms932_v11Mp3, map[string]*bintree{}}, - "sample_ms932_v1.mp3": &bintree{id3v1_testSample_ms932_v1Mp3, map[string]*bintree{}}, - "sample_usascii_v1.1.mp3": &bintree{id3v1_testSample_usascii_v11Mp3, map[string]*bintree{}}, - "sample_usascii_v1.mp3": &bintree{id3v1_testSample_usascii_v1Mp3, map[string]*bintree{}}, - "sample_utf8_v1.1.mp3": &bintree{id3v1_testSample_utf8_v11Mp3, map[string]*bintree{}}, - "sample_utf8_v1.mp3": &bintree{id3v1_testSample_utf8_v1Mp3, map[string]*bintree{}}, - }}, -}} - -// RestoreAsset restores an asset under the given directory -func RestoreAsset(dir, name string) error { - data, err := Asset(name) - if err != nil { - return err - } - info, err := AssetInfo(name) - if err != nil { - return err - } - err = os.MkdirAll(_filePath(dir, filepath.Dir(name)), os.FileMode(0755)) - if err != nil { - return err - } - err = ioutil.WriteFile(_filePath(dir, name), data, info.Mode()) - if err != nil { - return err - } - err = os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime()) - if err != nil { - return err - } - return nil -} - -// RestoreAssets restores an asset under the given directory recursively -func RestoreAssets(dir, name string) error { - children, err := AssetDir(name) - // File - if err != nil { - return RestoreAsset(dir, name) - } - // Dir - for _, child := range children { - err = RestoreAssets(dir, filepath.Join(name, child)) - if err != nil { - return err - } - } - return nil -} - -func _filePath(dir, name string) string { - cannonicalName := strings.Replace(name, "\\", "/", -1) - return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...) -} - diff --git a/id3v1_test/NOTICE.txt b/internal/id3v1_test/NOTICE.txt similarity index 100% rename from id3v1_test/NOTICE.txt rename to internal/id3v1_test/NOTICE.txt diff --git a/internal/id3v1_test/id3v1_testdata.go b/internal/id3v1_test/id3v1_testdata.go new file mode 100644 index 0000000..0be0896 --- /dev/null +++ b/internal/id3v1_test/id3v1_testdata.go @@ -0,0 +1,354 @@ +// Code generated by go-bindata. +// sources: +// internal/id3v1_test/sample_ms932_v1.1.mp3 +// internal/id3v1_test/sample_ms932_v1.mp3 +// internal/id3v1_test/sample_usascii_v1.1.mp3 +// internal/id3v1_test/sample_usascii_v1.mp3 +// internal/id3v1_test/sample_utf8_v1.1.mp3 +// internal/id3v1_test/sample_utf8_v1.mp3 +// DO NOT EDIT! + +package id3v1_test + +import ( + "bytes" + "compress/gzip" + "fmt" + "io" + "io/ioutil" + "os" + "path/filepath" + "strings" + "time" +) + +func bindataRead(data []byte, name string) ([]byte, error) { + gz, err := gzip.NewReader(bytes.NewBuffer(data)) + if err != nil { + return nil, fmt.Errorf("Read %q: %v", name, err) + } + + var buf bytes.Buffer + _, err = io.Copy(&buf, gz) + clErr := gz.Close() + + if err != nil { + return nil, fmt.Errorf("Read %q: %v", name, err) + } + if clErr != nil { + return nil, err + } + + return buf.Bytes(), nil +} + +type asset struct { + bytes []byte + info os.FileInfo +} + +type bindataFileInfo struct { + name string + size int64 + mode os.FileMode + modTime time.Time +} + +func (fi bindataFileInfo) Name() string { + return fi.name +} +func (fi bindataFileInfo) Size() int64 { + return fi.size +} +func (fi bindataFileInfo) Mode() os.FileMode { + return fi.mode +} +func (fi bindataFileInfo) ModTime() time.Time { + return fi.modTime +} +func (fi bindataFileInfo) IsDir() bool { + return false +} +func (fi bindataFileInfo) Sys() interface{} { + return nil +} + +var _internalId3v1_testSample_ms932_v11Mp3 = []byte("\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\xfa\xff\x58\x22\x85\x81\x81\x81\x71\x09\x03\x18\x30\x7b\x80\x48\x1f\x47\x5f\x57\x63\x3d\x4b\x4b\x3d\xd3\x50\x62\x01\xc8\x1c\x63\x74\x73\x88\xd6\x8d\x6a\x4e\x1a\x15\xcc\x09\x71\x74\x6f\x0e\x69\x9e\xdc\x5c\xd6\xdc\xdd\x74\xa6\x39\xae\xd9\xb9\x39\xbd\xb9\x9b\x01\x09\x20\xc9\x3a\x36\x46\x37\xa7\x36\x3b\x35\x47\x34\xa7\x63\x93\x6d\xee\x6e\xce\x6f\x6e\x40\xd6\x6b\x68\x69\x69\x10\x9c\x98\x5b\x90\x93\xaa\xe0\x92\x58\x92\xa8\x50\x9e\x59\x92\xa1\xe0\x1b\x6c\x69\x6c\xa4\x60\x6c\x62\x6a\x66\xce\xc0\x28\x03\x08\x00\x00\xff\xff\x9d\x69\xa1\x40\x58\x01\x00\x00") + +func internalId3v1_testSample_ms932_v11Mp3Bytes() ([]byte, error) { + return bindataRead( + _internalId3v1_testSample_ms932_v11Mp3, + "internal/id3v1_test/sample_ms932_v1.1.mp3", + ) +} + +func internalId3v1_testSample_ms932_v11Mp3() (*asset, error) { + bytes, err := internalId3v1_testSample_ms932_v11Mp3Bytes() + if err != nil { + return nil, err + } + + info := bindataFileInfo{name: "internal/id3v1_test/sample_ms932_v1.1.mp3", size: 344, mode: os.FileMode(438), modTime: time.Unix(1468246886, 0)} + a := &asset{bytes: bytes, info: info} + return a, nil +} + +var _internalId3v1_testSample_ms932_v1Mp3 = []byte("\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\xfa\xff\x58\x22\x85\x81\x81\x81\x71\x09\x03\x18\x30\x7b\x80\x48\x1f\x47\x5f\x57\x63\x3d\x4b\x4b\x3d\xd3\x50\x62\x01\xc8\x1c\x63\x74\x73\x88\xd6\x8d\x6a\x4e\x1a\x15\xcc\x09\x71\x74\x6f\x0e\x69\x9e\xdc\x5c\xd6\xdc\xdd\x74\xa6\x39\xae\xd9\xb9\x39\xbd\xb9\x5b\x01\x09\x20\xc9\x3a\x36\x46\x37\xa7\x36\x3b\x35\x47\x34\xa7\x63\x93\x6d\xee\x6e\xce\x6f\x6e\x40\xd6\x6b\x68\x69\x69\x10\x9c\x98\x5b\x90\x93\xaa\xe0\x92\x58\x92\xa8\x50\x9e\x59\x92\xa1\xe0\x1b\x6c\x69\x6c\xa4\x60\x6c\x62\x6a\x66\x6e\x61\x29\x03\x08\x00\x00\xff\xff\xfa\x22\x50\xe2\x58\x01\x00\x00") + +func internalId3v1_testSample_ms932_v1Mp3Bytes() ([]byte, error) { + return bindataRead( + _internalId3v1_testSample_ms932_v1Mp3, + "internal/id3v1_test/sample_ms932_v1.mp3", + ) +} + +func internalId3v1_testSample_ms932_v1Mp3() (*asset, error) { + bytes, err := internalId3v1_testSample_ms932_v1Mp3Bytes() + if err != nil { + return nil, err + } + + info := bindataFileInfo{name: "internal/id3v1_test/sample_ms932_v1.mp3", size: 344, mode: os.FileMode(438), modTime: time.Unix(1468246886, 0)} + a := &asset{bytes: bytes, info: info} + return a, nil +} + +var _internalId3v1_testSample_usascii_v11Mp3 = []byte("\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\xfa\xff\x58\x22\x85\x81\x81\x81\x71\x09\x03\x18\x30\x7b\x80\x48\x1f\x47\x5f\x57\x63\x3d\x4b\x4b\x3d\xd3\x50\x62\x01\xc8\x1c\x63\x74\x73\x88\xd6\x8d\x6a\x4e\x1a\x15\xcc\x09\x71\x74\x0f\x4e\xcc\x2d\xc8\x49\x55\x08\xc9\x2c\xc9\x49\x65\xc0\x00\x50\x59\xc7\xa2\x92\xcc\xe2\x12\x9c\xb2\x39\x49\xa5\xb9\x98\x7a\x0d\x2d\x2d\x0d\xa0\x2a\x5c\x12\x4b\x12\x15\xca\x33\x4b\x32\x14\x42\x83\x75\x1d\x83\x9d\x3d\x3d\x15\xcc\xcc\x19\x18\x65\x00\x01\x00\x00\xff\xff\x0b\x7f\x35\x28\x58\x01\x00\x00") + +func internalId3v1_testSample_usascii_v11Mp3Bytes() ([]byte, error) { + return bindataRead( + _internalId3v1_testSample_usascii_v11Mp3, + "internal/id3v1_test/sample_usascii_v1.1.mp3", + ) +} + +func internalId3v1_testSample_usascii_v11Mp3() (*asset, error) { + bytes, err := internalId3v1_testSample_usascii_v11Mp3Bytes() + if err != nil { + return nil, err + } + + info := bindataFileInfo{name: "internal/id3v1_test/sample_usascii_v1.1.mp3", size: 344, mode: os.FileMode(438), modTime: time.Unix(1468246886, 0)} + a := &asset{bytes: bytes, info: info} + return a, nil +} + +var _internalId3v1_testSample_usascii_v1Mp3 = []byte("\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\xfa\xff\x58\x22\x85\x81\x81\x81\x71\x09\x03\x18\x30\x7b\x80\x48\x1f\x47\x5f\x57\x63\x3d\x4b\x4b\x3d\xd3\x50\x62\x01\xc8\x1c\x63\x74\x73\x88\xd6\x8d\x6a\x4e\x1a\x15\xcc\x09\x71\x74\x0f\x4e\xcc\x2d\xc8\x49\x55\x08\xc9\x2c\x01\x92\x18\x00\x2a\xeb\x58\x54\x92\x59\x5c\x82\x53\x36\x27\xa9\x34\x17\x53\xaf\xa1\xa5\xa5\x01\x54\x85\x4b\x62\x49\xa2\x42\x79\x66\x49\x86\x42\x68\xb0\xae\x63\xb0\xb3\xa7\xa7\x82\x99\xb9\x85\xa5\x0c\x20\x00\x00\xff\xff\x2f\x76\xcd\x7e\x58\x01\x00\x00") + +func internalId3v1_testSample_usascii_v1Mp3Bytes() ([]byte, error) { + return bindataRead( + _internalId3v1_testSample_usascii_v1Mp3, + "internal/id3v1_test/sample_usascii_v1.mp3", + ) +} + +func internalId3v1_testSample_usascii_v1Mp3() (*asset, error) { + bytes, err := internalId3v1_testSample_usascii_v1Mp3Bytes() + if err != nil { + return nil, err + } + + info := bindataFileInfo{name: "internal/id3v1_test/sample_usascii_v1.mp3", size: 344, mode: os.FileMode(438), modTime: time.Unix(1468246886, 0)} + a := &asset{bytes: bytes, info: info} + return a, nil +} + +var _internalId3v1_testSample_utf8_v11Mp3 = []byte("\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\xfa\xff\x58\x22\x85\x81\x81\x81\x71\x09\x03\x18\x30\x7b\x80\x48\x1f\x47\x5f\x57\x63\x3d\x4b\x4b\x3d\xd3\x50\x62\x01\xc8\x1c\x63\x74\x73\x88\xd6\x8d\x6a\x4e\x1a\x15\xcc\x09\x71\x74\x7f\xdc\xb4\xf5\x71\xf3\xe6\xc7\xcd\xd3\x1f\x37\xaf\x7e\xdc\xb8\xee\x71\xd3\xfe\xc7\x4d\x4b\x1e\x37\x77\x00\xb9\x40\x33\x31\x64\x17\x3d\x6e\xde\xf3\xb8\xb9\xed\x71\xd3\xe2\xc7\x4d\x3b\xb1\xc9\xae\x7e\xdc\x3c\xe1\x71\xf3\x02\xa0\x5e\x43\x4b\x4b\x83\xe0\xc4\xdc\x82\x9c\x54\x05\x97\xc4\x92\x44\x85\xf2\xcc\x92\x0c\x85\xd0\x10\x37\x0b\x05\x23\x63\x13\x53\x33\x73\x06\x46\x19\x40\x00\x00\x00\xff\xff\x0c\x8a\xd5\x94\x58\x01\x00\x00") + +func internalId3v1_testSample_utf8_v11Mp3Bytes() ([]byte, error) { + return bindataRead( + _internalId3v1_testSample_utf8_v11Mp3, + "internal/id3v1_test/sample_utf8_v1.1.mp3", + ) +} + +func internalId3v1_testSample_utf8_v11Mp3() (*asset, error) { + bytes, err := internalId3v1_testSample_utf8_v11Mp3Bytes() + if err != nil { + return nil, err + } + + info := bindataFileInfo{name: "internal/id3v1_test/sample_utf8_v1.1.mp3", size: 344, mode: os.FileMode(438), modTime: time.Unix(1468246886, 0)} + a := &asset{bytes: bytes, info: info} + return a, nil +} + +var _internalId3v1_testSample_utf8_v1Mp3 = []byte("\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\xfa\xff\x58\x22\x85\x81\x81\x81\x71\x09\x03\x18\x30\x7b\x80\x48\x1f\x47\x5f\x57\x63\x3d\x4b\x4b\x3d\xd3\x50\x62\x01\xc8\x1c\x63\x74\x73\x88\xd6\x8d\x6a\x4e\x1a\x15\xcc\x09\x71\x74\x7f\xdc\xb4\xf5\x71\xf3\xe6\xc7\xcd\xd3\x1f\x37\xaf\x7e\xdc\xb8\xee\x71\xd3\xfe\xc7\x4d\x4b\x1e\x37\x77\x00\xb9\x0a\x0a\x0a\x18\xb2\x8b\x1e\x37\xef\x79\xdc\xdc\xf6\xb8\x69\xf1\xe3\xa6\x9d\xd8\x64\x57\x3f\x6e\x9e\xf0\xb8\x79\x01\x50\xaf\xa1\xa5\xa5\x41\x70\x62\x6e\x41\x4e\xaa\x82\x4b\x62\x49\xa2\x42\x79\x66\x49\x86\x42\x68\x88\x9b\x85\x82\x91\xb1\x89\xa9\x99\xb9\x85\xa5\x0c\x20\x00\x00\xff\xff\x90\xde\x3d\x7d\x58\x01\x00\x00") + +func internalId3v1_testSample_utf8_v1Mp3Bytes() ([]byte, error) { + return bindataRead( + _internalId3v1_testSample_utf8_v1Mp3, + "internal/id3v1_test/sample_utf8_v1.mp3", + ) +} + +func internalId3v1_testSample_utf8_v1Mp3() (*asset, error) { + bytes, err := internalId3v1_testSample_utf8_v1Mp3Bytes() + if err != nil { + return nil, err + } + + info := bindataFileInfo{name: "internal/id3v1_test/sample_utf8_v1.mp3", size: 344, mode: os.FileMode(438), modTime: time.Unix(1468246886, 0)} + a := &asset{bytes: bytes, info: info} + return a, nil +} + +// Asset loads and returns the asset for the given name. +// It returns an error if the asset could not be found or +// could not be loaded. +func Asset(name string) ([]byte, error) { + cannonicalName := strings.Replace(name, "\\", "/", -1) + if f, ok := _bindata[cannonicalName]; ok { + a, err := f() + if err != nil { + return nil, fmt.Errorf("Asset %s can't read by error: %v", name, err) + } + return a.bytes, nil + } + return nil, fmt.Errorf("Asset %s not found", name) +} + +// MustAsset is like Asset but panics when Asset would return an error. +// It simplifies safe initialization of global variables. +func MustAsset(name string) []byte { + a, err := Asset(name) + if err != nil { + panic("asset: Asset(" + name + "): " + err.Error()) + } + + return a +} + +// AssetInfo loads and returns the asset info for the given name. +// It returns an error if the asset could not be found or +// could not be loaded. +func AssetInfo(name string) (os.FileInfo, error) { + cannonicalName := strings.Replace(name, "\\", "/", -1) + if f, ok := _bindata[cannonicalName]; ok { + a, err := f() + if err != nil { + return nil, fmt.Errorf("AssetInfo %s can't read by error: %v", name, err) + } + return a.info, nil + } + return nil, fmt.Errorf("AssetInfo %s not found", name) +} + +// AssetNames returns the names of the assets. +func AssetNames() []string { + names := make([]string, 0, len(_bindata)) + for name := range _bindata { + names = append(names, name) + } + return names +} + +// _bindata is a table, holding each asset generator, mapped to its name. +var _bindata = map[string]func() (*asset, error){ + "internal/id3v1_test/sample_ms932_v1.1.mp3": internalId3v1_testSample_ms932_v11Mp3, + "internal/id3v1_test/sample_ms932_v1.mp3": internalId3v1_testSample_ms932_v1Mp3, + "internal/id3v1_test/sample_usascii_v1.1.mp3": internalId3v1_testSample_usascii_v11Mp3, + "internal/id3v1_test/sample_usascii_v1.mp3": internalId3v1_testSample_usascii_v1Mp3, + "internal/id3v1_test/sample_utf8_v1.1.mp3": internalId3v1_testSample_utf8_v11Mp3, + "internal/id3v1_test/sample_utf8_v1.mp3": internalId3v1_testSample_utf8_v1Mp3, +} + +// AssetDir returns the file names below a certain +// directory embedded in the file by go-bindata. +// For example if you run go-bindata on data/... and data contains the +// following hierarchy: +// data/ +// foo.txt +// img/ +// a.png +// b.png +// then AssetDir("data") would return []string{"foo.txt", "img"} +// AssetDir("data/img") would return []string{"a.png", "b.png"} +// AssetDir("foo.txt") and AssetDir("notexist") would return an error +// AssetDir("") will return []string{"data"}. +func AssetDir(name string) ([]string, error) { + node := _bintree + if len(name) != 0 { + cannonicalName := strings.Replace(name, "\\", "/", -1) + pathList := strings.Split(cannonicalName, "/") + for _, p := range pathList { + node = node.Children[p] + if node == nil { + return nil, fmt.Errorf("Asset %s not found", name) + } + } + } + if node.Func != nil { + return nil, fmt.Errorf("Asset %s not found", name) + } + rv := make([]string, 0, len(node.Children)) + for childName := range node.Children { + rv = append(rv, childName) + } + return rv, nil +} + +type bintree struct { + Func func() (*asset, error) + Children map[string]*bintree +} +var _bintree = &bintree{nil, map[string]*bintree{ + "internal": &bintree{nil, map[string]*bintree{ + "id3v1_test": &bintree{nil, map[string]*bintree{ + "sample_ms932_v1.1.mp3": &bintree{internalId3v1_testSample_ms932_v11Mp3, map[string]*bintree{}}, + "sample_ms932_v1.mp3": &bintree{internalId3v1_testSample_ms932_v1Mp3, map[string]*bintree{}}, + "sample_usascii_v1.1.mp3": &bintree{internalId3v1_testSample_usascii_v11Mp3, map[string]*bintree{}}, + "sample_usascii_v1.mp3": &bintree{internalId3v1_testSample_usascii_v1Mp3, map[string]*bintree{}}, + "sample_utf8_v1.1.mp3": &bintree{internalId3v1_testSample_utf8_v11Mp3, map[string]*bintree{}}, + "sample_utf8_v1.mp3": &bintree{internalId3v1_testSample_utf8_v1Mp3, map[string]*bintree{}}, + }}, + }}, +}} + +// RestoreAsset restores an asset under the given directory +func RestoreAsset(dir, name string) error { + data, err := Asset(name) + if err != nil { + return err + } + info, err := AssetInfo(name) + if err != nil { + return err + } + err = os.MkdirAll(_filePath(dir, filepath.Dir(name)), os.FileMode(0755)) + if err != nil { + return err + } + err = ioutil.WriteFile(_filePath(dir, name), data, info.Mode()) + if err != nil { + return err + } + err = os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime()) + if err != nil { + return err + } + return nil +} + +// RestoreAssets restores an asset under the given directory recursively +func RestoreAssets(dir, name string) error { + children, err := AssetDir(name) + // File + if err != nil { + return RestoreAsset(dir, name) + } + // Dir + for _, child := range children { + err = RestoreAssets(dir, filepath.Join(name, child)) + if err != nil { + return err + } + } + return nil +} + +func _filePath(dir, name string) string { + cannonicalName := strings.Replace(name, "\\", "/", -1) + return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...) +} + diff --git a/id3v1_test/sample_ms932_v1.1.mp3 b/internal/id3v1_test/sample_ms932_v1.1.mp3 similarity index 100% rename from id3v1_test/sample_ms932_v1.1.mp3 rename to internal/id3v1_test/sample_ms932_v1.1.mp3 diff --git a/id3v1_test/sample_ms932_v1.mp3 b/internal/id3v1_test/sample_ms932_v1.mp3 similarity index 100% rename from id3v1_test/sample_ms932_v1.mp3 rename to internal/id3v1_test/sample_ms932_v1.mp3 diff --git a/id3v1_test/sample_usascii_v1.1.mp3 b/internal/id3v1_test/sample_usascii_v1.1.mp3 similarity index 100% rename from id3v1_test/sample_usascii_v1.1.mp3 rename to internal/id3v1_test/sample_usascii_v1.1.mp3 diff --git a/id3v1_test/sample_usascii_v1.mp3 b/internal/id3v1_test/sample_usascii_v1.mp3 similarity index 100% rename from id3v1_test/sample_usascii_v1.mp3 rename to internal/id3v1_test/sample_usascii_v1.mp3 diff --git a/id3v1_test/sample_utf8_v1.1.mp3 b/internal/id3v1_test/sample_utf8_v1.1.mp3 similarity index 100% rename from id3v1_test/sample_utf8_v1.1.mp3 rename to internal/id3v1_test/sample_utf8_v1.1.mp3 diff --git a/id3v1_test/sample_utf8_v1.mp3 b/internal/id3v1_test/sample_utf8_v1.mp3 similarity index 100% rename from id3v1_test/sample_utf8_v1.mp3 rename to internal/id3v1_test/sample_utf8_v1.mp3