| 1 |
//go:build !datadog |
| 2 |
// +build !datadog |
| 3 |
|
| 4 |
package desync |
| 5 |
|
| 6 |
import "github.com/klauspost/compress/zstd" |
| 7 |
|
| 8 |
// Create a reader/writer that caches compressors. |
| 9 |
var ( |
| 10 |
encoder, _ = zstd.NewWriter(nil) |
| 11 |
decoder, _ = zstd.NewReader(nil) |
| 12 |
) |
| 13 |
|
| 14 |
// Compress a block using the only (currently) supported algorithm |
| 15 |
func Compress(src []byte) ([]byte, error) { |
| 16 |
return encoder.EncodeAll(src, make([]byte, 0, len(src))), nil |
| 17 |
} |
| 18 |
|
| 19 |
// Decompress a block using the only supported algorithm. If you already have |
| 20 |
// a buffer it can be passed into out and will be used. If out=nil, a buffer |
| 21 |
// will be allocated. |
| 22 |
func Decompress(dst, src []byte) ([]byte, error) { |
| 23 |
return decoder.DecodeAll(src, dst) |
| 24 |
} |