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

Expose gzip.Reader.Multistream #407

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Changes from all commits
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
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
}

rgmz marked this conversation as resolved.
Show resolved Hide resolved
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
Loading