data2minio/mq/compress.go

28 lines
488 B
Go

package mq
import (
"github.com/klauspost/compress/zstd"
)
// Compress 压缩
func Compress(src []byte) []byte {
encoder, _ := zstd.NewWriter(nil)
zstd.WithEncoderConcurrency(3)
return encoder.EncodeAll(src, make([]byte, 0, len(src)))
}
func UnCompress(src []byte) ([]byte, error) {
d, err := zstd.NewReader(nil)
if err != nil {
return nil, err
}
defer d.Close()
uncompressed, err := d.DecodeAll(src, nil)
if err != nil {
return nil, err
}
return uncompressed, nil
}