summaryrefslogtreecommitdiff
path: root/vendor/github.com/klauspost/compress/zstd/zip.go
diff options
context:
space:
mode:
authorDan Čermák <dcermak@suse.com>2022-03-17 13:40:46 +0100
committerDan Čermák <dcermak@suse.com>2022-03-21 13:21:25 +0100
commit63bf3991ef14959983ecd86c406bd941c908157b (patch)
treede28b99f4c787e284e36df270aac29a1a2b104ca /vendor/github.com/klauspost/compress/zstd/zip.go
parent248dbf6089922903d12553497a2faae27d1b503b (diff)
downloadpodman-63bf3991ef14959983ecd86c406bd941c908157b.tar.gz
podman-63bf3991ef14959983ecd86c406bd941c908157b.tar.bz2
podman-63bf3991ef14959983ecd86c406bd941c908157b.zip
vendor containers/storage with https://github.com/containers/storage/pull/1165
Signed-off-by: Dan Čermák <dcermak@suse.com>
Diffstat (limited to 'vendor/github.com/klauspost/compress/zstd/zip.go')
-rw-r--r--vendor/github.com/klauspost/compress/zstd/zip.go18
1 files changed, 8 insertions, 10 deletions
diff --git a/vendor/github.com/klauspost/compress/zstd/zip.go b/vendor/github.com/klauspost/compress/zstd/zip.go
index 967f29b31..ffffcbc25 100644
--- a/vendor/github.com/klauspost/compress/zstd/zip.go
+++ b/vendor/github.com/klauspost/compress/zstd/zip.go
@@ -20,7 +20,7 @@ const ZipMethodPKWare = 20
var zipReaderPool sync.Pool
-// newZipReader cannot be used since we would leak goroutines...
+// newZipReader creates a pooled zip decompressor.
func newZipReader(r io.Reader) io.ReadCloser {
dec, ok := zipReaderPool.Get().(*Decoder)
if ok {
@@ -44,10 +44,14 @@ func (r *pooledZipReader) Read(p []byte) (n int, err error) {
r.mu.Lock()
defer r.mu.Unlock()
if r.dec == nil {
- return 0, errors.New("Read after Close")
+ return 0, errors.New("read after close or EOF")
}
dec, err := r.dec.Read(p)
-
+ if err == io.EOF {
+ err = r.dec.Reset(nil)
+ zipReaderPool.Put(r.dec)
+ r.dec = nil
+ }
return dec, err
}
@@ -112,11 +116,5 @@ func ZipCompressor(opts ...EOption) func(w io.Writer) (io.WriteCloser, error) {
// ZipDecompressor returns a decompressor that can be registered with zip libraries.
// See ZipCompressor for example.
func ZipDecompressor() func(r io.Reader) io.ReadCloser {
- return func(r io.Reader) io.ReadCloser {
- d, err := NewReader(r, WithDecoderConcurrency(1), WithDecoderLowmem(true))
- if err != nil {
- panic(err)
- }
- return d.IOReadCloser()
- }
+ return newZipReader
}