[#209] compression: Do not store uncompressible data

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2023-04-28 13:50:25 +03:00
parent 529d0bc710
commit a1b4ba9980

View file

@ -87,7 +87,11 @@ func (c *Config) Compress(data []byte) []byte {
return data
}
maxSize := c.encoder.MaxEncodedSize(len(data))
return c.encoder.EncodeAll(data, make([]byte, 0, maxSize))
compressed := c.encoder.EncodeAll(data, make([]byte, 0, maxSize))
if len(data) < len(compressed) {
return data
}
return compressed
}
// Close closes encoder and decoder, returns any error occurred.