pub fn compress_with_level(
ct: CompressionType,
data: &[u8],
level: i32,
) -> Result<Bytes, CompressionError>Expand description
Compress data using the codec identified by ct at compression level
(KIP-390).
The level must pass CompressionType::check_level, which follows Kafka’s
CompressionType.levelValidator. compress(ct, data) gives the same bytes
as this function with CompressionType::default_level.
- gzip: the deflate level. -1 is the zlib default, which is level 6.
- zstd: the zstd level.
- lz4: Kafka’s
Lz4BlockOutputStreamuses the fast compressor at the default level 9, and LZ4 HC for every other level in1..=17. This function matches that split.
§Errors
Returns CompressionError::InvalidLevel when the level is out of range,
or when the codec (none, snappy) has no levels. Returns
CompressionError::FeatureDisabled when the codec’s Cargo feature is not
enabled.