diff --git a/zstd.go b/zstd.go index 7c9951acc..c87241f49 100644 --- a/zstd.go +++ b/zstd.go @@ -1,28 +1,16 @@ package sarama import ( - "sync" - "github.com/klauspost/compress/zstd" ) -var ( - zstdDec *zstd.Decoder - zstdEnc *zstd.Encoder - - zstdEncOnce, zstdDecOnce sync.Once -) +var zstdDec, _ = zstd.NewReader(nil) +var zstdEnc, _ = zstd.NewWriter(nil, zstd.WithZeroFrames(true)) 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 }