From a4ea7f47142fa7adf43091d5a02dd0649c0c3a55 Mon Sep 17 00:00:00 2001 From: Samuel Gaist Date: Wed, 1 Oct 2025 21:44:20 +0200 Subject: [PATCH 1/2] refactor: make extension detection more robust Current extension detection relies on string search which can lead to situation where a normal file is seen as an archive such as with the brotli extension which is br and the Bru markup language which uses bru. This refactor implement the detection based on splitting the file name on dots and then check the artifacts base on that. While not bullet proof it should keep the current behaviour while avoiding sitution where close extension gets mixed. --- brotli.go | 5 ++-- bz2.go | 5 ++-- gz.go | 5 ++-- internal/extensionutils.go | 18 +++++++++++ internal/extensionutils_test.go | 53 +++++++++++++++++++++++++++++++++ lz4.go | 5 ++-- lzip.go | 6 ++-- minlz.go | 6 ++-- rar.go | 5 ++-- sz.go | 7 +++-- tar.go | 5 ++-- xz.go | 5 ++-- zip.go | 4 ++- zlib.go | 5 ++-- zstd.go | 5 ++-- 15 files changed, 111 insertions(+), 28 deletions(-) create mode 100644 internal/extensionutils.go create mode 100644 internal/extensionutils_test.go diff --git a/brotli.go b/brotli.go index 9fb5a17..2191e9a 100644 --- a/brotli.go +++ b/brotli.go @@ -4,10 +4,11 @@ import ( "bytes" "context" "io" - "strings" "unicode/utf8" "github.com/andybalholm/brotli" + + "github.com/mholt/archives/internal" ) func init() { @@ -26,7 +27,7 @@ func (br Brotli) Match(ctx context.Context, filename string, stream io.Reader) ( var mr MatchResult // match filename - if strings.Contains(strings.ToLower(filename), br.Extension()) { + if extensions.Contains(filename, br.Extension()) { mr.ByName = true } diff --git a/bz2.go b/bz2.go index ff7bb3d..05cb5c7 100644 --- a/bz2.go +++ b/bz2.go @@ -4,9 +4,10 @@ import ( "bytes" "context" "io" - "strings" "github.com/dsnet/compress/bzip2" + + "github.com/mholt/archives/internal" ) func init() { @@ -25,7 +26,7 @@ func (bz Bz2) Match(_ context.Context, filename string, stream io.Reader) (Match var mr MatchResult // match filename - if strings.Contains(strings.ToLower(filename), bz.Extension()) { + if extensions.Contains(filename, bz.Extension()) { mr.ByName = true } diff --git a/gz.go b/gz.go index adbf1ed..357e927 100644 --- a/gz.go +++ b/gz.go @@ -4,10 +4,11 @@ import ( "bytes" "context" "io" - "strings" "github.com/klauspost/compress/gzip" "github.com/klauspost/pgzip" + + "github.com/mholt/archives/internal" ) func init() { @@ -37,7 +38,7 @@ func (gz Gz) Match(_ context.Context, filename string, stream io.Reader) (MatchR var mr MatchResult // match filename - if strings.Contains(strings.ToLower(filename), gz.Extension()) { + if extensions.Contains(filename, gz.Extension()) { mr.ByName = true } diff --git a/internal/extensionutils.go b/internal/extensionutils.go new file mode 100644 index 0000000..84b7abe --- /dev/null +++ b/internal/extensionutils.go @@ -0,0 +1,18 @@ +package extensions + +import ( + "slices" + "strings" +) + +func EndsWith(path string, extension string) bool { + extensions := strings.Split(strings.ToLower(path), ".") + ext := strings.Trim(extension, ".") + return extensions[len(extensions)-1] == ext +} + +func Contains(path string, extension string) bool { + extensions := strings.Split(strings.ToLower(path), ".") + ext := strings.Trim(extension, ".") + return slices.Contains(extensions, ext) +} diff --git a/internal/extensionutils_test.go b/internal/extensionutils_test.go new file mode 100644 index 0000000..c8147c7 --- /dev/null +++ b/internal/extensionutils_test.go @@ -0,0 +1,53 @@ +package extensions + +import ( + "testing" +) + +func TestEndsWith(t *testing.T) { + for _, tc := range []struct { + input string + extension string + want bool + }{ + {input: "test.tar", extension: "tar", want: true}, + {input: "test.tar", extension: "gz", want: false}, + {input: "test.tar.gz", extension: "tar", want: false}, + {input: "test.tar.gz", extension: "gz", want: true}, + {input: "test.tar.br", extension: "br", want: true}, + {input: "test.tar.br", extension: "bru", want: false}, + } { + t.Run(tc.input, func(t *testing.T) { + for _, ext := range []string{tc.extension, "." + tc.extension} { + got := EndsWith(tc.input, ext) + if got != tc.want { + t.Errorf("want: '%v', got: '%v')", tc.want, got) + } + } + }) + } +} + +func TestContains(t *testing.T) { + for _, tc := range []struct { + input string + extension string + want bool + }{ + {input: "test.tar", extension: "tar", want: true}, + {input: "test.tar", extension: "gz", want: false}, + {input: "test.tar.gz", extension: "tar", want: true}, + {input: "test.tar.gz", extension: "gz", want: true}, + {input: "test.tar.br", extension: "br", want: true}, + {input: "test.tar.br", extension: "bru", want: false}, + } { + t.Run(tc.input, func(t *testing.T) { + for _, ext := range []string{tc.extension, "." + tc.extension} { + got := Contains(tc.input, ext) + if got != tc.want { + t.Errorf("want: '%v', got: '%v')", tc.want, got) + } + } + }) + } +} diff --git a/lz4.go b/lz4.go index 39fce3c..d7a2a0d 100644 --- a/lz4.go +++ b/lz4.go @@ -4,9 +4,10 @@ import ( "bytes" "context" "io" - "strings" "github.com/pierrec/lz4/v4" + + "github.com/mholt/archives/internal" ) func init() { @@ -25,7 +26,7 @@ func (lz Lz4) Match(_ context.Context, filename string, stream io.Reader) (Match var mr MatchResult // match filename - if strings.Contains(strings.ToLower(filename), lz.Extension()) { + if extensions.Contains(filename, lz.Extension()) { mr.ByName = true } diff --git a/lzip.go b/lzip.go index fa7fdc1..00dcad3 100644 --- a/lzip.go +++ b/lzip.go @@ -4,10 +4,10 @@ import ( "bytes" "context" "io" - "path/filepath" - "strings" "github.com/sorairolake/lzip-go" + + "github.com/mholt/archives/internal" ) func init() { @@ -24,7 +24,7 @@ func (lz Lzip) Match(_ context.Context, filename string, stream io.Reader) (Matc var mr MatchResult // match filename - if filepath.Ext(strings.ToLower(filename)) == lz.Extension() { + if extensions.EndsWith(filename, lz.Extension()) { mr.ByName = true } diff --git a/minlz.go b/minlz.go index 72aede0..15378d3 100644 --- a/minlz.go +++ b/minlz.go @@ -4,10 +4,10 @@ import ( "bytes" "context" "io" - "path/filepath" - "strings" "github.com/minio/minlz" + + "github.com/mholt/archives/internal" ) func init() { @@ -27,7 +27,7 @@ func (mz MinLZ) Match(_ context.Context, filename string, stream io.Reader) (Mat var mr MatchResult // match filename - if filepath.Ext(strings.ToLower(filename)) == ".mz" { + if extensions.Contains(filename, mz.Extension()) { mr.ByName = true } diff --git a/rar.go b/rar.go index 388ecab..0286b54 100644 --- a/rar.go +++ b/rar.go @@ -10,10 +10,11 @@ import ( "log" "os" "path" - "strings" "time" "github.com/nwaples/rardecode/v2" + + "github.com/mholt/archives/internal" ) func init() { @@ -60,7 +61,7 @@ func (r Rar) Match(_ context.Context, filename string, stream io.Reader) (MatchR var mr MatchResult // match filename - if strings.Contains(strings.ToLower(filename), r.Extension()) { + if extensions.Contains(filename, r.Extension()) { mr.ByName = true } diff --git a/sz.go b/sz.go index bb23f21..11be929 100644 --- a/sz.go +++ b/sz.go @@ -4,9 +4,10 @@ import ( "bytes" "context" "io" - "strings" "github.com/klauspost/compress/s2" + + "github.com/mholt/archives/internal" ) func init() { @@ -51,8 +52,8 @@ func (sz Sz) Match(_ context.Context, filename string, stream io.Reader) (MatchR var mr MatchResult // match filename - if strings.Contains(strings.ToLower(filename), sz.Extension()) || - strings.Contains(strings.ToLower(filename), ".s2") { + if extensions.Contains(filename, sz.Extension()) || + extensions.Contains(filename, ".s2") { mr.ByName = true } diff --git a/tar.go b/tar.go index 96c495a..b1a057b 100644 --- a/tar.go +++ b/tar.go @@ -8,7 +8,8 @@ import ( "io" "io/fs" "log" - "strings" + + "github.com/mholt/archives/internal" ) func init() { @@ -47,7 +48,7 @@ func (t Tar) Match(_ context.Context, filename string, stream io.Reader) (MatchR var mr MatchResult // match filename - if strings.Contains(strings.ToLower(filename), t.Extension()) { + if extensions.Contains(filename, t.Extension()) { mr.ByName = true } diff --git a/xz.go b/xz.go index e213bae..d243329 100644 --- a/xz.go +++ b/xz.go @@ -4,10 +4,11 @@ import ( "bytes" "context" "io" - "strings" fastxz "github.com/mikelolasagasti/xz" "github.com/ulikunitz/xz" + + "github.com/mholt/archives/internal" ) func init() { @@ -24,7 +25,7 @@ func (x Xz) Match(_ context.Context, filename string, stream io.Reader) (MatchRe var mr MatchResult // match filename - if strings.Contains(strings.ToLower(filename), x.Extension()) { + if extensions.Contains(filename, x.Extension()) { mr.ByName = true } diff --git a/zip.go b/zip.go index be0b7bc..5d2afd3 100644 --- a/zip.go +++ b/zip.go @@ -19,6 +19,8 @@ import ( "github.com/klauspost/compress/zip" "github.com/klauspost/compress/zstd" "github.com/ulikunitz/xz" + + "github.com/mholt/archives/internal" ) func init() { @@ -85,7 +87,7 @@ func (z Zip) Match(_ context.Context, filename string, stream io.Reader) (MatchR var mr MatchResult // match filename - if strings.Contains(strings.ToLower(filename), z.Extension()) { + if extensions.Contains(filename, z.Extension()) { mr.ByName = true } diff --git a/zlib.go b/zlib.go index 9ee64f4..08190e9 100644 --- a/zlib.go +++ b/zlib.go @@ -3,9 +3,10 @@ package archives import ( "context" "io" - "strings" "github.com/klauspost/compress/zlib" + + "github.com/mholt/archives/internal" ) func init() { @@ -24,7 +25,7 @@ func (zz Zlib) Match(_ context.Context, filename string, stream io.Reader) (Matc var mr MatchResult // match filename - if strings.Contains(strings.ToLower(filename), zz.Extension()) { + if extensions.Contains(filename, zz.Extension()) { mr.ByName = true } diff --git a/zstd.go b/zstd.go index c36c6b9..e0ce6f9 100644 --- a/zstd.go +++ b/zstd.go @@ -4,9 +4,10 @@ import ( "bytes" "context" "io" - "strings" "github.com/klauspost/compress/zstd" + + "github.com/mholt/archives/internal" ) func init() { @@ -26,7 +27,7 @@ func (zs Zstd) Match(_ context.Context, filename string, stream io.Reader) (Matc var mr MatchResult // match filename - if strings.Contains(strings.ToLower(filename), zs.Extension()) { + if extensions.Contains(filename, zs.Extension()) { mr.ByName = true } From b7e23a95bb8d64727f69055462e6f6cd3155f7c0 Mon Sep 17 00:00:00 2001 From: Samuel Gaist Date: Wed, 8 Oct 2025 00:41:54 +0200 Subject: [PATCH 2/2] refactor: remove internal utils and use filepath All file types are now tested using equality with their respective extension except for .tar (which matches the original implementation). --- 7z.go | 3 +- brotli.go | 6 ++-- bz2.go | 6 ++-- formats_test.go | 38 +++++++++++++++++++++++ gz.go | 6 ++-- internal/extensionutils.go | 18 ----------- internal/extensionutils_test.go | 53 --------------------------------- lz4.go | 6 ++-- lzip.go | 6 ++-- minlz.go | 6 ++-- rar.go | 6 ++-- sz.go | 8 ++--- tar.go | 5 ++-- xz.go | 6 ++-- zip.go | 5 ++-- zlib.go | 6 ++-- zstd.go | 6 ++-- 17 files changed, 78 insertions(+), 112 deletions(-) delete mode 100644 internal/extensionutils.go delete mode 100644 internal/extensionutils_test.go diff --git a/7z.go b/7z.go index 2e50203..c81494a 100644 --- a/7z.go +++ b/7z.go @@ -8,6 +8,7 @@ import ( "io" "io/fs" "log" + "path/filepath" "strings" "github.com/bodgit/sevenzip" @@ -37,7 +38,7 @@ func (z SevenZip) Match(_ context.Context, filename string, stream io.Reader) (M var mr MatchResult // match filename - if strings.Contains(strings.ToLower(filename), z.Extension()) { + if filepath.Ext(strings.ToLower(filename)) == z.Extension() { mr.ByName = true } diff --git a/brotli.go b/brotli.go index 2191e9a..a832f20 100644 --- a/brotli.go +++ b/brotli.go @@ -4,11 +4,11 @@ import ( "bytes" "context" "io" + "path/filepath" + "strings" "unicode/utf8" "github.com/andybalholm/brotli" - - "github.com/mholt/archives/internal" ) func init() { @@ -27,7 +27,7 @@ func (br Brotli) Match(ctx context.Context, filename string, stream io.Reader) ( var mr MatchResult // match filename - if extensions.Contains(filename, br.Extension()) { + if filepath.Ext(strings.ToLower(filename)) == br.Extension() { mr.ByName = true } diff --git a/bz2.go b/bz2.go index 05cb5c7..cc3a751 100644 --- a/bz2.go +++ b/bz2.go @@ -4,10 +4,10 @@ import ( "bytes" "context" "io" + "path/filepath" + "strings" "github.com/dsnet/compress/bzip2" - - "github.com/mholt/archives/internal" ) func init() { @@ -26,7 +26,7 @@ func (bz Bz2) Match(_ context.Context, filename string, stream io.Reader) (Match var mr MatchResult // match filename - if extensions.Contains(filename, bz.Extension()) { + if filepath.Ext(strings.ToLower(filename)) == bz.Extension() { mr.ByName = true } diff --git a/formats_test.go b/formats_test.go index 8220245..927b689 100644 --- a/formats_test.go +++ b/formats_test.go @@ -114,6 +114,44 @@ func checkErr(t *testing.T, err error, msgFmt string, args ...any) { t.Fatalf(msgFmt+": %s", args...) } +func TestIdentifyFindFormatByFileName(t *testing.T) { + tests := []struct { + filename string + expected string + }{ + { + filename: "test.tar", + expected: ".tar", + }, + { + filename: "test.tar.bz2", + expected: ".tar.bz2", + }, + { + filename: "test.tar.br", + expected: ".tar.br", + }, + { + filename: "test.tar.bru", + expected: ".tar", + }, + { + filename: "test.7z", + expected: ".7z", + }, + } + + for _, tt := range tests { + t.Run(tt.filename, func(t *testing.T) { + format, _, err := Identify(context.Background(), tt.filename, nil) + checkErr(t, err, "identifying") + if format.Extension() != tt.expected { + t.Errorf("unexpected extension: %v, expected: %v", format.Extension(), tt.expected) + } + }) + } +} + func TestIdentifyDoesNotMatchContentFromTrimmedKnownHeaderHaving0Suffix(t *testing.T) { // Using the outcome of `n, err := io.ReadFull(stream, buf)` without minding n // may lead to a mis-characterization for cases with known header ending with 0x0 diff --git a/gz.go b/gz.go index 357e927..e0b9d99 100644 --- a/gz.go +++ b/gz.go @@ -4,11 +4,11 @@ import ( "bytes" "context" "io" + "path/filepath" + "strings" "github.com/klauspost/compress/gzip" "github.com/klauspost/pgzip" - - "github.com/mholt/archives/internal" ) func init() { @@ -38,7 +38,7 @@ func (gz Gz) Match(_ context.Context, filename string, stream io.Reader) (MatchR var mr MatchResult // match filename - if extensions.Contains(filename, gz.Extension()) { + if filepath.Ext(strings.ToLower(filename)) == gz.Extension() { mr.ByName = true } diff --git a/internal/extensionutils.go b/internal/extensionutils.go deleted file mode 100644 index 84b7abe..0000000 --- a/internal/extensionutils.go +++ /dev/null @@ -1,18 +0,0 @@ -package extensions - -import ( - "slices" - "strings" -) - -func EndsWith(path string, extension string) bool { - extensions := strings.Split(strings.ToLower(path), ".") - ext := strings.Trim(extension, ".") - return extensions[len(extensions)-1] == ext -} - -func Contains(path string, extension string) bool { - extensions := strings.Split(strings.ToLower(path), ".") - ext := strings.Trim(extension, ".") - return slices.Contains(extensions, ext) -} diff --git a/internal/extensionutils_test.go b/internal/extensionutils_test.go deleted file mode 100644 index c8147c7..0000000 --- a/internal/extensionutils_test.go +++ /dev/null @@ -1,53 +0,0 @@ -package extensions - -import ( - "testing" -) - -func TestEndsWith(t *testing.T) { - for _, tc := range []struct { - input string - extension string - want bool - }{ - {input: "test.tar", extension: "tar", want: true}, - {input: "test.tar", extension: "gz", want: false}, - {input: "test.tar.gz", extension: "tar", want: false}, - {input: "test.tar.gz", extension: "gz", want: true}, - {input: "test.tar.br", extension: "br", want: true}, - {input: "test.tar.br", extension: "bru", want: false}, - } { - t.Run(tc.input, func(t *testing.T) { - for _, ext := range []string{tc.extension, "." + tc.extension} { - got := EndsWith(tc.input, ext) - if got != tc.want { - t.Errorf("want: '%v', got: '%v')", tc.want, got) - } - } - }) - } -} - -func TestContains(t *testing.T) { - for _, tc := range []struct { - input string - extension string - want bool - }{ - {input: "test.tar", extension: "tar", want: true}, - {input: "test.tar", extension: "gz", want: false}, - {input: "test.tar.gz", extension: "tar", want: true}, - {input: "test.tar.gz", extension: "gz", want: true}, - {input: "test.tar.br", extension: "br", want: true}, - {input: "test.tar.br", extension: "bru", want: false}, - } { - t.Run(tc.input, func(t *testing.T) { - for _, ext := range []string{tc.extension, "." + tc.extension} { - got := Contains(tc.input, ext) - if got != tc.want { - t.Errorf("want: '%v', got: '%v')", tc.want, got) - } - } - }) - } -} diff --git a/lz4.go b/lz4.go index d7a2a0d..d5f2b86 100644 --- a/lz4.go +++ b/lz4.go @@ -4,10 +4,10 @@ import ( "bytes" "context" "io" + "path/filepath" + "strings" "github.com/pierrec/lz4/v4" - - "github.com/mholt/archives/internal" ) func init() { @@ -26,7 +26,7 @@ func (lz Lz4) Match(_ context.Context, filename string, stream io.Reader) (Match var mr MatchResult // match filename - if extensions.Contains(filename, lz.Extension()) { + if filepath.Ext(strings.ToLower(filename)) == lz.Extension() { mr.ByName = true } diff --git a/lzip.go b/lzip.go index 00dcad3..fa7fdc1 100644 --- a/lzip.go +++ b/lzip.go @@ -4,10 +4,10 @@ import ( "bytes" "context" "io" + "path/filepath" + "strings" "github.com/sorairolake/lzip-go" - - "github.com/mholt/archives/internal" ) func init() { @@ -24,7 +24,7 @@ func (lz Lzip) Match(_ context.Context, filename string, stream io.Reader) (Matc var mr MatchResult // match filename - if extensions.EndsWith(filename, lz.Extension()) { + if filepath.Ext(strings.ToLower(filename)) == lz.Extension() { mr.ByName = true } diff --git a/minlz.go b/minlz.go index 15378d3..b00a30c 100644 --- a/minlz.go +++ b/minlz.go @@ -4,10 +4,10 @@ import ( "bytes" "context" "io" + "path/filepath" + "strings" "github.com/minio/minlz" - - "github.com/mholt/archives/internal" ) func init() { @@ -27,7 +27,7 @@ func (mz MinLZ) Match(_ context.Context, filename string, stream io.Reader) (Mat var mr MatchResult // match filename - if extensions.Contains(filename, mz.Extension()) { + if filepath.Ext(strings.ToLower(filename)) == mz.Extension() { mr.ByName = true } diff --git a/rar.go b/rar.go index 0286b54..9669780 100644 --- a/rar.go +++ b/rar.go @@ -10,11 +10,11 @@ import ( "log" "os" "path" + "path/filepath" + "strings" "time" "github.com/nwaples/rardecode/v2" - - "github.com/mholt/archives/internal" ) func init() { @@ -61,7 +61,7 @@ func (r Rar) Match(_ context.Context, filename string, stream io.Reader) (MatchR var mr MatchResult // match filename - if extensions.Contains(filename, r.Extension()) { + if filepath.Ext(strings.ToLower(filename)) == r.Extension() { mr.ByName = true } diff --git a/sz.go b/sz.go index 11be929..bbad8f1 100644 --- a/sz.go +++ b/sz.go @@ -4,10 +4,10 @@ import ( "bytes" "context" "io" + "path/filepath" + "strings" "github.com/klauspost/compress/s2" - - "github.com/mholt/archives/internal" ) func init() { @@ -52,8 +52,8 @@ func (sz Sz) Match(_ context.Context, filename string, stream io.Reader) (MatchR var mr MatchResult // match filename - if extensions.Contains(filename, sz.Extension()) || - extensions.Contains(filename, ".s2") { + if filepath.Ext(strings.ToLower(filename)) == sz.Extension() || + filepath.Ext(strings.ToLower(filename)) == ".s2" { mr.ByName = true } diff --git a/tar.go b/tar.go index b1a057b..96c495a 100644 --- a/tar.go +++ b/tar.go @@ -8,8 +8,7 @@ import ( "io" "io/fs" "log" - - "github.com/mholt/archives/internal" + "strings" ) func init() { @@ -48,7 +47,7 @@ func (t Tar) Match(_ context.Context, filename string, stream io.Reader) (MatchR var mr MatchResult // match filename - if extensions.Contains(filename, t.Extension()) { + if strings.Contains(strings.ToLower(filename), t.Extension()) { mr.ByName = true } diff --git a/xz.go b/xz.go index d243329..717d477 100644 --- a/xz.go +++ b/xz.go @@ -4,11 +4,11 @@ import ( "bytes" "context" "io" + "path/filepath" + "strings" fastxz "github.com/mikelolasagasti/xz" "github.com/ulikunitz/xz" - - "github.com/mholt/archives/internal" ) func init() { @@ -25,7 +25,7 @@ func (x Xz) Match(_ context.Context, filename string, stream io.Reader) (MatchRe var mr MatchResult // match filename - if extensions.Contains(filename, x.Extension()) { + if filepath.Ext(strings.ToLower(filename)) == x.Extension() { mr.ByName = true } diff --git a/zip.go b/zip.go index 5d2afd3..630bd6c 100644 --- a/zip.go +++ b/zip.go @@ -10,6 +10,7 @@ import ( "log" "os" "path" + "path/filepath" "strings" szip "github.com/STARRY-S/zip" @@ -19,8 +20,6 @@ import ( "github.com/klauspost/compress/zip" "github.com/klauspost/compress/zstd" "github.com/ulikunitz/xz" - - "github.com/mholt/archives/internal" ) func init() { @@ -87,7 +86,7 @@ func (z Zip) Match(_ context.Context, filename string, stream io.Reader) (MatchR var mr MatchResult // match filename - if extensions.Contains(filename, z.Extension()) { + if filepath.Ext(strings.ToLower(filename)) == z.Extension() { mr.ByName = true } diff --git a/zlib.go b/zlib.go index 08190e9..3730e48 100644 --- a/zlib.go +++ b/zlib.go @@ -3,10 +3,10 @@ package archives import ( "context" "io" + "path/filepath" + "strings" "github.com/klauspost/compress/zlib" - - "github.com/mholt/archives/internal" ) func init() { @@ -25,7 +25,7 @@ func (zz Zlib) Match(_ context.Context, filename string, stream io.Reader) (Matc var mr MatchResult // match filename - if extensions.Contains(filename, zz.Extension()) { + if filepath.Ext(strings.ToLower(filename)) == zz.Extension() { mr.ByName = true } diff --git a/zstd.go b/zstd.go index e0ce6f9..e5f717a 100644 --- a/zstd.go +++ b/zstd.go @@ -4,10 +4,10 @@ import ( "bytes" "context" "io" + "path/filepath" + "strings" "github.com/klauspost/compress/zstd" - - "github.com/mholt/archives/internal" ) func init() { @@ -27,7 +27,7 @@ func (zs Zstd) Match(_ context.Context, filename string, stream io.Reader) (Matc var mr MatchResult // match filename - if extensions.Contains(filename, zs.Extension()) { + if filepath.Ext(strings.ToLower(filename)) == zs.Extension() { mr.ByName = true }