diff --git a/match.go b/match.go index 82cf804..f22e46e 100644 --- a/match.go +++ b/match.go @@ -52,7 +52,7 @@ func MatchFile(filepath string) (types.Type, error) { } // MatchReader is convenient wrapper to Match() any Reader -func MatchReader(reader io.Reader) (types.Type, error) { +func MatchReader(reader io.ReadSeeker) (types.Type, error) { buffer := make([]byte, 8192) // 8K makes msooxml tests happy and allows for expanded custom file checks _, err := reader.Read(buffer) @@ -60,6 +60,8 @@ func MatchReader(reader io.Reader) (types.Type, error) { return types.Unknown, err } + reader.Seek(0, 0) + return Match(buffer) } diff --git a/match_test.go b/match_test.go index 946bb25..09b31e1 100644 --- a/match_test.go +++ b/match_test.go @@ -71,12 +71,12 @@ func TestMatchFile(t *testing.T) { func TestMatchReader(t *testing.T) { cases := []struct { - buf io.Reader + buf io.ReadSeeker ext string }{ - {bytes.NewBuffer([]byte{0xFF, 0xD8, 0xFF}), "jpg"}, - {bytes.NewBuffer([]byte{0xFF, 0xD8, 0x00}), "unknown"}, - {bytes.NewBuffer([]byte{0x89, 0x50, 0x4E, 0x47}), "png"}, + {bytes.NewReader([]byte{0xFF, 0xD8, 0xFF}), "jpg"}, + {bytes.NewReader([]byte{0xFF, 0xD8, 0x00}), "unknown"}, + {bytes.NewReader([]byte{0x89, 0x50, 0x4E, 0x47}), "png"}, } for _, test := range cases {