Dictionary compression uses a pre-digested dictionary to improve compression ratios, especially for small files that share similar structure.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/facebook/zstd/llms.txt
Use this file to discover all available pages before exploring further.
ZSTD_createCDict()
Create a digested compression dictionary for reuse across multiple compression operations.Dictionary data (can be released after CDict creation, as content is copied internally).
Size of the dictionary buffer.
Compression level to use with this dictionary. This level will be used for all future compressions with this CDict.
Returns
Pointer to the createdZSTD_CDict, or NULL on failure.
Notes
- Digesting a dictionary is a costly operation; create once and reuse
- The resulting CDict can be shared by multiple threads concurrently (read-only usage)
- Dictionary content is copied into the CDict, so
dictBuffercan be freed after creation - An empty dictionary can be created to transport only the compression level
- Compression level is decided at dictionary creation time and cannot be changed
Example
ZSTD_compress_usingCDict()
Compress data using a digested dictionary.Compression context (create with
ZSTD_createCCtx()).Destination buffer for compressed data.
Size of destination buffer. Use
ZSTD_compressBound(srcSize) to guarantee sufficient space.Source data to compress.
Size of source data.
Pre-created compression dictionary.
Returns
Compressed size written intodst (<= dstCapacity), or an error code which can be tested with ZSTD_isError().
Frame Parameters
This function writes the following into the frame header:- Dictionary ID: yes
- Content size: yes
- Checksum: no
ZSTD_CCtx_setParameter(), ZSTD_CCtx_refCDict(), and ZSTD_compress2()) for more control.
Example
ZSTD_freeCDict()
Free memory allocated byZSTD_createCDict().
Dictionary to free. Passing NULL is safe and performs no operation.
Returns
Always returns 0.Advanced API
For more control over dictionary compression, use the advanced API:ZSTD_CCtx_refCDict()
Reference a prepared dictionary for all future compressed frames.ZSTD_compress2() for more control.