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 qualityChoose a quality firstDefault
Write into a caller-owned sliceOutput buffersDefault
Decode untrusted input with budgetsSet limits for untrusted inputDefault
Write a raw stream incrementallyStream through WriteDefault
Drive a raw or framed encoder with tiny buffersSans I/O compressionDefault; experimental for frames
Decode arriving chunks and resource eventsSans I/O decompressionDefault; experimental for frames
Read or write raw, parallel, and framed streamsRead / Write I/ODefault; experimental 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 resourcesexperimental
Add resource names and write incrementallyWrite resources and metadataexperimental
Read just the selected resourceIndexed resource readsexperimental

Run from the repository

Initialize the C reference submodule used by development builds:

git submodule update --init --recursive
cargo run --release --example compress

The parallel file example uses caller-owned scoped threads and disk staging. The destination must not already exist:

cargo run --release --example parallel -- input.bin output.br

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 experimental 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, and the I/O guide. It does not exercise the codec with --all-features, because that would also enable no_std and remove the std APIs these recipes demonstrate.