Miscellaneous APIs¶
Frame Inspection¶
Data emitted from zstd compression is encapsulated in a frame. This frame begins with a 4 byte magic number header followed by 2 to 14 bytes describing the frame in more detail. For more info, see https://github.com/facebook/zstd/blob/master/doc/zstd_compression_format.md.
- zstandard.get_frame_parameters(data, format=0)¶
Parse a zstd frame header into frame parameters.
Depending on which fields are present in the frame and their values, the length of the frame parameters varies. If insufficient bytes are passed in to fully parse the frame parameters,
ZstdErroris raised. To ensure frame parameters can be parsed, pass in at least 18 bytes.- Parameters:
data – Data from which to read frame parameters.
format – Set the format of data for the decoder.
- Returns:
- zstandard.frame_header_size(data)¶
Obtain the size of a frame header.
- Returns:
Integer size in bytes.
- zstandard.frame_content_size(data)¶
Obtain the decompressed size of a frame.
The returned value is usually accurate. But strictly speaking it should not be trusted.
- Returns:
-1if size unknown and a non-negative integer otherwise.
- class zstandard.FrameParameters(fparams)¶
Information about a zstd frame.
Instances have the following attributes:
content_sizeInteger size of original, uncompressed content. This will be
0if the original content size isn’t written to the frame (controlled with thewrite_content_sizeargument toZstdCompressor) or if the input content size was0.window_sizeInteger size of maximum back-reference distance in compressed data.
dict_idInteger of dictionary ID used for compression.
0if no dictionary ID was used or if the dictionary ID was0.has_checksumBool indicating whether a 4 byte content checksum is stored at the end of the frame.
estimate_decompression_context_size()¶
- zstandard.estimate_decompression_context_size()¶
Estimate the memory size requirements for a decompressor instance.
- Returns:
Integer number of bytes.
Constants¶
The following module constants/attributes are exposed:
ZSTD_VERSIONThis module attribute exposes a 3-tuple of the Zstandard version. e.g.
(1, 0, 0)MAX_COMPRESSION_LEVELInteger max compression level accepted by compression functions
COMPRESSION_RECOMMENDED_INPUT_SIZERecommended chunk size to feed to compressor functions
COMPRESSION_RECOMMENDED_OUTPUT_SIZERecommended chunk size for compression output
DECOMPRESSION_RECOMMENDED_INPUT_SIZERecommended chunk size to feed into decompresor functions
DECOMPRESSION_RECOMMENDED_OUTPUT_SIZERecommended chunk size for decompression output
FRAME_HEADERbytes containing header of the Zstandard frame
MAGIC_NUMBERFrame header as an integer
FLUSH_BLOCKFlushing behavior that denotes to flush a zstd block. A decompressor will be able to decode all data fed into the compressor so far.
FLUSH_FRAMEFlushing behavior that denotes to end a zstd frame. Any new data fed to the compressor will start a new frame.
CONTENTSIZE_UNKNOWNValue for content size when the content size is unknown.
CONTENTSIZE_ERRORValue for content size when content size couldn’t be determined.
WINDOWLOG_MINMinimum value for compression parameter
WINDOWLOG_MAXMaximum value for compression parameter
CHAINLOG_MINMinimum value for compression parameter
CHAINLOG_MAXMaximum value for compression parameter
HASHLOG_MINMinimum value for compression parameter
HASHLOG_MAXMaximum value for compression parameter
SEARCHLOG_MINMinimum value for compression parameter
SEARCHLOG_MAXMaximum value for compression parameter
MINMATCH_MINMinimum value for compression parameter
MINMATCH_MAXMaximum value for compression parameter
SEARCHLENGTH_MINMinimum value for compression parameter
Deprecated: use
MINMATCH_MINSEARCHLENGTH_MAXMaximum value for compression parameter
Deprecated: use
MINMATCH_MAXTARGETLENGTH_MINMinimum value for compression parameter
STRATEGY_FASTCompression strategy
STRATEGY_DFASTCompression strategy
STRATEGY_GREEDYCompression strategy
STRATEGY_LAZYCompression strategy
STRATEGY_LAZY2Compression strategy
STRATEGY_BTLAZY2Compression strategy
STRATEGY_BTOPTCompression strategy
STRATEGY_BTULTRACompression strategy
STRATEGY_BTULTRA2Compression strategy
FORMAT_ZSTD1Zstandard frame format
FORMAT_ZSTD1_MAGICLESSZstandard frame format without magic header