Expand description
RFC 8878 Zstandard decoder.
The entry points:
StreamingDecoder— implementscrate::io::Readover a compressed byte stream, transparently parsing the frame header and concatenated frames. The typical choice for application code.FrameDecoder— single-frame interface; use when the caller manages the input buffer manually (zero-copy slices, network framing, etc).workspace::WorkspaceDecoder(featurecaller-workspace): streaming decoder over a byte slice the caller sizes and owns, with no allocation and limits on window, output and work. For consumers that account their memory themselves, such as browser bundles verifying a download.DictionaryHandle— pre-parsed dictionary handle. Parse the dictionary bytes once withDictionaryHandle::decode_dictand reuse the handle across every subsequent decode; saves the per-frame dictionary parse cost when the same dictionary is used many times in a row.
Both decoders expose dictionary-aware constructors / methods, though the exact naming differs:
StreamingDecoder::new_with_dictionary_handle/StreamingDecoder::new_with_dictionary_bytesFrameDecoder::decode_all_with_dict_handle/FrameDecoder::decode_all_with_dict_bytes
The _handle variants reuse a previously parsed
DictionaryHandle; the _bytes variants parse the dictionary
per call (suitable for one-off decodes).
Errors surface through errors::FrameDecoderError and the per-decoder
error types in the errors submodule.
Modules§
- errors
- Errors that might occur while decoding zstd formatted data
- workspace
caller-workspace - Streaming decoder that runs entirely in caller-owned memory.
Structs§
- Dictionary
- Zstandard includes support for “raw content” dictionaries, that store bytes optionally used during sequence execution.
- Dictionary
Handle - Shared pre-parsed dictionary handle for repeated decoding.
- Dictionary
Refused - A dictionary a
StreamingDecoderconstructor refused, with what the constructor took by value handed back: the source, unread, since the dictionary is checked before anything is read, and the decoder where the caller passed one (()where the constructor makes its own). - Finished
Frame - The sizes of one frame a
StreamingDecoderdecoded, asStreamingDecoder::read_reporting_framesreports it: what the frame took from the source and what it decoded to, as upstream’sZSTD_trace_decompress_endreports them. - Frame
Decoder - Low level Zstandard decoder that can be used to decompress frames with fine control over when and how many bytes are decoded.
- Frame
Header Info - Frame header fields decoded by
read_frame_header_info, mirroring the values the CZSTD_getFrameHeaderfills into aZSTD_FrameHeader. - Partial
Decode lsm - Outcome of
FrameDecoder::decode_blocks_partial: the decompressed bytes of the requested inner-block range plus where (if anywhere) decoding stopped early. - Resume
Input lsm - Resume input fed to
FrameDecoder::decode_blocks_partial’sresumeargument to continue a cold partial decode without re-decompressing the preceding blocks. - Resume
State lsm - Cross-block decode state needed to resume a cold partial decode at an inner
block boundary, emitted by
FrameDecoder::decode_blocks_partialwhen itsemit_resumeargument istrue(returned inPartialDecode::resume_state) and fed back via that same method’sresumeargument (ResumeInput). - Streaming
Decoder - High level Zstandard frame decoder that can be used to decompress a given Zstandard frame.
Enums§
- Block
Decoding Strategy - Content
Checksum - How the decoder treats a frame’s optional XXH64 content checksum (RFC 8878 Content_Checksum_flag). The XXH64 pass over the decompressed output is a measurable share of decode time, so it is made skippable.
- Frame
Content Size - Decompressed size a frame declares in its header, as read by
read_frame_content_sizewithout decoding the frame body. - Frame
Size Error - Error from
find_frame_compressed_size.
Constants§
- DICTIONARY_
MAGIC - This 4 byte (little endian) magic number refers to the start of a dictionary
- MAXIMUM_
ALLOWED_ WINDOW_ SIZE - Largest window a frame may declare before a decoder that holds the window
itself refuses it, unless
FrameDecoder::set_max_window_sizeraised the ceiling. - MAX_
DECODER_ WINDOW_ SIZE - Largest window any decode accepts, the ceiling
FrameDecoder::set_max_window_sizecan be raised to. The largest window this build decodes on any path, however far the ceiling is raised: upstreamZSTD_WINDOWLOG_MAX,1 << 31on 64-bit targets and1 << 30on 32-bit ones, where a larger window could not be addressed.
Functions§
- find_
frame_ compressed_ size - On-disk byte length of the FIRST frame in
src— magic number, frame header, every block, and the trailing content checksum when present — computed by walking the block headers without decoding any block body. - frame_
decompressed_ bound - Upper bound on the decompressed size of the FIRST frame in
src, without decoding the body. Backs the CZSTD_decompressBound(per-frame term). - frame_
header_ size - Length in bytes of the frame header at the start of
src, including the 4-byte magic number (the offset at which the first block begins). Backs the CZSTD_frameHeaderSize. - read_
frame_ content_ size - Read the decompressed size a frame declares in its header, without decoding the frame body.
- read_
frame_ header_ info - Decode the leading frame header fields of
srcwithout decoding the body.