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

Commit

Permalink
return zip.Reader in FileSystem if file is a zip file (#349)
Browse files Browse the repository at this point in the history
* return zip.Reader in FileSystem if file is a zip file

* Update fs.go

Co-authored-by: Matt Holt <[email protected]>
  • Loading branch information
WeidiDeng and mholt authored Sep 10, 2022
1 parent b4f84f1 commit be18265
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 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,13 @@ 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.
// 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"
"github.com/klauspost/compress/zstd"
"github.com/ulikunitz/xz"
"golang.org/x/text/encoding"
Expand Down

0 comments on commit be18265

Please sign in to comment.