github.com/quay/claircore@v1.5.28/pkg/ovalutil/pool.go (about) 1 package ovalutil 2 3 import ( 4 "io" 5 "sync" 6 7 "github.com/klauspost/compress/gzip" 8 "github.com/klauspost/compress/zstd" 9 ) 10 11 var ( 12 gzipPool sync.Pool 13 zstdPool sync.Pool 14 ) 15 16 func getGzip(r io.Reader) (*gzip.Reader, error) { 17 z := gzipPool.Get().(*gzip.Reader) 18 if z == nil { 19 return gzip.NewReader(r) 20 } 21 if err := z.Reset(r); err != nil { 22 return nil, err 23 } 24 return z, nil 25 } 26 27 func putGzip(z *gzip.Reader) { 28 gzipPool.Put(z) 29 } 30 31 func getZstd(r io.Reader) (*zstd.Decoder, error) { 32 z := zstdPool.Get().(*zstd.Decoder) 33 if z == nil { 34 return zstd.NewReader(r) 35 } 36 if err := z.Reset(r); err != nil { 37 return nil, err 38 } 39 return z, nil 40 } 41 42 func putZstd(z *zstd.Decoder) { 43 zstdPool.Put(z) 44 }