mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-15 16:30:55 +01:00
0697164b4f
This is manual merge of the https://github.com/VictoriaMetrics/VictoriaMetrics/pull/152 Thanks to nustinov@gmail.com for the initial pull request.
31 lines
603 B
Go
31 lines
603 B
Go
package common
|
|
|
|
import (
|
|
"compress/gzip"
|
|
"io"
|
|
"sync"
|
|
)
|
|
|
|
// GetGzipReader returns new gzip reader from the pool.
|
|
//
|
|
// Return back the gzip reader when it no longer needed with PutGzipReader.
|
|
func GetGzipReader(r io.Reader) (*gzip.Reader, error) {
|
|
v := gzipReaderPool.Get()
|
|
if v == nil {
|
|
return gzip.NewReader(r)
|
|
}
|
|
zr := v.(*gzip.Reader)
|
|
if err := zr.Reset(r); err != nil {
|
|
return nil, err
|
|
}
|
|
return zr, nil
|
|
}
|
|
|
|
// PutGzipReader returns back gzip reader obtained via GetGzipReader.
|
|
func PutGzipReader(zr *gzip.Reader) {
|
|
_ = zr.Close()
|
|
gzipReaderPool.Put(zr)
|
|
}
|
|
|
|
var gzipReaderPool sync.Pool
|