pub fn compress(data: &[u8]) -> Option<Vec<u8>>Expand description
Compress a byte slice with zstd.
Returns Some(compressed) if compression reduced the size, or
None if the compressed output is >= the input size. This
ensures compression is never harmful — the caller should store
the block uncompressed when None is returned.
Uses the default compression level (3).
§Example
use bcp_encoder::compression::compress;
let data = "fn main() { }\n".repeat(100);
match compress(data.as_bytes()) {
Some(compressed) => assert!(compressed.len() < data.len()),
None => { /* data was incompressible */ }
}