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

Commit

Permalink
gzip: expose gzip.Multistream (#407)
Browse files Browse the repository at this point in the history
  • Loading branch information
rgmz authored Jun 13, 2024
1 parent de08bfa commit 07b70a6
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions gz.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ type Gz struct {
// than no compression.
CompressionLevel int

// DisableMultistream controls whether the reader supports multistream files.
// See https://pkg.go.dev/compress/gzip#example-Reader.Multistream
DisableMultistream bool

// Use a fast parallel Gzip implementation. This is only
// effective for large streams (about 1 MB or greater).
Multithreaded bool
Expand Down Expand Up @@ -65,14 +69,19 @@ func (gz Gz) OpenWriter(w io.Writer) (io.WriteCloser, error) {
}

func (gz Gz) OpenReader(r io.Reader) (io.ReadCloser, error) {
var rc io.ReadCloser
var err error
if gz.Multithreaded {
rc, err = pgzip.NewReader(r)
} else {
rc, err = gzip.NewReader(r)
gzR, err := pgzip.NewReader(r)
if gzR != nil && gz.DisableMultistream {
gzR.Multistream(false)
}
return gzR, err
}

gzR, err := gzip.NewReader(r)
if gzR != nil && gz.DisableMultistream {
gzR.Multistream(false)
}
return rc, err
return gzR, err
}

// magic number at the beginning of gzip files
Expand Down

0 comments on commit 07b70a6

Please sign in to comment.