Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions filetype_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -70,6 +72,7 @@ func TestIsSupported(t *testing.T) {
{"abc", false},
{"png", true},
{"mp4", true},
{"mp3", true},
{"", false},
}

Expand All @@ -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 {
Expand Down
Binary file added fixtures/sample.mp3
Binary file not shown.
2 changes: 2 additions & 0 deletions match_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func TestMatchFile(t *testing.T) {
{"tar"},
{"tif"},
{"mp4"},
{"mp3"},
}

for _, test := range cases {
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions matchers/audio.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down