Skip to content
This repository has been archived by the owner on Nov 19, 2024. It is now read-only.

return zip.Reader in FileSystem if file is a zip file #349

Merged
merged 2 commits into from
Sep 10, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 10 additions & 0 deletions fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"runtime"
"strings"
"time"

"github.com/klauspost/compress/zip"
)

// FileSystem opens the file at root as a read-only file system. The root may be a
Expand Down Expand Up @@ -54,6 +56,14 @@ func FileSystem(root string) (fs.FS, error) {
if format != nil {
// TODO: we only really need Extractor and Decompressor here, not the combined interfaces...
if af, ok := format.(Archival); ok {
// zip.Reader is more performant thant ArchiveFS, because zip.Reader caches content information
// and zip.Reader can open several content files concurrently because of io.ReaderAt requirement
// while ArchiveFS can't.

mholt marked this conversation as resolved.
Show resolved Hide resolved
// zip.Reader doesn't suffer from issue #330 and #310 according to local test
if _, ok = format.(Zip); ok {
return zip.NewReader(file, info.Size())
}
return ArchiveFS{Path: root, Format: af}, nil
}
if cf, ok := format.(Compression); ok {
Expand Down
2 changes: 1 addition & 1 deletion zip.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package archiver

import (
"archive/zip"
"bytes"
"context"
"errors"
Expand All @@ -13,6 +12,7 @@ import (
"strings"

"github.com/dsnet/compress/bzip2"
"github.com/klauspost/compress/zip"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha, thanks!

"github.com/klauspost/compress/zstd"
"github.com/ulikunitz/xz"
"golang.org/x/text/encoding"
Expand Down