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_slice, compress_to_uninitdecompress_to_slice, decompress_to_uninitBuffers 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
Any of the above with a dictionarycompress_with_dictionary*, start_with_dictionary, into_session_with_dictionary, writer_with_dictionary, reader_with_dictionarydecompress_with_dictionary*, start_with_dictionary, into_session_with_dictionary, writer_with_dictionary, reader_with_dictionaryDictionaries

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

Parallel compression

ParallelCompressor (in mzstd::compressor::parallel) is a separate execution strategy for compression: it splits one frame into independent segments and hands them to your executor as tasks. The library does not create a thread pool. The output is a valid Zstandard frame, 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
Push or pull through std::io across your threadswriter, reader

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

Guides by task

TaskRead
Pick a level, parameters, 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 resource eventsSans I/O decompression
Split a job across workersParallel compression
Package several resourcesFraming containers
Share a dictionary or use magicless framesDictionaries and extended formats
Copy a complete programExamples

Errors

ConfigError covers encoder configuration, DecodeConfigError decoder limits, DictionaryError dictionary preparation, and EncodeError / DecodeError codec failures. Failed decoder calls report exact progress in DecodeFailure; output delivered before final validation can be partial. I/O adapters return std::io::Error, with the codec error as its source.

Reference