Expand description
§compress-utils
A unified, safe Rust interface to eight compression algorithms — Zstandard,
Brotli, zlib, gzip, bzip2, LZ4, XZ/LZMA and Snappy — over a single C core.
Every algorithm speaks the same API; switching codecs is a one-enum change.
Raw DEFLATE, raw LZ4 blocks and raw LZO1X blocks (decompression only) are
also available; raw blocks don’t record their size, so decode them with
decompress_with_capacity.
use compress_utils::{compress, decompress, Algorithm};
let data = b"the quick brown fox jumps over the lazy dog";
let packed = compress(Algorithm::Zstd, data, 5)?;
let restored = decompress(Algorithm::Zstd, &packed)?;
assert_eq!(&restored, data);For large or incremental data, use the streaming adapters Compressor
(an std::io::Write) and Decompressor (an std::io::Read) in the
stream module.
Re-exports§
pub use stream::Compressor;pub use stream::Decompressor;
Modules§
Structs§
- Error
- An error returned by the library: a
Statuscode plus the human-readable message the C core reported.
Enums§
- Algorithm
- A compression algorithm. Values match the
CU_ALGO_*constants in the C ABI. - Status
- A C ABI status code, carried on
Errorso callers can match on the exact failure. Values match theCU_ERR_*constants.
Constants§
- DEFAULT_
LEVEL - A sensible middle-of-the-road compression level, matching the C++, Python and Go bindings. Levels run 1 (fastest) ..= 10 (smallest).
Functions§
- compress
- Compress
datawithalgoatlevel(1 fastest ..= 10 smallest). - decompress
- Decompress
dataproduced byalgo. When the wire format records the decompressed size it is recovered in a single pass; otherwise this falls back to the streaming decoder (as the C++/Python/Go bindings do). Formats that record no size and can’t be streamed (Algorithm::Lz4Raw) needdecompress_with_capacityinstead. - decompress_
with_ capacity - Decompress
datainto at mostcapacitybytes. The capacity is an upper bound on the output, allocated up front; the result holds only the bytes written. Required for formats that don’t record their size and can’t be streamed (Algorithm::Lz4Raw), and skips the size probe for every other algorithm. - set_
max_ decompressed_ size - Set a global cap on the output size one-shot
decompresswill accept. Defaults to 1 GiB;0disables the cap. Does not affect the streamingDecompressor, which should enforce its own limit. - version
- The linked library version string (
"MAJOR.MINOR.PATCH").