Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Examples

The recipes below include complete programs and round-trip assertions. Examples use the default std, compression, and decompression features unless stated otherwise. The documentation workflow compiles and runs their Rust code against the current checkout.

TaskRecipeFeatures / extra dependency
Compress and decompress bytesFirst round tripDefault
Reuse codec and destination memoryReuse the workspaceDefault
Pick a level and explicit parametersChoose a level firstDefault
Write into a caller-owned sliceOutput buffersDefault
Decode untrusted input with limitsSet limits for untrusted inputDefault
Compress small records with a dictionaryPrepared dictionariesDefault
Write a raw stream incrementallyStream through WriteDefault
Drive a raw or framed encoder with tiny buffersSans I/O compressionDefault; framed for frames
Decode arriving chunks and resource eventsSans I/O decompressionDefault; framed for frames
Read or write raw, parallel, and framed streamsRead / Write I/ODefault; framed for frames
Use scoped CPU workersCompressing a sliceDefault
Reuse a Rayon thread poolRunning tasks with RayonDefault + rayon
Stream through parallel workersReader and writer adaptersDefault
Package compressed and stored resourcesOne container, two resourcesframed
Add resource names and write incrementallyWrite resources and metadataframed
Read just the selected resourceIndexed resource readsframed

Run from the repository

The runnable user recipes are complete programs embedded in the guides. To compile and run all of them against this checkout:

python3 scripts/docs.py test-examples

The repository also provides a profiling driver:

git submodule update --init --recursive
cargo run --release --example profile_compressor -- testdata/alice29.txt

See benchmarking for profiling options and the C comparison.

For a parallel batch, all taken tasks must run or be dropped before finalization. For a streaming adapter, keep workers running while the adapter blocks. For writers, finish each resource and the enclosing stream or container explicitly.

Verify the documented recipes

python3 scripts/docs.py test-examples

This creates a temporary Cargo consumer under target/, depends on the local crate with framed enabled and on Rayon, and runs each fenced Rust program from the recipe guides: getting started, configuration, buffers, decompression, streaming, parallel, frames, Sans I/O compression/decompression, the I/O guide, and dictionaries. It does not exercise the codec with --all-features, because that would also enable no_std and remove the std APIs these recipes demonstrate.