Skip to main content

Crate zrip

Crate zrip 

Source
Expand description

Fast, pure-Rust zstd compression.

zrip implements zstd compression levels -7 through 4 (Fast and DFast strategies), targeting high-speed compression for data transfers. It produces standard zstd frames decompressible by any compliant decoder.

§Quick start

let data = b"hello world, hello zstd compression!";

// Compress at level 1 (fast)
let compressed = zrip::compress(data, 1).unwrap();

// Decompress
let decompressed = zrip::decompress(&compressed).unwrap();
assert_eq!(&decompressed, data);

§Compression levels

LevelStrategyNotes
-7..=-1FastFastest encode, lowest ratio
0Library default (currently level 1)
1..=2FastGood balance for network transfers
3..=4DFastBetter ratio, still fast

§Streaming

FrameEncoder and FrameDecoder implement std::io::Write and std::io::Read for streaming compression and decompression.

use std::io::{Write, Read};

let mut encoder = zrip::FrameEncoder::new(Vec::new(), 1).unwrap();
encoder.write_all(b"streaming data").unwrap();
let compressed = encoder.finish().unwrap();

let mut decoder = zrip::FrameDecoder::new(&compressed[..]);
let mut output = Vec::new();
decoder.read_to_end(&mut output).unwrap();
assert_eq!(&output, b"streaming data");

§Long distance matching

For data with long-range repetitions, enable LDM via Options:

let opts = zrip::Options::default().window_log(24).ldm(true);
let compressed = zrip::compress_opts(b"data with long-range repeats", 1, &opts).unwrap();

§Buffer reuse

For repeated compression/decompression, CompressContext and DecompressContext reuse internal buffers across calls, reducing allocation overhead in hot loops.

§Feature flags

  • std (default): enables alloc and standard library support.
  • alloc: no_std with heap allocation (Vec, etc.).
  • frame (default): frame header parsing/writing; implies std.
  • ldm (default): long distance matching for large-window compression.
  • dict_builder: COVER/FastCOVER dictionary training.
  • nightly: #[optimize] attributes for hot paths.

Modules§

dict
error
frame
Zstd frame format constants.

Structs§

CompressContext
Reusable compression context that amortizes hash table and buffer allocations.
DecompressContext
Reusable decompression context that amortizes buffer allocations.
Dictionary
A pre-trained zstd dictionary for improved compression of small data.
FrameDecoder
Streaming zstd decompressor implementing Read.
FrameEncoder
Streaming zstd compressor implementing Write.
LdmParams
Parameters for Long Distance Matching.
LevelParams
Compression parameters for a specific level.
Options
Options for large-window and LDM compression, orthogonal to level.

Enums§

CompressError
Error returned by compression functions.
DecompressError
Error returned by decompression functions.
ZstdError
Unified error type wrapping both compression and decompression errors.

Constants§

DEFAULT_DECOMPRESS_LIMIT
DEFAULT_LEVEL
Default compression level used when level 0 is requested.
SAFE_DECOMPRESS_LIMIT
A conservative output limit (128 MiB) suitable for decompressing untrusted input.

Functions§

compress
compress_bound
compress_into
compress_opts
compress_with_dict
compress_with_params
decompress
decompress_into
decompress_with_dict
decompress_with_limit