forked from TrueCloudLab/frostfs-node
[#176] blobstor: Handle error of zstd (de)compressor creation
In previous implementation WithCompressObjects returned Option than could panic if zstd (de)compressor creation failed with error. From now errors with (de)compressor creation result in an option without using data compression. In this case, the error is written to the log passed to the option constructor. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
6f8c45d61b
commit
f194c840d7
2 changed files with 32 additions and 12 deletions
|
@ -12,24 +12,24 @@ func noOpDecompressor(data []byte) ([]byte, error) {
|
|||
return data, nil
|
||||
}
|
||||
|
||||
func zstdCompressor() func([]byte) []byte {
|
||||
func zstdCompressor() (func([]byte) []byte, error) {
|
||||
enc, err := zstd.NewWriter(nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return func(data []byte) []byte {
|
||||
return enc.EncodeAll(data, make([]byte, 0, len(data)))
|
||||
}
|
||||
}, nil
|
||||
}
|
||||
|
||||
func zstdDecompressor() func([]byte) ([]byte, error) {
|
||||
func zstdDecompressor() (func([]byte) ([]byte, error), error) {
|
||||
dec, err := zstd.NewReader(nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return func(data []byte) ([]byte, error) {
|
||||
return dec.DecodeAll(data, nil)
|
||||
}
|
||||
}, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue