ZSTD_decompress()
Decompresses zstd-compressed data into an already allocated destination buffer.Parameters
Pointer to the destination buffer where decompressed data will be written.
Size of the destination buffer. This is an upper bound of the original size to regenerate. Use
ZSTD_getFrameContentSize() to get the exact decompressed size from the frame header.Pointer to the compressed data.
Must be the exact size of some number of compressed and/or skippable frames. Multiple compressed frames can be decompressed at once with this method. The result will be the concatenation of all decompressed frames, back to back.
Return Value
Returns the number of bytes decompressed into
dst (<= dstCapacity), or an error code if it fails (which can be tested using ZSTD_isError()).Important Notes
compressedSizemust be the exact size of compressed data- If the maximum upper bound isn’t known, prefer using streaming mode to decompress data
- First frame’s decompressed size can be extracted using
ZSTD_getFrameContentSize()
Example
Related Functions
ZSTD_getFrameContentSize()- Get decompressed size from frame headerZSTD_decompressDCtx()- Decompress with explicit contextZSTD_isError()- Check if return value is an error
ZSTD_decompressDCtx()
Same asZSTD_decompress(), but requires an allocated ZSTD_DCtx decompression context. This allows reusing the context for multiple decompression operations.
Parameters
Pointer to a decompression context created by
ZSTD_createDCtx().Pointer to the destination buffer where decompressed data will be written.
Size of the destination buffer.
Pointer to the compressed data.
Size of the compressed data.
Return Value
Returns the number of bytes decompressed into
dst (<= dstCapacity), or an error code if it fails.Important Notes
- When decompressing many times, it is recommended to allocate a context only once and reuse it for each successive decompression operation
- This will make workload friendlier for system’s memory
- Use one context per thread for parallel execution
- Compatible with sticky parameters (advanced API)
Example
Related Functions
ZSTD_createDCtx()- Create decompression contextZSTD_freeDCtx()- Free decompression contextZSTD_decompress()- Simple one-shot decompression
ZSTD_decompress_usingDict()
Decompression using a known dictionary. The dictionary must be identical to the one used during compression.Parameters
Pointer to a decompression context.
Pointer to the destination buffer where decompressed data will be written.
Size of the destination buffer.
Pointer to the compressed data.
Size of the compressed data.
Pointer to the dictionary data. Must be identical to the one used during compression. When
dict == NULL || dictSize < 8, no dictionary is used.Size of the dictionary in bytes.
Return Value
Returns the number of bytes decompressed into
dst, or an error code if it fails.Important Notes
- Dictionary must be identical to the one used during compression
- This function loads the dictionary, resulting in significant startup delay
- It’s intended for a dictionary used only once
- When
dict == NULL || dictSize < 8, no dictionary is used - For repeated use of the same dictionary, use
ZSTD_decompress_usingDDict()instead
Example
Related Functions
ZSTD_decompress_usingDDict()- Decompress using a pre-digested dictionary (more efficient for repeated use)ZSTD_createDDict()- Create a digested dictionary for reuseZSTD_getDictID_fromFrame()- Get dictionary ID from compressed frame