blob: 58880e2b4b531c870b95d13ae7d49f85c2154d31 [file] [log] [blame]
Pragya Arya324337e2020-02-20 14:35:08 +05301package sarama
2
3import (
4 "github.com/klauspost/compress/zstd"
5 "sync"
6)
7
8var (
9 zstdDec *zstd.Decoder
10 zstdEnc *zstd.Encoder
11
12 zstdEncOnce, zstdDecOnce sync.Once
13)
14
15func zstdDecompress(dst, src []byte) ([]byte, error) {
16 zstdDecOnce.Do(func() {
17 zstdDec, _ = zstd.NewReader(nil)
18 })
19 return zstdDec.DecodeAll(src, dst)
20}
21
22func zstdCompress(dst, src []byte) ([]byte, error) {
23 zstdEncOnce.Do(func() {
24 zstdEnc, _ = zstd.NewWriter(nil, zstd.WithZeroFrames(true))
25 })
26 return zstdEnc.EncodeAll(src, dst), nil
27}