finclip-app-manager/vendor/github.com/Shopify/sarama/zstd.go

28 lines
511 B
Go
Raw Permalink Normal View History

2023-11-02 18:36:36 +08:00
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
}