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

Choose your API

Compression and decompression expose the same I/O shapes. Pick the row that matches how your application already moves bytes, then follow its guide. New to the crate? Start with getting started.

Both codecs

I/O shapeCompressionDecompressionGuide
Return a new Vec<u8>Compressor::compressDecompressor::decompressGetting started
Append to an existing Veccompress_intodecompress_intoBuffers and memory reuse
Write into a caller-owned slicecompress_to_slicedecompress_to_sliceBuffers and memory reuse
Pull output through std::io::ReadCompressor::readerDecompressor::readerRead / Write I/O
Push input through std::io::WriteCompressor::writerDecompressor::writerRead / Write I/O
Drive input and output incrementallystart → EncoderSessionstart → DecoderSessionSans I/O compression, decompression
Same, with the session owning the codecinto_session → EncoderSessionOwnedinto_session → DecoderSessionOwnedSans I/O compression, decompression

Compressor and Decompressor own reusable working state. Keep one alive across payloads when allocation reuse matters.

Parallel compression

ParallelCompressor is a separate execution strategy for compression: it splits the input into independent segments and hands them to your executor as tasks. The library does not create a thread pool. The output is one ordinary Brotli stream, decoded by the ordinary Decompressor. Requires std.

I/O shapeEntry point
Split one known input across your threadsprepare_slice / prepare_source → ScopedParallelBatch
Stream chunked input across your threadsstart → ParallelEncoderSession + ParallelTaskQueue
Same, with the session owning the compressorinto_session → ParallelEncoderSessionOwned
Pull parallel output through std::io::Readreader → ParallelEncoderReader + ParallelTaskQueue
Push input through std::io::Write across your threadswriter → ParallelEncoderWriter + ParallelTaskQueue

See parallel compression for scoped threads, Rayon, budgets, disk staging, and streaming.

Guides by task

TaskRead
Pick a quality, window, or Cargo featuresConfiguration and features
Control allocations and retained memoryBuffers and memory reuse
Decode untrusted input with resource limitsDecompression and limits
Understand readers, writers, sessions, and finishStreaming and completion
Connect readers and writers for every formatRead / Write I/O
Drive compression with caller buffersSans I/O compression
Decode arriving chunks and framed eventsSans I/O decompression
Split a job across workersParallel compression
Write or decode framing containersFraming containers
Share a dictionary or use extended formatsDictionaries and extended formats
Copy a complete programExamples

Errors

ConfigError covers configuration, DictionaryError covers dictionary preparation, EncodeError covers compression, and SizeOverflow covers size-bound arithmetic. I/O adapters return std::io::Error; writer finalization preserves the writer in FinishError.

Reference