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; to choose what runs inside a frame, read graphs.

Both codecs

I/O shapeCompressionDecompression
Return a new Vec<u8>Compressor::compressDecompressor::decompress
Append to an existing Veccompress_intodecompress_into
Write into a caller-owned slicecompress_to_slicedecompress_to_slice
Write into uninitialized memorycompress_to_uninitdecompress_to_uninit
Typed and multiple inputs / outputscompress_inputs, compress_inputs_intodecompress_typed → Vec<TypedOutput>
Choose the graph / codec nodesCompressor::builder(..).with_graph(..) / ParallelCompressor::builder(..).with_graph(..)— (the frame carries its own)
Pull output through std::io::ReadCompressor::readerDecompressor::reader
Push input through std::io::WriteCompressor::writerDecompressor::writer
Drive input/output incrementallystart → EncoderSessionstart → DecoderSession
Same, into uninitialized memoryEncoderSession::process_uninitDecoderSession::process_uninit
Same, with the session owning the codecinto_session → EncoderSessionOwnedinto_session → DecoderSessionOwned

The decoder needs no graph: a frame records the codecs that produced it. Compressor and Decompressor own reusable working state. Keep one alive across payloads when allocation reuse matters.

Parallel compression

ParallelCompressor lives in mopenzl::compressor::parallel and is unavailable with no_std. It splits one input into segments and hands them to your executor as tasks; the library does not create a thread pool. Streaming buffers compressed chunks until finish, when the total input size is known.

I/O shapeEntry point
Split one known input across your threadsprepare_slice / prepare_source → ScopedParallelBatch
Stream chunked input across your threadsstart → ParallelEncoderSession + ParallelTaskQueue
Same, into uninitialized memoryParallelEncoderSession::process_uninit
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, sources, staging, and streaming.

Guides by task

TaskRead
Choose graphs, selectors, segmenters or codec pipelinesGraphs
See what each codec does and which feature enables itCodecs
Compress integers, records or stringsStructured data
Implement and register an application-defined codecCustom codecs
Use a Zstandard dictionaryDictionaries
Set the level, format version, checksums or Cargo featuresConfiguration and features
Control allocations, or write into uninitialized memoryBuffers and memory reuse
Decode untrusted input with resource limitsDecompression and limits
Read a frame’s comment, version or output types without decodingFrame metadata
Understand readers, writers, sessions, and finishStreaming and completion
Connect synchronous I/ORead / Write I/O
Drive caller-owned buffers directlySans I/O compression and decompression
Schedule compression on your own threadsParallel compression
Use a different graph for each indexed resourceFraming containers and graph recipes (framed feature)
Copy a complete programExamples

Errors

ConfigError covers configuration, EncodeError covers compression (including EncodeError::Graph(GraphError) for graph failures), DecodeError covers decompression, graph::GraphError covers graph construction, and dict::DictError covers dictionaries. I/O adapters return std::io::Error; writer finalization preserves the writer in FinishError.

Reference