tile38/vendor/github.com/Shopify/sarama/zstd.go

29 lines
512 B
Go
Raw Permalink Normal View History

2020-06-25 00:20:22 +03:00
package sarama
import (
"sync"
"github.com/klauspost/compress/zstd"
)
var (
zstdDec *zstd.Decoder
zstdEnc *zstd.Encoder
zstdEncOnce, zstdDecOnce sync.Once
)
func zstdDecompress(dst, src []byte) ([]byte, error) {
zstdDecOnce.Do(func() {
zstdDec, _ = zstd.NewReader(nil)
})
return zstdDec.DecodeAll(src, dst)
}
func zstdCompress(dst, src []byte) ([]byte, error) {
zstdEncOnce.Do(func() {
zstdEnc, _ = zstd.NewWriter(nil, zstd.WithZeroFrames(true))
})
return zstdEnc.EncodeAll(src, dst), nil
}