From cc2a62aa84e283b8b4e2700ca839c7eed846a340 Mon Sep 17 00:00:00 2001 From: Richard Gomez Date: Thu, 13 Jun 2024 12:57:17 -0400 Subject: [PATCH] feat(gzip): expose gzip.Multistream --- gz.go | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/gz.go b/gz.go index e747d030..b9873f19 100644 --- a/gz.go +++ b/gz.go @@ -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 @@ -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