blob: 58880e2b4b531c870b95d13ae7d49f85c2154d31 [file] [log] [blame]
package sarama
import (
"github.com/klauspost/compress/zstd"
"sync"
)
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
}