2020-11-17 16:29:00 +00:00
|
|
|
package blobstor
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/klauspost/compress/zstd"
|
|
|
|
)
|
|
|
|
|
|
|
|
func noOpCompressor(data []byte) []byte {
|
|
|
|
return data
|
|
|
|
}
|
|
|
|
|
|
|
|
func noOpDecompressor(data []byte) ([]byte, error) {
|
|
|
|
return data, nil
|
|
|
|
}
|
|
|
|
|
2020-11-18 12:27:21 +00:00
|
|
|
func zstdCompressor() (func([]byte) []byte, error) {
|
2020-11-17 16:29:00 +00:00
|
|
|
enc, err := zstd.NewWriter(nil)
|
|
|
|
if err != nil {
|
2020-11-18 12:27:21 +00:00
|
|
|
return nil, err
|
2020-11-17 16:29:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return func(data []byte) []byte {
|
|
|
|
return enc.EncodeAll(data, make([]byte, 0, len(data)))
|
2020-11-18 12:27:21 +00:00
|
|
|
}, nil
|
2020-11-17 16:29:00 +00:00
|
|
|
}
|
|
|
|
|
2020-11-18 12:27:21 +00:00
|
|
|
func zstdDecompressor() (func([]byte) ([]byte, error), error) {
|
2020-11-17 16:29:00 +00:00
|
|
|
dec, err := zstd.NewReader(nil)
|
|
|
|
if err != nil {
|
2020-11-18 12:27:21 +00:00
|
|
|
return nil, err
|
2020-11-17 16:29:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return func(data []byte) ([]byte, error) {
|
|
|
|
return dec.DecodeAll(data, nil)
|
2020-11-18 12:27:21 +00:00
|
|
|
}, nil
|
2020-11-17 16:29:00 +00:00
|
|
|
}
|