diff --git a/filetype_test.go b/filetype_test.go index dfa9cce..62fa9fe 100644 --- a/filetype_test.go +++ b/filetype_test.go @@ -33,6 +33,8 @@ func TestIsType(t *testing.T) { {[]byte{0xFF, 0xD8, 0xFF}, types.Get("jpg"), true}, {[]byte{0xFF, 0xD8, 0x00}, types.Get("jpg"), false}, {[]byte{0x89, 0x50, 0x4E, 0x47}, types.Get("png"), true}, + {[]byte{0xFF, 0xFA, 0x90}, types.Get("mp3"), true}, + {[]byte{0xFF, 0xFB, 0x90}, types.Get("mp3"), true}, } for _, test := range cases { @@ -70,6 +72,7 @@ func TestIsSupported(t *testing.T) { {"abc", false}, {"png", true}, {"mp4", true}, + {"mp3", true}, {"", false}, } @@ -89,6 +92,7 @@ func TestIsMIMESupported(t *testing.T) { {"foo/bar", false}, {"image/png", true}, {"video/mpeg", true}, + {"audio/mpeg", true}, } for _, test := range cases { diff --git a/fixtures/sample.mp3 b/fixtures/sample.mp3 new file mode 100644 index 0000000..521e1f1 Binary files /dev/null and b/fixtures/sample.mp3 differ diff --git a/match_test.go b/match_test.go index b0e542f..cc7ab97 100644 --- a/match_test.go +++ b/match_test.go @@ -43,6 +43,7 @@ func TestMatchFile(t *testing.T) { {"tar"}, {"tif"}, {"mp4"}, + {"mp3"}, } for _, test := range cases { @@ -137,6 +138,7 @@ func TestMatchesMap(t *testing.T) { {[]byte{0xFF, 0xD8, 0xFF}, true}, {[]byte{0x89, 0x50, 0x4E, 0x47}, true}, {[]byte{0xFF, 0x0, 0x0}, false}, + {[]byte{0xFF, 0xFC, 0x90}, false}, } for _, test := range cases { diff --git a/matchers/audio.go b/matchers/audio.go index 7b27caf..2d66124 100644 --- a/matchers/audio.go +++ b/matchers/audio.go @@ -28,8 +28,9 @@ func Midi(buf []byte) bool { func Mp3(buf []byte) bool { return len(buf) > 2 && - ((buf[0] == 0x49 && buf[1] == 0x44 && buf[2] == 0x33) || - (buf[0] == 0xFF && buf[1] == 0xfb)) + ((buf[0] == 0x49 && buf[1] == 0x44 && buf[2] == 0x33) || // ID3v2 + // Final bit (has crc32) may be or may not be set. + (buf[0] == 0xFF && (buf[1] == 0xFA || buf[1] == 0xFB))) } func M4a(buf []byte) bool {