Skip to main content

Crate compress_utils

Crate compress_utils 

Source
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§

stream
Streaming compression and decompression as standard std::io adapters.

Structs§

Error
An error returned by the library: a Status code 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 Error so callers can match on the exact failure. Values match the CU_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 data with algo at level (1 fastest ..= 10 smallest).
decompress
Decompress data produced by algo. 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) need decompress_with_capacity instead.
decompress_with_capacity
Decompress data into at most capacity bytes. 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 decompress will accept. Defaults to 1 GiB; 0 disables the cap. Does not affect the streaming Decompressor, which should enforce its own limit.
version
The linked library version string ("MAJOR.MINOR.PATCH").