10c16b537SWarner Losh<html>
20c16b537SWarner Losh<head>
30c16b537SWarner Losh<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
4*19fcbaf1SConrad Meyer<title>zstd 1.3.4 Manual</title>
50c16b537SWarner Losh</head>
60c16b537SWarner Losh<body>
7*19fcbaf1SConrad Meyer<h1>zstd 1.3.4 Manual</h1>
80c16b537SWarner Losh<hr>
90c16b537SWarner Losh<a name="Contents"></a><h2>Contents</h2>
100c16b537SWarner Losh<ol>
110c16b537SWarner Losh<li><a href="#Chapter1">Introduction</a></li>
120c16b537SWarner Losh<li><a href="#Chapter2">Version</a></li>
130c16b537SWarner Losh<li><a href="#Chapter3">Simple API</a></li>
14*19fcbaf1SConrad Meyer<li><a href="#Chapter4">Explicit context</a></li>
150c16b537SWarner Losh<li><a href="#Chapter5">Simple dictionary API</a></li>
160c16b537SWarner Losh<li><a href="#Chapter6">Bulk processing dictionary API</a></li>
170c16b537SWarner Losh<li><a href="#Chapter7">Streaming</a></li>
180c16b537SWarner Losh<li><a href="#Chapter8">Streaming compression - HowTo</a></li>
190c16b537SWarner Losh<li><a href="#Chapter9">Streaming decompression - HowTo</a></li>
200c16b537SWarner Losh<li><a href="#Chapter10">START OF ADVANCED AND EXPERIMENTAL FUNCTIONS</a></li>
210c16b537SWarner Losh<li><a href="#Chapter11">Advanced types</a></li>
22*19fcbaf1SConrad Meyer<li><a href="#Chapter12">Frame size functions</a></li>
23*19fcbaf1SConrad Meyer<li><a href="#Chapter13">Memory management</a></li>
24*19fcbaf1SConrad Meyer<li><a href="#Chapter14">Advanced compression functions</a></li>
25*19fcbaf1SConrad Meyer<li><a href="#Chapter15">Advanced decompression functions</a></li>
26*19fcbaf1SConrad Meyer<li><a href="#Chapter16">Advanced streaming functions</a></li>
27*19fcbaf1SConrad Meyer<li><a href="#Chapter17">Buffer-less and synchronous inner streaming functions</a></li>
28*19fcbaf1SConrad Meyer<li><a href="#Chapter18">Buffer-less streaming compression (synchronous mode)</a></li>
29*19fcbaf1SConrad Meyer<li><a href="#Chapter19">Buffer-less streaming decompression (synchronous mode)</a></li>
30*19fcbaf1SConrad Meyer<li><a href="#Chapter20">New advanced API (experimental)</a></li>
31*19fcbaf1SConrad Meyer<li><a href="#Chapter21">Block level API</a></li>
320c16b537SWarner Losh</ol>
330c16b537SWarner Losh<hr>
340c16b537SWarner Losh<a name="Chapter1"></a><h2>Introduction</h2><pre>
350c16b537SWarner Losh  zstd, short for Zstandard, is a fast lossless compression algorithm,
360c16b537SWarner Losh  targeting real-time compression scenarios at zlib-level and better compression ratios.
370c16b537SWarner Losh  The zstd compression library provides in-memory compression and decompression functions.
380c16b537SWarner Losh  The library supports compression levels from 1 up to ZSTD_maxCLevel() which is currently 22.
390c16b537SWarner Losh  Levels >= 20, labeled `--ultra`, should be used with caution, as they require more memory.
400c16b537SWarner Losh  Compression can be done in:
410c16b537SWarner Losh    - a single step (described as Simple API)
42*19fcbaf1SConrad Meyer    - a single step, reusing a context (described as Explicit context)
430c16b537SWarner Losh    - unbounded multiple steps (described as Streaming compression)
440c16b537SWarner Losh  The compression ratio achievable on small data can be highly improved using a dictionary in:
450c16b537SWarner Losh    - a single step (described as Simple dictionary API)
46*19fcbaf1SConrad Meyer    - a single step, reusing a dictionary (described as Bulk-processing dictionary API)
470c16b537SWarner Losh
480c16b537SWarner Losh  Advanced experimental functions can be accessed using #define ZSTD_STATIC_LINKING_ONLY before including zstd.h.
490c16b537SWarner Losh  Advanced experimental APIs shall never be used with a dynamic library.
500c16b537SWarner Losh  They are not "stable", their definition may change in the future. Only static linking is allowed.
510c16b537SWarner Losh<BR></pre>
520c16b537SWarner Losh
530c16b537SWarner Losh<a name="Chapter2"></a><h2>Version</h2><pre></pre>
540c16b537SWarner Losh
550c16b537SWarner Losh<pre><b>unsigned ZSTD_versionNumber(void);   </b>/**< useful to check dll version */<b>
560c16b537SWarner Losh</b></pre><BR>
570c16b537SWarner Losh<a name="Chapter3"></a><h2>Simple API</h2><pre></pre>
580c16b537SWarner Losh
590c16b537SWarner Losh<pre><b>size_t ZSTD_compress( void* dst, size_t dstCapacity,
600c16b537SWarner Losh                const void* src, size_t srcSize,
610c16b537SWarner Losh                      int compressionLevel);
620c16b537SWarner Losh</b><p>  Compresses `src` content as a single zstd compressed frame into already allocated `dst`.
630c16b537SWarner Losh  Hint : compression runs faster if `dstCapacity` >=  `ZSTD_compressBound(srcSize)`.
640c16b537SWarner Losh  @return : compressed size written into `dst` (<= `dstCapacity),
650c16b537SWarner Losh            or an error code if it fails (which can be tested using ZSTD_isError()).
660c16b537SWarner Losh</p></pre><BR>
670c16b537SWarner Losh
680c16b537SWarner Losh<pre><b>size_t ZSTD_decompress( void* dst, size_t dstCapacity,
690c16b537SWarner Losh                  const void* src, size_t compressedSize);
700c16b537SWarner Losh</b><p>  `compressedSize` : must be the _exact_ size of some number of compressed and/or skippable frames.
710c16b537SWarner Losh  `dstCapacity` is an upper bound of originalSize to regenerate.
720c16b537SWarner Losh  If user cannot imply a maximum upper bound, it's better to use streaming mode to decompress data.
730c16b537SWarner Losh  @return : the number of bytes decompressed into `dst` (<= `dstCapacity`),
740c16b537SWarner Losh            or an errorCode if it fails (which can be tested using ZSTD_isError()).
750c16b537SWarner Losh</p></pre><BR>
760c16b537SWarner Losh
770c16b537SWarner Losh<pre><b>#define ZSTD_CONTENTSIZE_UNKNOWN (0ULL - 1)
780c16b537SWarner Losh#define ZSTD_CONTENTSIZE_ERROR   (0ULL - 2)
790c16b537SWarner Loshunsigned long long ZSTD_getFrameContentSize(const void *src, size_t srcSize);
800c16b537SWarner Losh</b><p>  `src` should point to the start of a ZSTD encoded frame.
810c16b537SWarner Losh  `srcSize` must be at least as large as the frame header.
820c16b537SWarner Losh            hint : any size >= `ZSTD_frameHeaderSize_max` is large enough.
830c16b537SWarner Losh  @return : - decompressed size of the frame in `src`, if known
840c16b537SWarner Losh            - ZSTD_CONTENTSIZE_UNKNOWN if the size cannot be determined
850c16b537SWarner Losh            - ZSTD_CONTENTSIZE_ERROR if an error occurred (e.g. invalid magic number, srcSize too small)
860c16b537SWarner Losh   note 1 : a 0 return value means the frame is valid but "empty".
870c16b537SWarner Losh   note 2 : decompressed size is an optional field, it may not be present, typically in streaming mode.
880c16b537SWarner Losh            When `return==ZSTD_CONTENTSIZE_UNKNOWN`, data to decompress could be any size.
890c16b537SWarner Losh            In which case, it's necessary to use streaming mode to decompress data.
900c16b537SWarner Losh            Optionally, application can rely on some implicit limit,
910c16b537SWarner Losh            as ZSTD_decompress() only needs an upper bound of decompressed size.
920c16b537SWarner Losh            (For example, data could be necessarily cut into blocks <= 16 KB).
930c16b537SWarner Losh   note 3 : decompressed size is always present when compression is done with ZSTD_compress()
940c16b537SWarner Losh   note 4 : decompressed size can be very large (64-bits value),
950c16b537SWarner Losh            potentially larger than what local system can handle as a single memory segment.
960c16b537SWarner Losh            In which case, it's necessary to use streaming mode to decompress data.
970c16b537SWarner Losh   note 5 : If source is untrusted, decompressed size could be wrong or intentionally modified.
980c16b537SWarner Losh            Always ensure return value fits within application's authorized limits.
990c16b537SWarner Losh            Each application can set its own limits.
1000c16b537SWarner Losh   note 6 : This function replaces ZSTD_getDecompressedSize()
1010c16b537SWarner Losh</p></pre><BR>
1020c16b537SWarner Losh
1030c16b537SWarner Losh<pre><b>unsigned long long ZSTD_getDecompressedSize(const void* src, size_t srcSize);
1040c16b537SWarner Losh</b><p>  NOTE: This function is now obsolete, in favor of ZSTD_getFrameContentSize().
105*19fcbaf1SConrad Meyer  Both functions work the same way, but ZSTD_getDecompressedSize() blends
106*19fcbaf1SConrad Meyer  "empty", "unknown" and "error" results to the same return value (0),
107*19fcbaf1SConrad Meyer  while ZSTD_getFrameContentSize() gives them separate return values.
108*19fcbaf1SConrad Meyer `src` is the start of a zstd compressed frame.
1090c16b537SWarner Losh @return : content size to be decompressed, as a 64-bits value _if known and not empty_, 0 otherwise.
1100c16b537SWarner Losh</p></pre><BR>
1110c16b537SWarner Losh
112052d3c12SConrad Meyer<h3>Helper functions</h3><pre></pre><b><pre>#define ZSTD_COMPRESSBOUND(srcSize)   ((srcSize) + ((srcSize)>>8) + (((srcSize) < (128<<10)) ? (((128<<10) - (srcSize)) >> 11) </b>/* margin, from 64 to 0 */ : 0))  /* this formula ensures that bound(A) + bound(B) <= bound(A+B) as long as A and B >= 128 KB */<b>
113*19fcbaf1SConrad Meyersize_t      ZSTD_compressBound(size_t srcSize); </b>/*!< maximum compressed size in worst case single-pass scenario */<b>
1140c16b537SWarner Loshunsigned    ZSTD_isError(size_t code);          </b>/*!< tells if a `size_t` function result is an error code */<b>
1150c16b537SWarner Loshconst char* ZSTD_getErrorName(size_t code);     </b>/*!< provides readable string from an error code */<b>
1160c16b537SWarner Loshint         ZSTD_maxCLevel(void);               </b>/*!< maximum compression level available */<b>
1170c16b537SWarner Losh</pre></b><BR>
118*19fcbaf1SConrad Meyer<a name="Chapter4"></a><h2>Explicit context</h2><pre></pre>
1190c16b537SWarner Losh
1200c16b537SWarner Losh<h3>Compression context</h3><pre>  When compressing many times,
1210c16b537SWarner Losh  it is recommended to allocate a context just once, and re-use it for each successive compression operation.
1220c16b537SWarner Losh  This will make workload friendlier for system's memory.
1230c16b537SWarner Losh  Use one context per thread for parallel execution in multi-threaded environments.
1240c16b537SWarner Losh</pre><b><pre>typedef struct ZSTD_CCtx_s ZSTD_CCtx;
1250c16b537SWarner LoshZSTD_CCtx* ZSTD_createCCtx(void);
1260c16b537SWarner Loshsize_t     ZSTD_freeCCtx(ZSTD_CCtx* cctx);
1270c16b537SWarner Losh</pre></b><BR>
1280c16b537SWarner Losh<pre><b>size_t ZSTD_compressCCtx(ZSTD_CCtx* ctx,
1290c16b537SWarner Losh                         void* dst, size_t dstCapacity,
1300c16b537SWarner Losh                   const void* src, size_t srcSize,
1310c16b537SWarner Losh                         int compressionLevel);
1320c16b537SWarner Losh</b><p>  Same as ZSTD_compress(), requires an allocated ZSTD_CCtx (see ZSTD_createCCtx()).
1330c16b537SWarner Losh</p></pre><BR>
1340c16b537SWarner Losh
1350c16b537SWarner Losh<h3>Decompression context</h3><pre>  When decompressing many times,
1360c16b537SWarner Losh  it is recommended to allocate a context only once,
1370c16b537SWarner Losh  and re-use it for each successive compression operation.
1380c16b537SWarner Losh  This will make workload friendlier for system's memory.
1390c16b537SWarner Losh  Use one context per thread for parallel execution.
1400c16b537SWarner Losh</pre><b><pre>typedef struct ZSTD_DCtx_s ZSTD_DCtx;
1410c16b537SWarner LoshZSTD_DCtx* ZSTD_createDCtx(void);
1420c16b537SWarner Loshsize_t     ZSTD_freeDCtx(ZSTD_DCtx* dctx);
1430c16b537SWarner Losh</pre></b><BR>
1440c16b537SWarner Losh<pre><b>size_t ZSTD_decompressDCtx(ZSTD_DCtx* ctx,
1450c16b537SWarner Losh                           void* dst, size_t dstCapacity,
1460c16b537SWarner Losh                     const void* src, size_t srcSize);
1470c16b537SWarner Losh</b><p>  Same as ZSTD_decompress(), requires an allocated ZSTD_DCtx (see ZSTD_createDCtx())
1480c16b537SWarner Losh</p></pre><BR>
1490c16b537SWarner Losh
1500c16b537SWarner Losh<a name="Chapter5"></a><h2>Simple dictionary API</h2><pre></pre>
1510c16b537SWarner Losh
1520c16b537SWarner Losh<pre><b>size_t ZSTD_compress_usingDict(ZSTD_CCtx* ctx,
1530c16b537SWarner Losh                               void* dst, size_t dstCapacity,
1540c16b537SWarner Losh                         const void* src, size_t srcSize,
1550c16b537SWarner Losh                         const void* dict,size_t dictSize,
1560c16b537SWarner Losh                               int compressionLevel);
1570c16b537SWarner Losh</b><p>  Compression using a predefined Dictionary (see dictBuilder/zdict.h).
1580c16b537SWarner Losh  Note : This function loads the dictionary, resulting in significant startup delay.
1590c16b537SWarner Losh  Note : When `dict == NULL || dictSize < 8` no dictionary is used.
1600c16b537SWarner Losh</p></pre><BR>
1610c16b537SWarner Losh
1620c16b537SWarner Losh<pre><b>size_t ZSTD_decompress_usingDict(ZSTD_DCtx* dctx,
1630c16b537SWarner Losh                                 void* dst, size_t dstCapacity,
1640c16b537SWarner Losh                           const void* src, size_t srcSize,
1650c16b537SWarner Losh                           const void* dict,size_t dictSize);
1660c16b537SWarner Losh</b><p>  Decompression using a predefined Dictionary (see dictBuilder/zdict.h).
1670c16b537SWarner Losh  Dictionary must be identical to the one used during compression.
1680c16b537SWarner Losh  Note : This function loads the dictionary, resulting in significant startup delay.
1690c16b537SWarner Losh  Note : When `dict == NULL || dictSize < 8` no dictionary is used.
1700c16b537SWarner Losh</p></pre><BR>
1710c16b537SWarner Losh
1720c16b537SWarner Losh<a name="Chapter6"></a><h2>Bulk processing dictionary API</h2><pre></pre>
1730c16b537SWarner Losh
1740c16b537SWarner Losh<pre><b>ZSTD_CDict* ZSTD_createCDict(const void* dictBuffer, size_t dictSize,
1750c16b537SWarner Losh                             int compressionLevel);
1760c16b537SWarner Losh</b><p>  When compressing multiple messages / blocks with the same dictionary, it's recommended to load it just once.
1770c16b537SWarner Losh  ZSTD_createCDict() will create a digested dictionary, ready to start future compression operations without startup delay.
1780c16b537SWarner Losh  ZSTD_CDict can be created once and shared by multiple threads concurrently, since its usage is read-only.
1790c16b537SWarner Losh  `dictBuffer` can be released after ZSTD_CDict creation, since its content is copied within CDict
1800c16b537SWarner Losh</p></pre><BR>
1810c16b537SWarner Losh
1820c16b537SWarner Losh<pre><b>size_t      ZSTD_freeCDict(ZSTD_CDict* CDict);
1830c16b537SWarner Losh</b><p>  Function frees memory allocated by ZSTD_createCDict().
1840c16b537SWarner Losh</p></pre><BR>
1850c16b537SWarner Losh
1860c16b537SWarner Losh<pre><b>size_t ZSTD_compress_usingCDict(ZSTD_CCtx* cctx,
1870c16b537SWarner Losh                                void* dst, size_t dstCapacity,
1880c16b537SWarner Losh                          const void* src, size_t srcSize,
1890c16b537SWarner Losh                          const ZSTD_CDict* cdict);
1900c16b537SWarner Losh</b><p>  Compression using a digested Dictionary.
1910c16b537SWarner Losh  Faster startup than ZSTD_compress_usingDict(), recommended when same dictionary is used multiple times.
1920c16b537SWarner Losh  Note that compression level is decided during dictionary creation.
1930c16b537SWarner Losh  Frame parameters are hardcoded (dictID=yes, contentSize=yes, checksum=no)
1940c16b537SWarner Losh</p></pre><BR>
1950c16b537SWarner Losh
1960c16b537SWarner Losh<pre><b>ZSTD_DDict* ZSTD_createDDict(const void* dictBuffer, size_t dictSize);
1970c16b537SWarner Losh</b><p>  Create a digested dictionary, ready to start decompression operation without startup delay.
1980c16b537SWarner Losh  dictBuffer can be released after DDict creation, as its content is copied inside DDict
1990c16b537SWarner Losh</p></pre><BR>
2000c16b537SWarner Losh
2010c16b537SWarner Losh<pre><b>size_t      ZSTD_freeDDict(ZSTD_DDict* ddict);
2020c16b537SWarner Losh</b><p>  Function frees memory allocated with ZSTD_createDDict()
2030c16b537SWarner Losh</p></pre><BR>
2040c16b537SWarner Losh
2050c16b537SWarner Losh<pre><b>size_t ZSTD_decompress_usingDDict(ZSTD_DCtx* dctx,
2060c16b537SWarner Losh                                  void* dst, size_t dstCapacity,
2070c16b537SWarner Losh                            const void* src, size_t srcSize,
2080c16b537SWarner Losh                            const ZSTD_DDict* ddict);
2090c16b537SWarner Losh</b><p>  Decompression using a digested Dictionary.
2100c16b537SWarner Losh  Faster startup than ZSTD_decompress_usingDict(), recommended when same dictionary is used multiple times.
2110c16b537SWarner Losh</p></pre><BR>
2120c16b537SWarner Losh
2130c16b537SWarner Losh<a name="Chapter7"></a><h2>Streaming</h2><pre></pre>
2140c16b537SWarner Losh
2150c16b537SWarner Losh<pre><b>typedef struct ZSTD_inBuffer_s {
2160c16b537SWarner Losh  const void* src;    </b>/**< start of input buffer */<b>
2170c16b537SWarner Losh  size_t size;        </b>/**< size of input buffer */<b>
2180c16b537SWarner Losh  size_t pos;         </b>/**< position where reading stopped. Will be updated. Necessarily 0 <= pos <= size */<b>
2190c16b537SWarner Losh} ZSTD_inBuffer;
2200c16b537SWarner Losh</b></pre><BR>
2210c16b537SWarner Losh<pre><b>typedef struct ZSTD_outBuffer_s {
2220c16b537SWarner Losh  void*  dst;         </b>/**< start of output buffer */<b>
2230c16b537SWarner Losh  size_t size;        </b>/**< size of output buffer */<b>
2240c16b537SWarner Losh  size_t pos;         </b>/**< position where writing stopped. Will be updated. Necessarily 0 <= pos <= size */<b>
2250c16b537SWarner Losh} ZSTD_outBuffer;
2260c16b537SWarner Losh</b></pre><BR>
2270c16b537SWarner Losh<a name="Chapter8"></a><h2>Streaming compression - HowTo</h2><pre>
2280c16b537SWarner Losh  A ZSTD_CStream object is required to track streaming operation.
2290c16b537SWarner Losh  Use ZSTD_createCStream() and ZSTD_freeCStream() to create/release resources.
2300c16b537SWarner Losh  ZSTD_CStream objects can be reused multiple times on consecutive compression operations.
2310c16b537SWarner Losh  It is recommended to re-use ZSTD_CStream in situations where many streaming operations will be achieved consecutively,
2320c16b537SWarner Losh  since it will play nicer with system's memory, by re-using already allocated memory.
2330c16b537SWarner Losh  Use one separate ZSTD_CStream per thread for parallel execution.
2340c16b537SWarner Losh
2350c16b537SWarner Losh  Start a new compression by initializing ZSTD_CStream.
2360c16b537SWarner Losh  Use ZSTD_initCStream() to start a new compression operation.
2370c16b537SWarner Losh  Use ZSTD_initCStream_usingDict() or ZSTD_initCStream_usingCDict() for a compression which requires a dictionary (experimental section)
2380c16b537SWarner Losh
2390c16b537SWarner Losh  Use ZSTD_compressStream() repetitively to consume input stream.
2400c16b537SWarner Losh  The function will automatically update both `pos` fields.
2410c16b537SWarner Losh  Note that it may not consume the entire input, in which case `pos < size`,
2420c16b537SWarner Losh  and it's up to the caller to present again remaining data.
2430c16b537SWarner Losh  @return : a size hint, preferred nb of bytes to use as input for next function call
2440c16b537SWarner Losh            or an error code, which can be tested using ZSTD_isError().
2450c16b537SWarner Losh            Note 1 : it's just a hint, to help latency a little, any other value will work fine.
2460c16b537SWarner Losh            Note 2 : size hint is guaranteed to be <= ZSTD_CStreamInSize()
2470c16b537SWarner Losh
2480c16b537SWarner Losh  At any moment, it's possible to flush whatever data remains within internal buffer, using ZSTD_flushStream().
2490c16b537SWarner Losh  `output->pos` will be updated.
2500c16b537SWarner Losh  Note that some content might still be left within internal buffer if `output->size` is too small.
2510c16b537SWarner Losh  @return : nb of bytes still present within internal buffer (0 if it's empty)
2520c16b537SWarner Losh            or an error code, which can be tested using ZSTD_isError().
2530c16b537SWarner Losh
2540c16b537SWarner Losh  ZSTD_endStream() instructs to finish a frame.
2550c16b537SWarner Losh  It will perform a flush and write frame epilogue.
2560c16b537SWarner Losh  The epilogue is required for decoders to consider a frame completed.
2570c16b537SWarner Losh  ZSTD_endStream() may not be able to flush full data if `output->size` is too small.
2580c16b537SWarner Losh  In which case, call again ZSTD_endStream() to complete the flush.
2590c16b537SWarner Losh  @return : 0 if frame fully completed and fully flushed,
2600c16b537SWarner Losh             or >0 if some data is still present within internal buffer
2610c16b537SWarner Losh                  (value is minimum size estimation for remaining data to flush, but it could be more)
2620c16b537SWarner Losh            or an error code, which can be tested using ZSTD_isError().
2630c16b537SWarner Losh
2640c16b537SWarner Losh
2650c16b537SWarner Losh<BR></pre>
2660c16b537SWarner Losh
2670c16b537SWarner Losh<pre><b>typedef ZSTD_CCtx ZSTD_CStream;  </b>/**< CCtx and CStream are now effectively same object (>= v1.3.0) */<b>
2680c16b537SWarner Losh</b></pre><BR>
2690c16b537SWarner Losh<h3>ZSTD_CStream management functions</h3><pre></pre><b><pre>ZSTD_CStream* ZSTD_createCStream(void);
2700c16b537SWarner Loshsize_t ZSTD_freeCStream(ZSTD_CStream* zcs);
2710c16b537SWarner Losh</pre></b><BR>
2720c16b537SWarner Losh<h3>Streaming compression functions</h3><pre></pre><b><pre>size_t ZSTD_initCStream(ZSTD_CStream* zcs, int compressionLevel);
2730c16b537SWarner Loshsize_t ZSTD_compressStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output, ZSTD_inBuffer* input);
2740c16b537SWarner Loshsize_t ZSTD_flushStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output);
2750c16b537SWarner Loshsize_t ZSTD_endStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output);
2760c16b537SWarner Losh</pre></b><BR>
2770c16b537SWarner Losh<pre><b>size_t ZSTD_CStreamInSize(void);    </b>/**< recommended size for input buffer */<b>
2780c16b537SWarner Losh</b></pre><BR>
2790c16b537SWarner Losh<pre><b>size_t ZSTD_CStreamOutSize(void);   </b>/**< recommended size for output buffer. Guarantee to successfully flush at least one complete compressed block in all circumstances. */<b>
2800c16b537SWarner Losh</b></pre><BR>
2810c16b537SWarner Losh<a name="Chapter9"></a><h2>Streaming decompression - HowTo</h2><pre>
2820c16b537SWarner Losh  A ZSTD_DStream object is required to track streaming operations.
2830c16b537SWarner Losh  Use ZSTD_createDStream() and ZSTD_freeDStream() to create/release resources.
2840c16b537SWarner Losh  ZSTD_DStream objects can be re-used multiple times.
2850c16b537SWarner Losh
2860c16b537SWarner Losh  Use ZSTD_initDStream() to start a new decompression operation,
2870c16b537SWarner Losh   or ZSTD_initDStream_usingDict() if decompression requires a dictionary.
2880c16b537SWarner Losh   @return : recommended first input size
2890c16b537SWarner Losh
2900c16b537SWarner Losh  Use ZSTD_decompressStream() repetitively to consume your input.
2910c16b537SWarner Losh  The function will update both `pos` fields.
2920c16b537SWarner Losh  If `input.pos < input.size`, some input has not been consumed.
2930c16b537SWarner Losh  It's up to the caller to present again remaining data.
2940c16b537SWarner Losh  If `output.pos < output.size`, decoder has flushed everything it could.
2950c16b537SWarner Losh  @return : 0 when a frame is completely decoded and fully flushed,
2960c16b537SWarner Losh            an error code, which can be tested using ZSTD_isError(),
2970c16b537SWarner Losh            any other value > 0, which means there is still some decoding to do to complete current frame.
2980c16b537SWarner Losh            The return value is a suggested next input size (a hint to improve latency) that will never load more than the current frame.
2990c16b537SWarner Losh
3000c16b537SWarner Losh<BR></pre>
3010c16b537SWarner Losh
3020c16b537SWarner Losh<pre><b>typedef ZSTD_DCtx ZSTD_DStream;  </b>/**< DCtx and DStream are now effectively same object (>= v1.3.0) */<b>
3030c16b537SWarner Losh</b></pre><BR>
3040c16b537SWarner Losh<h3>ZSTD_DStream management functions</h3><pre></pre><b><pre>ZSTD_DStream* ZSTD_createDStream(void);
3050c16b537SWarner Loshsize_t ZSTD_freeDStream(ZSTD_DStream* zds);
3060c16b537SWarner Losh</pre></b><BR>
3070c16b537SWarner Losh<h3>Streaming decompression functions</h3><pre></pre><b><pre>size_t ZSTD_initDStream(ZSTD_DStream* zds);
3080c16b537SWarner Loshsize_t ZSTD_decompressStream(ZSTD_DStream* zds, ZSTD_outBuffer* output, ZSTD_inBuffer* input);
3090c16b537SWarner Losh</pre></b><BR>
3100c16b537SWarner Losh<pre><b>size_t ZSTD_DStreamInSize(void);    </b>/*!< recommended size for input buffer */<b>
3110c16b537SWarner Losh</b></pre><BR>
3120c16b537SWarner Losh<pre><b>size_t ZSTD_DStreamOutSize(void);   </b>/*!< recommended size for output buffer. Guarantee to successfully flush at least one complete block in all circumstances. */<b>
3130c16b537SWarner Losh</b></pre><BR>
3140c16b537SWarner Losh<a name="Chapter10"></a><h2>START OF ADVANCED AND EXPERIMENTAL FUNCTIONS</h2><pre> The definitions in this section are considered experimental.
3150c16b537SWarner Losh They should never be used with a dynamic library, as prototypes may change in the future.
3160c16b537SWarner Losh They are provided for advanced scenarios.
3170c16b537SWarner Losh Use them only in association with static linking.
3180c16b537SWarner Losh
3190c16b537SWarner Losh<BR></pre>
3200c16b537SWarner Losh
3210c16b537SWarner Losh<a name="Chapter11"></a><h2>Advanced types</h2><pre></pre>
3220c16b537SWarner Losh
3230c16b537SWarner Losh<pre><b>typedef enum { ZSTD_fast=1, ZSTD_dfast, ZSTD_greedy, ZSTD_lazy, ZSTD_lazy2,
3240c16b537SWarner Losh               ZSTD_btlazy2, ZSTD_btopt, ZSTD_btultra } ZSTD_strategy;   </b>/* from faster to stronger */<b>
3250c16b537SWarner Losh</b></pre><BR>
3260c16b537SWarner Losh<pre><b>typedef struct {
3270c16b537SWarner Losh    unsigned windowLog;      </b>/**< largest match distance : larger == more compression, more memory needed during decompression */<b>
3280c16b537SWarner Losh    unsigned chainLog;       </b>/**< fully searched segment : larger == more compression, slower, more memory (useless for fast) */<b>
3290c16b537SWarner Losh    unsigned hashLog;        </b>/**< dispatch table : larger == faster, more memory */<b>
3300c16b537SWarner Losh    unsigned searchLog;      </b>/**< nb of searches : larger == more compression, slower */<b>
3310c16b537SWarner Losh    unsigned searchLength;   </b>/**< match length searched : larger == faster decompression, sometimes less compression */<b>
3320c16b537SWarner Losh    unsigned targetLength;   </b>/**< acceptable match size for optimal parser (only) : larger == more compression, slower */<b>
3330c16b537SWarner Losh    ZSTD_strategy strategy;
3340c16b537SWarner Losh} ZSTD_compressionParameters;
3350c16b537SWarner Losh</b></pre><BR>
3360c16b537SWarner Losh<pre><b>typedef struct {
3370c16b537SWarner Losh    unsigned contentSizeFlag; </b>/**< 1: content size will be in frame header (when known) */<b>
3380c16b537SWarner Losh    unsigned checksumFlag;    </b>/**< 1: generate a 32-bits checksum at end of frame, for error detection */<b>
3390c16b537SWarner Losh    unsigned noDictIDFlag;    </b>/**< 1: no dictID will be saved into frame header (if dictionary compression) */<b>
3400c16b537SWarner Losh} ZSTD_frameParameters;
3410c16b537SWarner Losh</b></pre><BR>
3420c16b537SWarner Losh<pre><b>typedef struct {
3430c16b537SWarner Losh    ZSTD_compressionParameters cParams;
3440c16b537SWarner Losh    ZSTD_frameParameters fParams;
3450c16b537SWarner Losh} ZSTD_parameters;
3460c16b537SWarner Losh</b></pre><BR>
347*19fcbaf1SConrad Meyer<pre><b>typedef enum {
348*19fcbaf1SConrad Meyer    ZSTD_dct_auto=0,      </b>/* dictionary is "full" when starting with ZSTD_MAGIC_DICTIONARY, otherwise it is "rawContent" */<b>
349*19fcbaf1SConrad Meyer    ZSTD_dct_rawContent,  </b>/* ensures dictionary is always loaded as rawContent, even if it starts with ZSTD_MAGIC_DICTIONARY */<b>
350*19fcbaf1SConrad Meyer    ZSTD_dct_fullDict     </b>/* refuses to load a dictionary if it does not respect Zstandard's specification */<b>
351*19fcbaf1SConrad Meyer} ZSTD_dictContentType_e;
352052d3c12SConrad Meyer</b></pre><BR>
353*19fcbaf1SConrad Meyer<pre><b>typedef enum {
354*19fcbaf1SConrad Meyer    ZSTD_dlm_byCopy = 0, </b>/**< Copy dictionary content internally */<b>
355*19fcbaf1SConrad Meyer    ZSTD_dlm_byRef,      </b>/**< Reference dictionary content -- the dictionary buffer must outlive its users. */<b>
356*19fcbaf1SConrad Meyer} ZSTD_dictLoadMethod_e;
357*19fcbaf1SConrad Meyer</b></pre><BR>
358*19fcbaf1SConrad Meyer<a name="Chapter12"></a><h2>Frame size functions</h2><pre></pre>
3590c16b537SWarner Losh
3600c16b537SWarner Losh<pre><b>size_t ZSTD_findFrameCompressedSize(const void* src, size_t srcSize);
3610c16b537SWarner Losh</b><p>  `src` should point to the start of a ZSTD encoded frame or skippable frame
362052d3c12SConrad Meyer  `srcSize` must be >= first frame size
3630c16b537SWarner Losh  @return : the compressed size of the first frame starting at `src`,
3640c16b537SWarner Losh            suitable to pass to `ZSTD_decompress` or similar,
3650c16b537SWarner Losh            or an error code if input is invalid
3660c16b537SWarner Losh</p></pre><BR>
3670c16b537SWarner Losh
3680c16b537SWarner Losh<pre><b>unsigned long long ZSTD_findDecompressedSize(const void* src, size_t srcSize);
3690c16b537SWarner Losh</b><p>  `src` should point the start of a series of ZSTD encoded and/or skippable frames
3700c16b537SWarner Losh  `srcSize` must be the _exact_ size of this series
3710c16b537SWarner Losh       (i.e. there should be a frame boundary exactly at `srcSize` bytes after `src`)
3720c16b537SWarner Losh  @return : - decompressed size of all data in all successive frames
3730c16b537SWarner Losh            - if the decompressed size cannot be determined: ZSTD_CONTENTSIZE_UNKNOWN
3740c16b537SWarner Losh            - if an error occurred: ZSTD_CONTENTSIZE_ERROR
3750c16b537SWarner Losh
3760c16b537SWarner Losh   note 1 : decompressed size is an optional field, that may not be present, especially in streaming mode.
3770c16b537SWarner Losh            When `return==ZSTD_CONTENTSIZE_UNKNOWN`, data to decompress could be any size.
3780c16b537SWarner Losh            In which case, it's necessary to use streaming mode to decompress data.
3790c16b537SWarner Losh   note 2 : decompressed size is always present when compression is done with ZSTD_compress()
3800c16b537SWarner Losh   note 3 : decompressed size can be very large (64-bits value),
3810c16b537SWarner Losh            potentially larger than what local system can handle as a single memory segment.
3820c16b537SWarner Losh            In which case, it's necessary to use streaming mode to decompress data.
3830c16b537SWarner Losh   note 4 : If source is untrusted, decompressed size could be wrong or intentionally modified.
3840c16b537SWarner Losh            Always ensure result fits within application's authorized limits.
3850c16b537SWarner Losh            Each application can set its own limits.
3860c16b537SWarner Losh   note 5 : ZSTD_findDecompressedSize handles multiple frames, and so it must traverse the input to
3870c16b537SWarner Losh            read each contained frame header.  This is fast as most of the data is skipped,
3880c16b537SWarner Losh            however it does mean that all frame data must be present and valid.
3890c16b537SWarner Losh</p></pre><BR>
3900c16b537SWarner Losh
3910c16b537SWarner Losh<pre><b>size_t ZSTD_frameHeaderSize(const void* src, size_t srcSize);
3920c16b537SWarner Losh</b><p>   `src` should point to the start of a ZSTD frame
3930c16b537SWarner Losh   `srcSize` must be >= ZSTD_frameHeaderSize_prefix.
3940c16b537SWarner Losh   @return : size of the Frame Header
3950c16b537SWarner Losh</p></pre><BR>
3960c16b537SWarner Losh
397*19fcbaf1SConrad Meyer<a name="Chapter13"></a><h2>Memory management</h2><pre></pre>
3980c16b537SWarner Losh
3990c16b537SWarner Losh<pre><b>size_t ZSTD_sizeof_CCtx(const ZSTD_CCtx* cctx);
4000c16b537SWarner Loshsize_t ZSTD_sizeof_DCtx(const ZSTD_DCtx* dctx);
4010c16b537SWarner Loshsize_t ZSTD_sizeof_CStream(const ZSTD_CStream* zcs);
4020c16b537SWarner Loshsize_t ZSTD_sizeof_DStream(const ZSTD_DStream* zds);
4030c16b537SWarner Loshsize_t ZSTD_sizeof_CDict(const ZSTD_CDict* cdict);
4040c16b537SWarner Loshsize_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict);
4050c16b537SWarner Losh</b><p>  These functions give the current memory usage of selected object.
406*19fcbaf1SConrad Meyer  Object memory usage can evolve when re-used.
4070c16b537SWarner Losh</p></pre><BR>
4080c16b537SWarner Losh
4090c16b537SWarner Losh<pre><b>size_t ZSTD_estimateCCtxSize(int compressionLevel);
4100c16b537SWarner Loshsize_t ZSTD_estimateCCtxSize_usingCParams(ZSTD_compressionParameters cParams);
4110c16b537SWarner Loshsize_t ZSTD_estimateCCtxSize_usingCCtxParams(const ZSTD_CCtx_params* params);
4120c16b537SWarner Loshsize_t ZSTD_estimateDCtxSize(void);
4130c16b537SWarner Losh</b><p>  These functions make it possible to estimate memory usage
4140c16b537SWarner Losh  of a future {D,C}Ctx, before its creation.
4150c16b537SWarner Losh  ZSTD_estimateCCtxSize() will provide a budget large enough for any compression level up to selected one.
4160c16b537SWarner Losh  It will also consider src size to be arbitrarily "large", which is worst case.
4170c16b537SWarner Losh  If srcSize is known to always be small, ZSTD_estimateCCtxSize_usingCParams() can provide a tighter estimation.
4180c16b537SWarner Losh  ZSTD_estimateCCtxSize_usingCParams() can be used in tandem with ZSTD_getCParams() to create cParams from compressionLevel.
419*19fcbaf1SConrad Meyer  ZSTD_estimateCCtxSize_usingCCtxParams() can be used in tandem with ZSTD_CCtxParam_setParameter(). Only single-threaded compression is supported. This function will return an error code if ZSTD_p_nbWorkers is >= 1.
420*19fcbaf1SConrad Meyer  Note : CCtx size estimation is only correct for single-threaded compression.
4210c16b537SWarner Losh</p></pre><BR>
4220c16b537SWarner Losh
4230c16b537SWarner Losh<pre><b>size_t ZSTD_estimateCStreamSize(int compressionLevel);
4240c16b537SWarner Loshsize_t ZSTD_estimateCStreamSize_usingCParams(ZSTD_compressionParameters cParams);
4250c16b537SWarner Loshsize_t ZSTD_estimateCStreamSize_usingCCtxParams(const ZSTD_CCtx_params* params);
4260c16b537SWarner Loshsize_t ZSTD_estimateDStreamSize(size_t windowSize);
4270c16b537SWarner Loshsize_t ZSTD_estimateDStreamSize_fromFrame(const void* src, size_t srcSize);
4280c16b537SWarner Losh</b><p>  ZSTD_estimateCStreamSize() will provide a budget large enough for any compression level up to selected one.
4290c16b537SWarner Losh  It will also consider src size to be arbitrarily "large", which is worst case.
4300c16b537SWarner Losh  If srcSize is known to always be small, ZSTD_estimateCStreamSize_usingCParams() can provide a tighter estimation.
4310c16b537SWarner Losh  ZSTD_estimateCStreamSize_usingCParams() can be used in tandem with ZSTD_getCParams() to create cParams from compressionLevel.
432*19fcbaf1SConrad Meyer  ZSTD_estimateCStreamSize_usingCCtxParams() can be used in tandem with ZSTD_CCtxParam_setParameter(). Only single-threaded compression is supported. This function will return an error code if ZSTD_p_nbWorkers is >= 1.
433*19fcbaf1SConrad Meyer  Note : CStream size estimation is only correct for single-threaded compression.
4340c16b537SWarner Losh  ZSTD_DStream memory budget depends on window Size.
4350c16b537SWarner Losh  This information can be passed manually, using ZSTD_estimateDStreamSize,
4360c16b537SWarner Losh  or deducted from a valid frame Header, using ZSTD_estimateDStreamSize_fromFrame();
4370c16b537SWarner Losh  Note : if streaming is init with function ZSTD_init?Stream_usingDict(),
4380c16b537SWarner Losh         an internal ?Dict will be created, which additional size is not estimated here.
4390c16b537SWarner Losh         In this case, get total size by adding ZSTD_estimate?DictSize
4400c16b537SWarner Losh</p></pre><BR>
4410c16b537SWarner Losh
4420c16b537SWarner Losh<pre><b>size_t ZSTD_estimateCDictSize(size_t dictSize, int compressionLevel);
4430c16b537SWarner Loshsize_t ZSTD_estimateCDictSize_advanced(size_t dictSize, ZSTD_compressionParameters cParams, ZSTD_dictLoadMethod_e dictLoadMethod);
4440c16b537SWarner Loshsize_t ZSTD_estimateDDictSize(size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod);
4450c16b537SWarner Losh</b><p>  ZSTD_estimateCDictSize() will bet that src size is relatively "small", and content is copied, like ZSTD_createCDict().
446*19fcbaf1SConrad Meyer  ZSTD_estimateCDictSize_advanced() makes it possible to control compression parameters precisely, like ZSTD_createCDict_advanced().
447*19fcbaf1SConrad Meyer  Note : dictionaries created by reference (`ZSTD_dlm_byRef`) are logically smaller.
4480c16b537SWarner Losh
4490c16b537SWarner Losh</p></pre><BR>
4500c16b537SWarner Losh
4510c16b537SWarner Losh<pre><b>ZSTD_CCtx*    ZSTD_initStaticCCtx(void* workspace, size_t workspaceSize);
452*19fcbaf1SConrad MeyerZSTD_CStream* ZSTD_initStaticCStream(void* workspace, size_t workspaceSize);    </b>/**< same as ZSTD_initStaticCCtx() */<b>
453*19fcbaf1SConrad Meyer</b><p>  Initialize an object using a pre-allocated fixed-size buffer.
454*19fcbaf1SConrad Meyer  workspace: The memory area to emplace the object into.
455*19fcbaf1SConrad Meyer             Provided pointer *must be 8-bytes aligned*.
456*19fcbaf1SConrad Meyer             Buffer must outlive object.
457*19fcbaf1SConrad Meyer  workspaceSize: Use ZSTD_estimate*Size() to determine
458*19fcbaf1SConrad Meyer                 how large workspace must be to support target scenario.
459*19fcbaf1SConrad Meyer @return : pointer to object (same address as workspace, just different type),
460*19fcbaf1SConrad Meyer           or NULL if error (size too small, incorrect alignment, etc.)
461*19fcbaf1SConrad Meyer  Note : zstd will never resize nor malloc() when using a static buffer.
462*19fcbaf1SConrad Meyer         If the object requires more memory than available,
463*19fcbaf1SConrad Meyer         zstd will just error out (typically ZSTD_error_memory_allocation).
4640c16b537SWarner Losh  Note 2 : there is no corresponding "free" function.
465*19fcbaf1SConrad Meyer           Since workspace is allocated externally, it must be freed externally too.
466*19fcbaf1SConrad Meyer  Note 3 : cParams : use ZSTD_getCParams() to convert a compression level
467*19fcbaf1SConrad Meyer           into its associated cParams.
468*19fcbaf1SConrad Meyer  Limitation 1 : currently not compatible with internal dictionary creation, triggered by
469*19fcbaf1SConrad Meyer                 ZSTD_CCtx_loadDictionary(), ZSTD_initCStream_usingDict() or ZSTD_initDStream_usingDict().
470*19fcbaf1SConrad Meyer  Limitation 2 : static cctx currently not compatible with multi-threading.
471*19fcbaf1SConrad Meyer  Limitation 3 : static dctx is incompatible with legacy support.
4720c16b537SWarner Losh
4730c16b537SWarner Losh</p></pre><BR>
4740c16b537SWarner Losh
475*19fcbaf1SConrad Meyer<pre><b>ZSTD_DStream* ZSTD_initStaticDStream(void* workspace, size_t workspaceSize);    </b>/**< same as ZSTD_initStaticDCtx() */<b>
476*19fcbaf1SConrad Meyer</b></pre><BR>
477*19fcbaf1SConrad Meyer<pre><b>typedef void* (*ZSTD_allocFunction) (void* opaque, size_t size);
478*19fcbaf1SConrad Meyertypedef void  (*ZSTD_freeFunction) (void* opaque, void* address);
479*19fcbaf1SConrad Meyertypedef struct { ZSTD_allocFunction customAlloc; ZSTD_freeFunction customFree; void* opaque; } ZSTD_customMem;
480*19fcbaf1SConrad Meyerstatic ZSTD_customMem const ZSTD_defaultCMem = { NULL, NULL, NULL };  </b>/**< this constant defers to stdlib's functions */<b>
481*19fcbaf1SConrad Meyer</b><p>  These prototypes make it possible to pass your own allocation/free functions.
482*19fcbaf1SConrad Meyer  ZSTD_customMem is provided at creation time, using ZSTD_create*_advanced() variants listed below.
483*19fcbaf1SConrad Meyer  All allocation/free operations will be completed using these custom variants instead of regular <stdlib.h> ones.
484*19fcbaf1SConrad Meyer
485*19fcbaf1SConrad Meyer</p></pre><BR>
486*19fcbaf1SConrad Meyer
487*19fcbaf1SConrad Meyer<a name="Chapter14"></a><h2>Advanced compression functions</h2><pre></pre>
488*19fcbaf1SConrad Meyer
4890c16b537SWarner Losh<pre><b>ZSTD_CDict* ZSTD_createCDict_byReference(const void* dictBuffer, size_t dictSize, int compressionLevel);
4900c16b537SWarner Losh</b><p>  Create a digested dictionary for compression
4910c16b537SWarner Losh  Dictionary content is simply referenced, and therefore stays in dictBuffer.
4920c16b537SWarner Losh  It is important that dictBuffer outlives CDict, it must remain read accessible throughout the lifetime of CDict
4930c16b537SWarner Losh</p></pre><BR>
4940c16b537SWarner Losh
4950c16b537SWarner Losh<pre><b>ZSTD_compressionParameters ZSTD_getCParams(int compressionLevel, unsigned long long estimatedSrcSize, size_t dictSize);
4960c16b537SWarner Losh</b><p>   @return ZSTD_compressionParameters structure for a selected compression level and estimated srcSize.
4970c16b537SWarner Losh   `estimatedSrcSize` value is optional, select 0 if not known
4980c16b537SWarner Losh</p></pre><BR>
4990c16b537SWarner Losh
5000c16b537SWarner Losh<pre><b>ZSTD_parameters ZSTD_getParams(int compressionLevel, unsigned long long estimatedSrcSize, size_t dictSize);
5010c16b537SWarner Losh</b><p>   same as ZSTD_getCParams(), but @return a full `ZSTD_parameters` object instead of sub-component `ZSTD_compressionParameters`.
502052d3c12SConrad Meyer   All fields of `ZSTD_frameParameters` are set to default : contentSize=1, checksum=0, noDictID=0
5030c16b537SWarner Losh</p></pre><BR>
5040c16b537SWarner Losh
5050c16b537SWarner Losh<pre><b>size_t ZSTD_checkCParams(ZSTD_compressionParameters params);
5060c16b537SWarner Losh</b><p>   Ensure param values remain within authorized range
5070c16b537SWarner Losh</p></pre><BR>
5080c16b537SWarner Losh
5090c16b537SWarner Losh<pre><b>ZSTD_compressionParameters ZSTD_adjustCParams(ZSTD_compressionParameters cPar, unsigned long long srcSize, size_t dictSize);
5100c16b537SWarner Losh</b><p>  optimize params for a given `srcSize` and `dictSize`.
5110c16b537SWarner Losh  both values are optional, select `0` if unknown.
5120c16b537SWarner Losh</p></pre><BR>
5130c16b537SWarner Losh
5140c16b537SWarner Losh<pre><b>size_t ZSTD_compress_advanced (ZSTD_CCtx* cctx,
5150c16b537SWarner Losh                      void* dst, size_t dstCapacity,
5160c16b537SWarner Losh                const void* src, size_t srcSize,
5170c16b537SWarner Losh                const void* dict,size_t dictSize,
5180c16b537SWarner Losh                      ZSTD_parameters params);
5190c16b537SWarner Losh</b><p>   Same as ZSTD_compress_usingDict(), with fine-tune control over each compression parameter
5200c16b537SWarner Losh</p></pre><BR>
5210c16b537SWarner Losh
5220c16b537SWarner Losh<pre><b>size_t ZSTD_compress_usingCDict_advanced(ZSTD_CCtx* cctx,
5230c16b537SWarner Losh                      void* dst, size_t dstCapacity,
5240c16b537SWarner Losh                const void* src, size_t srcSize,
5250c16b537SWarner Losh                const ZSTD_CDict* cdict, ZSTD_frameParameters fParams);
5260c16b537SWarner Losh</b><p>   Same as ZSTD_compress_usingCDict(), with fine-tune control over frame parameters
5270c16b537SWarner Losh</p></pre><BR>
5280c16b537SWarner Losh
529*19fcbaf1SConrad Meyer<a name="Chapter15"></a><h2>Advanced decompression functions</h2><pre></pre>
5300c16b537SWarner Losh
5310c16b537SWarner Losh<pre><b>unsigned ZSTD_isFrame(const void* buffer, size_t size);
5320c16b537SWarner Losh</b><p>  Tells if the content of `buffer` starts with a valid Frame Identifier.
5330c16b537SWarner Losh  Note : Frame Identifier is 4 bytes. If `size < 4`, @return will always be 0.
5340c16b537SWarner Losh  Note 2 : Legacy Frame Identifiers are considered valid only if Legacy Support is enabled.
5350c16b537SWarner Losh  Note 3 : Skippable Frame Identifiers are considered valid.
5360c16b537SWarner Losh</p></pre><BR>
5370c16b537SWarner Losh
5380c16b537SWarner Losh<pre><b>ZSTD_DDict* ZSTD_createDDict_byReference(const void* dictBuffer, size_t dictSize);
5390c16b537SWarner Losh</b><p>  Create a digested dictionary, ready to start decompression operation without startup delay.
5400c16b537SWarner Losh  Dictionary content is referenced, and therefore stays in dictBuffer.
5410c16b537SWarner Losh  It is important that dictBuffer outlives DDict,
5420c16b537SWarner Losh  it must remain read accessible throughout the lifetime of DDict
5430c16b537SWarner Losh</p></pre><BR>
5440c16b537SWarner Losh
5450c16b537SWarner Losh<pre><b>unsigned ZSTD_getDictID_fromDict(const void* dict, size_t dictSize);
5460c16b537SWarner Losh</b><p>  Provides the dictID stored within dictionary.
5470c16b537SWarner Losh  if @return == 0, the dictionary is not conformant with Zstandard specification.
5480c16b537SWarner Losh  It can still be loaded, but as a content-only dictionary.
5490c16b537SWarner Losh</p></pre><BR>
5500c16b537SWarner Losh
5510c16b537SWarner Losh<pre><b>unsigned ZSTD_getDictID_fromDDict(const ZSTD_DDict* ddict);
5520c16b537SWarner Losh</b><p>  Provides the dictID of the dictionary loaded into `ddict`.
5530c16b537SWarner Losh  If @return == 0, the dictionary is not conformant to Zstandard specification, or empty.
5540c16b537SWarner Losh  Non-conformant dictionaries can still be loaded, but as content-only dictionaries.
5550c16b537SWarner Losh</p></pre><BR>
5560c16b537SWarner Losh
5570c16b537SWarner Losh<pre><b>unsigned ZSTD_getDictID_fromFrame(const void* src, size_t srcSize);
5580c16b537SWarner Losh</b><p>  Provides the dictID required to decompressed the frame stored within `src`.
5590c16b537SWarner Losh  If @return == 0, the dictID could not be decoded.
5600c16b537SWarner Losh  This could for one of the following reasons :
5610c16b537SWarner Losh  - The frame does not require a dictionary to be decoded (most common case).
5620c16b537SWarner Losh  - The frame was built with dictID intentionally removed. Whatever dictionary is necessary is a hidden information.
5630c16b537SWarner Losh    Note : this use case also happens when using a non-conformant dictionary.
5640c16b537SWarner Losh  - `srcSize` is too small, and as a result, the frame header could not be decoded (only possible if `srcSize < ZSTD_FRAMEHEADERSIZE_MAX`).
5650c16b537SWarner Losh  - This is not a Zstandard frame.
5660c16b537SWarner Losh  When identifying the exact failure cause, it's possible to use ZSTD_getFrameHeader(), which will provide a more precise error code.
5670c16b537SWarner Losh</p></pre><BR>
5680c16b537SWarner Losh
569*19fcbaf1SConrad Meyer<a name="Chapter16"></a><h2>Advanced streaming functions</h2><pre></pre>
5700c16b537SWarner Losh
571*19fcbaf1SConrad Meyer<h3>Advanced Streaming compression functions</h3><pre></pre><b><pre>size_t ZSTD_initCStream_srcSize(ZSTD_CStream* zcs, int compressionLevel, unsigned long long pledgedSrcSize);   </b>/**< pledgedSrcSize must be correct. If it is not known at init time, use ZSTD_CONTENTSIZE_UNKNOWN. Note that, for compatibility with older programs, "0" also disables frame content size field. It may be enabled in the future. */<b>
5720c16b537SWarner Loshsize_t ZSTD_initCStream_usingDict(ZSTD_CStream* zcs, const void* dict, size_t dictSize, int compressionLevel); </b>/**< creates of an internal CDict (incompatible with static CCtx), except if dict == NULL or dictSize < 8, in which case no dict is used. Note: dict is loaded with ZSTD_dm_auto (treated as a full zstd dictionary if it begins with ZSTD_MAGIC_DICTIONARY, else as raw content) and ZSTD_dlm_byCopy.*/<b>
5730c16b537SWarner Loshsize_t ZSTD_initCStream_advanced(ZSTD_CStream* zcs, const void* dict, size_t dictSize,
574052d3c12SConrad Meyer                                             ZSTD_parameters params, unsigned long long pledgedSrcSize);  </b>/**< pledgedSrcSize must be correct. If srcSize is not known at init time, use value ZSTD_CONTENTSIZE_UNKNOWN. dict is loaded with ZSTD_dm_auto and ZSTD_dlm_byCopy. */<b>
5750c16b537SWarner Loshsize_t ZSTD_initCStream_usingCDict(ZSTD_CStream* zcs, const ZSTD_CDict* cdict);  </b>/**< note : cdict will just be referenced, and must outlive compression session */<b>
576052d3c12SConrad Meyersize_t ZSTD_initCStream_usingCDict_advanced(ZSTD_CStream* zcs, const ZSTD_CDict* cdict, ZSTD_frameParameters fParams, unsigned long long pledgedSrcSize);  </b>/**< same as ZSTD_initCStream_usingCDict(), with control over frame parameters. pledgedSrcSize must be correct. If srcSize is not known at init time, use value ZSTD_CONTENTSIZE_UNKNOWN. */<b>
5770c16b537SWarner Losh</pre></b><BR>
5780c16b537SWarner Losh<pre><b>size_t ZSTD_resetCStream(ZSTD_CStream* zcs, unsigned long long pledgedSrcSize);
5790c16b537SWarner Losh</b><p>  start a new compression job, using same parameters from previous job.
5800c16b537SWarner Losh  This is typically useful to skip dictionary loading stage, since it will re-use it in-place..
5810c16b537SWarner Losh  Note that zcs must be init at least once before using ZSTD_resetCStream().
582052d3c12SConrad Meyer  If pledgedSrcSize is not known at reset time, use macro ZSTD_CONTENTSIZE_UNKNOWN.
5830c16b537SWarner Losh  If pledgedSrcSize > 0, its value must be correct, as it will be written in header, and controlled at the end.
584052d3c12SConrad Meyer  For the time being, pledgedSrcSize==0 is interpreted as "srcSize unknown" for compatibility with older programs,
585*19fcbaf1SConrad Meyer  but it will change to mean "empty" in future version, so use macro ZSTD_CONTENTSIZE_UNKNOWN instead.
5860c16b537SWarner Losh @return : 0, or an error code (which can be tested using ZSTD_isError())
5870c16b537SWarner Losh</p></pre><BR>
5880c16b537SWarner Losh
589*19fcbaf1SConrad Meyer<pre><b>typedef struct {
590*19fcbaf1SConrad Meyer    unsigned long long ingested;
591*19fcbaf1SConrad Meyer    unsigned long long consumed;
592*19fcbaf1SConrad Meyer    unsigned long long produced;
593*19fcbaf1SConrad Meyer} ZSTD_frameProgression;
594*19fcbaf1SConrad Meyer</b></pre><BR>
595*19fcbaf1SConrad Meyer<h3>Advanced Streaming decompression functions</h3><pre></pre><b><pre>typedef enum { DStream_p_maxWindowSize } ZSTD_DStreamParameter_e;
5960c16b537SWarner Loshsize_t ZSTD_setDStreamParameter(ZSTD_DStream* zds, ZSTD_DStreamParameter_e paramType, unsigned paramValue);   </b>/* obsolete : this API will be removed in a future version */<b>
5970c16b537SWarner Loshsize_t ZSTD_initDStream_usingDict(ZSTD_DStream* zds, const void* dict, size_t dictSize); </b>/**< note: no dictionary will be used if dict == NULL or dictSize < 8 */<b>
5980c16b537SWarner Loshsize_t ZSTD_initDStream_usingDDict(ZSTD_DStream* zds, const ZSTD_DDict* ddict);  </b>/**< note : ddict is referenced, it must outlive decompression session */<b>
5990c16b537SWarner Loshsize_t ZSTD_resetDStream(ZSTD_DStream* zds);  </b>/**< re-use decompression parameters from previous init; saves dictionary loading */<b>
6000c16b537SWarner Losh</pre></b><BR>
601*19fcbaf1SConrad Meyer<a name="Chapter17"></a><h2>Buffer-less and synchronous inner streaming functions</h2><pre>
6020c16b537SWarner Losh  This is an advanced API, giving full control over buffer management, for users which need direct control over memory.
6030c16b537SWarner Losh  But it's also a complex one, with several restrictions, documented below.
6040c16b537SWarner Losh  Prefer normal streaming API for an easier experience.
6050c16b537SWarner Losh
6060c16b537SWarner Losh<BR></pre>
6070c16b537SWarner Losh
608*19fcbaf1SConrad Meyer<a name="Chapter18"></a><h2>Buffer-less streaming compression (synchronous mode)</h2><pre>
6090c16b537SWarner Losh  A ZSTD_CCtx object is required to track streaming operations.
6100c16b537SWarner Losh  Use ZSTD_createCCtx() / ZSTD_freeCCtx() to manage resource.
6110c16b537SWarner Losh  ZSTD_CCtx object can be re-used multiple times within successive compression operations.
6120c16b537SWarner Losh
6130c16b537SWarner Losh  Start by initializing a context.
6140c16b537SWarner Losh  Use ZSTD_compressBegin(), or ZSTD_compressBegin_usingDict() for dictionary compression,
6150c16b537SWarner Losh  or ZSTD_compressBegin_advanced(), for finer parameter control.
6160c16b537SWarner Losh  It's also possible to duplicate a reference context which has already been initialized, using ZSTD_copyCCtx()
6170c16b537SWarner Losh
6180c16b537SWarner Losh  Then, consume your input using ZSTD_compressContinue().
6190c16b537SWarner Losh  There are some important considerations to keep in mind when using this advanced function :
6200c16b537SWarner Losh  - ZSTD_compressContinue() has no internal buffer. It uses externally provided buffers only.
6210c16b537SWarner Losh  - Interface is synchronous : input is consumed entirely and produces 1+ compressed blocks.
6220c16b537SWarner Losh  - Caller must ensure there is enough space in `dst` to store compressed data under worst case scenario.
6230c16b537SWarner Losh    Worst case evaluation is provided by ZSTD_compressBound().
6240c16b537SWarner Losh    ZSTD_compressContinue() doesn't guarantee recover after a failed compression.
6250c16b537SWarner Losh  - ZSTD_compressContinue() presumes prior input ***is still accessible and unmodified*** (up to maximum distance size, see WindowLog).
6260c16b537SWarner Losh    It remembers all previous contiguous blocks, plus one separated memory segment (which can itself consists of multiple contiguous blocks)
6270c16b537SWarner Losh  - ZSTD_compressContinue() detects that prior input has been overwritten when `src` buffer overlaps.
6280c16b537SWarner Losh    In which case, it will "discard" the relevant memory section from its history.
6290c16b537SWarner Losh
6300c16b537SWarner Losh  Finish a frame with ZSTD_compressEnd(), which will write the last block(s) and optional checksum.
6310c16b537SWarner Losh  It's possible to use srcSize==0, in which case, it will write a final empty block to end the frame.
6320c16b537SWarner Losh  Without last block mark, frames are considered unfinished (hence corrupted) by compliant decoders.
6330c16b537SWarner Losh
6340c16b537SWarner Losh  `ZSTD_CCtx` object can be re-used (ZSTD_compressBegin()) to compress again.
6350c16b537SWarner Losh<BR></pre>
6360c16b537SWarner Losh
6370c16b537SWarner Losh<h3>Buffer-less streaming compression functions</h3><pre></pre><b><pre>size_t ZSTD_compressBegin(ZSTD_CCtx* cctx, int compressionLevel);
6380c16b537SWarner Loshsize_t ZSTD_compressBegin_usingDict(ZSTD_CCtx* cctx, const void* dict, size_t dictSize, int compressionLevel);
639052d3c12SConrad Meyersize_t ZSTD_compressBegin_advanced(ZSTD_CCtx* cctx, const void* dict, size_t dictSize, ZSTD_parameters params, unsigned long long pledgedSrcSize); </b>/**< pledgedSrcSize : If srcSize is not known at init time, use ZSTD_CONTENTSIZE_UNKNOWN */<b>
6400c16b537SWarner Loshsize_t ZSTD_compressBegin_usingCDict(ZSTD_CCtx* cctx, const ZSTD_CDict* cdict); </b>/**< note: fails if cdict==NULL */<b>
641052d3c12SConrad Meyersize_t ZSTD_compressBegin_usingCDict_advanced(ZSTD_CCtx* const cctx, const ZSTD_CDict* const cdict, ZSTD_frameParameters const fParams, unsigned long long const pledgedSrcSize);   </b>/* compression parameters are already set within cdict. pledgedSrcSize must be correct. If srcSize is not known, use macro ZSTD_CONTENTSIZE_UNKNOWN */<b>
642052d3c12SConrad Meyersize_t ZSTD_copyCCtx(ZSTD_CCtx* cctx, const ZSTD_CCtx* preparedCCtx, unsigned long long pledgedSrcSize); </b>/**<  note: if pledgedSrcSize is not known, use ZSTD_CONTENTSIZE_UNKNOWN */<b>
6430c16b537SWarner Losh</pre></b><BR>
644*19fcbaf1SConrad Meyer<a name="Chapter19"></a><h2>Buffer-less streaming decompression (synchronous mode)</h2><pre>
6450c16b537SWarner Losh  A ZSTD_DCtx object is required to track streaming operations.
6460c16b537SWarner Losh  Use ZSTD_createDCtx() / ZSTD_freeDCtx() to manage it.
6470c16b537SWarner Losh  A ZSTD_DCtx object can be re-used multiple times.
6480c16b537SWarner Losh
6490c16b537SWarner Losh  First typical operation is to retrieve frame parameters, using ZSTD_getFrameHeader().
6500c16b537SWarner Losh  Frame header is extracted from the beginning of compressed frame, so providing only the frame's beginning is enough.
6510c16b537SWarner Losh  Data fragment must be large enough to ensure successful decoding.
6520c16b537SWarner Losh `ZSTD_frameHeaderSize_max` bytes is guaranteed to always be large enough.
6530c16b537SWarner Losh  @result : 0 : successful decoding, the `ZSTD_frameHeader` structure is correctly filled.
6540c16b537SWarner Losh           >0 : `srcSize` is too small, please provide at least @result bytes on next attempt.
6550c16b537SWarner Losh           errorCode, which can be tested using ZSTD_isError().
6560c16b537SWarner Losh
6570c16b537SWarner Losh  It fills a ZSTD_frameHeader structure with important information to correctly decode the frame,
6580c16b537SWarner Losh  such as the dictionary ID, content size, or maximum back-reference distance (`windowSize`).
6590c16b537SWarner Losh  Note that these values could be wrong, either because of data corruption, or because a 3rd party deliberately spoofs false information.
6600c16b537SWarner Losh  As a consequence, check that values remain within valid application range.
6610c16b537SWarner Losh  For example, do not allocate memory blindly, check that `windowSize` is within expectation.
6620c16b537SWarner Losh  Each application can set its own limits, depending on local restrictions.
6630c16b537SWarner Losh  For extended interoperability, it is recommended to support `windowSize` of at least 8 MB.
6640c16b537SWarner Losh
6650c16b537SWarner Losh  ZSTD_decompressContinue() needs previous data blocks during decompression, up to `windowSize` bytes.
6660c16b537SWarner Losh  ZSTD_decompressContinue() is very sensitive to contiguity,
6670c16b537SWarner Losh  if 2 blocks don't follow each other, make sure that either the compressor breaks contiguity at the same place,
6680c16b537SWarner Losh  or that previous contiguous segment is large enough to properly handle maximum back-reference distance.
6690c16b537SWarner Losh  There are multiple ways to guarantee this condition.
6700c16b537SWarner Losh
6710c16b537SWarner Losh  The most memory efficient way is to use a round buffer of sufficient size.
6720c16b537SWarner Losh  Sufficient size is determined by invoking ZSTD_decodingBufferSize_min(),
6730c16b537SWarner Losh  which can @return an error code if required value is too large for current system (in 32-bits mode).
6740c16b537SWarner Losh  In a round buffer methodology, ZSTD_decompressContinue() decompresses each block next to previous one,
6750c16b537SWarner Losh  up to the moment there is not enough room left in the buffer to guarantee decoding another full block,
6760c16b537SWarner Losh  which maximum size is provided in `ZSTD_frameHeader` structure, field `blockSizeMax`.
6770c16b537SWarner Losh  At which point, decoding can resume from the beginning of the buffer.
6780c16b537SWarner Losh  Note that already decoded data stored in the buffer should be flushed before being overwritten.
6790c16b537SWarner Losh
6800c16b537SWarner Losh  There are alternatives possible, for example using two or more buffers of size `windowSize` each, though they consume more memory.
6810c16b537SWarner Losh
6820c16b537SWarner Losh  Finally, if you control the compression process, you can also ignore all buffer size rules,
6830c16b537SWarner Losh  as long as the encoder and decoder progress in "lock-step",
6840c16b537SWarner Losh  aka use exactly the same buffer sizes, break contiguity at the same place, etc.
6850c16b537SWarner Losh
6860c16b537SWarner Losh  Once buffers are setup, start decompression, with ZSTD_decompressBegin().
6870c16b537SWarner Losh  If decompression requires a dictionary, use ZSTD_decompressBegin_usingDict() or ZSTD_decompressBegin_usingDDict().
6880c16b537SWarner Losh
6890c16b537SWarner Losh  Then use ZSTD_nextSrcSizeToDecompress() and ZSTD_decompressContinue() alternatively.
6900c16b537SWarner Losh  ZSTD_nextSrcSizeToDecompress() tells how many bytes to provide as 'srcSize' to ZSTD_decompressContinue().
6910c16b537SWarner Losh  ZSTD_decompressContinue() requires this _exact_ amount of bytes, or it will fail.
6920c16b537SWarner Losh
6930c16b537SWarner Losh @result of ZSTD_decompressContinue() is the number of bytes regenerated within 'dst' (necessarily <= dstCapacity).
6940c16b537SWarner Losh  It can be zero : it just means ZSTD_decompressContinue() has decoded some metadata item.
6950c16b537SWarner Losh  It can also be an error code, which can be tested with ZSTD_isError().
6960c16b537SWarner Losh
6970c16b537SWarner Losh  A frame is fully decoded when ZSTD_nextSrcSizeToDecompress() returns zero.
6980c16b537SWarner Losh  Context can then be reset to start a new decompression.
6990c16b537SWarner Losh
7000c16b537SWarner Losh  Note : it's possible to know if next input to present is a header or a block, using ZSTD_nextInputType().
7010c16b537SWarner Losh  This information is not required to properly decode a frame.
7020c16b537SWarner Losh
7030c16b537SWarner Losh  == Special case : skippable frames
7040c16b537SWarner Losh
7050c16b537SWarner Losh  Skippable frames allow integration of user-defined data into a flow of concatenated frames.
7060c16b537SWarner Losh  Skippable frames will be ignored (skipped) by decompressor.
7070c16b537SWarner Losh  The format of skippable frames is as follows :
7080c16b537SWarner Losh  a) Skippable frame ID - 4 Bytes, Little endian format, any value from 0x184D2A50 to 0x184D2A5F
7090c16b537SWarner Losh  b) Frame Size - 4 Bytes, Little endian format, unsigned 32-bits
7100c16b537SWarner Losh  c) Frame Content - any content (User Data) of length equal to Frame Size
7110c16b537SWarner Losh  For skippable frames ZSTD_getFrameHeader() returns zfhPtr->frameType==ZSTD_skippableFrame.
7120c16b537SWarner Losh  For skippable frames ZSTD_decompressContinue() always returns 0 : it only skips the content.
7130c16b537SWarner Losh<BR></pre>
7140c16b537SWarner Losh
7150c16b537SWarner Losh<h3>Buffer-less streaming decompression functions</h3><pre></pre><b><pre>typedef enum { ZSTD_frame, ZSTD_skippableFrame } ZSTD_frameType_e;
7160c16b537SWarner Loshtypedef struct {
7170c16b537SWarner Losh    unsigned long long frameContentSize; </b>/* if == ZSTD_CONTENTSIZE_UNKNOWN, it means this field is not available. 0 means "empty" */<b>
7180c16b537SWarner Losh    unsigned long long windowSize;       </b>/* can be very large, up to <= frameContentSize */<b>
7190c16b537SWarner Losh    unsigned blockSizeMax;
7200c16b537SWarner Losh    ZSTD_frameType_e frameType;          </b>/* if == ZSTD_skippableFrame, frameContentSize is the size of skippable content */<b>
7210c16b537SWarner Losh    unsigned headerSize;
7220c16b537SWarner Losh    unsigned dictID;
7230c16b537SWarner Losh    unsigned checksumFlag;
7240c16b537SWarner Losh} ZSTD_frameHeader;
7250c16b537SWarner Loshsize_t ZSTD_getFrameHeader(ZSTD_frameHeader* zfhPtr, const void* src, size_t srcSize);   </b>/**< doesn't consume input */<b>
7260c16b537SWarner Loshsize_t ZSTD_decodingBufferSize_min(unsigned long long windowSize, unsigned long long frameContentSize);  </b>/**< when frame content size is not known, pass in frameContentSize == ZSTD_CONTENTSIZE_UNKNOWN */<b>
7270c16b537SWarner Losh</pre></b><BR>
7280c16b537SWarner Losh<pre><b>typedef enum { ZSTDnit_frameHeader, ZSTDnit_blockHeader, ZSTDnit_block, ZSTDnit_lastBlock, ZSTDnit_checksum, ZSTDnit_skippableFrame } ZSTD_nextInputType_e;
7290c16b537SWarner Losh</b></pre><BR>
730*19fcbaf1SConrad Meyer<a name="Chapter20"></a><h2>New advanced API (experimental)</h2><pre></pre>
7310c16b537SWarner Losh
7320c16b537SWarner Losh<pre><b>typedef enum {
733*19fcbaf1SConrad Meyer    </b>/* Opened question : should we have a format ZSTD_f_auto ?<b>
734*19fcbaf1SConrad Meyer     * Today, it would mean exactly the same as ZSTD_f_zstd1.
735*19fcbaf1SConrad Meyer     * But, in the future, should several formats become supported,
7360c16b537SWarner Losh     * on the compression side, it would mean "default format".
737*19fcbaf1SConrad Meyer     * On the decompression side, it would mean "automatic format detection",
738*19fcbaf1SConrad Meyer     * so that ZSTD_f_zstd1 would mean "accept *only* zstd frames".
7390c16b537SWarner Losh     * Since meaning is a little different, another option could be to define different enums for compression and decompression.
7400c16b537SWarner Losh     * This question could be kept for later, when there are actually multiple formats to support,
7410c16b537SWarner Losh     * but there is also the question of pinning enum values, and pinning value `0` is especially important */
7420c16b537SWarner Losh    ZSTD_f_zstd1 = 0,        </b>/* zstd frame format, specified in zstd_compression_format.md (default) */<b>
7430c16b537SWarner Losh    ZSTD_f_zstd1_magicless,  </b>/* Variant of zstd frame format, without initial 4-bytes magic number.<b>
7440c16b537SWarner Losh                              * Useful to save 4 bytes per generated frame.
7450c16b537SWarner Losh                              * Decoder cannot recognise automatically this format, requiring instructions. */
7460c16b537SWarner Losh} ZSTD_format_e;
7470c16b537SWarner Losh</b></pre><BR>
7480c16b537SWarner Losh<pre><b>typedef enum {
7490c16b537SWarner Losh    </b>/* compression format */<b>
7500c16b537SWarner Losh    ZSTD_p_format = 10,      </b>/* See ZSTD_format_e enum definition.<b>
7510c16b537SWarner Losh                              * Cast selected format as unsigned for ZSTD_CCtx_setParameter() compatibility. */
7520c16b537SWarner Losh
7530c16b537SWarner Losh    </b>/* compression parameters */<b>
7540c16b537SWarner Losh    ZSTD_p_compressionLevel=100, </b>/* Update all compression parameters according to pre-defined cLevel table<b>
7550c16b537SWarner Losh                              * Default level is ZSTD_CLEVEL_DEFAULT==3.
756*19fcbaf1SConrad Meyer                              * Special: value 0 means "do not change cLevel".
757*19fcbaf1SConrad Meyer                              * Note 1 : it's possible to pass a negative compression level by casting it to unsigned type.
758*19fcbaf1SConrad Meyer                              * Note 2 : setting a level sets all default values of other compression parameters.
759*19fcbaf1SConrad Meyer                              * Note 3 : setting compressionLevel automatically updates ZSTD_p_compressLiterals. */
7600c16b537SWarner Losh    ZSTD_p_windowLog,        </b>/* Maximum allowed back-reference distance, expressed as power of 2.<b>
7610c16b537SWarner Losh                              * Must be clamped between ZSTD_WINDOWLOG_MIN and ZSTD_WINDOWLOG_MAX.
762*19fcbaf1SConrad Meyer                              * Special: value 0 means "use default windowLog".
7630c16b537SWarner Losh                              * Note: Using a window size greater than ZSTD_MAXWINDOWSIZE_DEFAULT (default: 2^27)
764*19fcbaf1SConrad Meyer                              *       requires explicitly allowing such window size during decompression stage. */
7650c16b537SWarner Losh    ZSTD_p_hashLog,          </b>/* Size of the probe table, as a power of 2.<b>
7660c16b537SWarner Losh                              * Resulting table size is (1 << (hashLog+2)).
7670c16b537SWarner Losh                              * Must be clamped between ZSTD_HASHLOG_MIN and ZSTD_HASHLOG_MAX.
7680c16b537SWarner Losh                              * Larger tables improve compression ratio of strategies <= dFast,
7690c16b537SWarner Losh                              * and improve speed of strategies > dFast.
770*19fcbaf1SConrad Meyer                              * Special: value 0 means "use default hashLog". */
7710c16b537SWarner Losh    ZSTD_p_chainLog,         </b>/* Size of the full-search table, as a power of 2.<b>
7720c16b537SWarner Losh                              * Resulting table size is (1 << (chainLog+2)).
7730c16b537SWarner Losh                              * Larger tables result in better and slower compression.
7740c16b537SWarner Losh                              * This parameter is useless when using "fast" strategy.
775*19fcbaf1SConrad Meyer                              * Special: value 0 means "use default chainLog". */
7760c16b537SWarner Losh    ZSTD_p_searchLog,        </b>/* Number of search attempts, as a power of 2.<b>
7770c16b537SWarner Losh                              * More attempts result in better and slower compression.
7780c16b537SWarner Losh                              * This parameter is useless when using "fast" and "dFast" strategies.
779*19fcbaf1SConrad Meyer                              * Special: value 0 means "use default searchLog". */
7800c16b537SWarner Losh    ZSTD_p_minMatch,         </b>/* Minimum size of searched matches (note : repCode matches can be smaller).<b>
7810c16b537SWarner Losh                              * Larger values make faster compression and decompression, but decrease ratio.
7820c16b537SWarner Losh                              * Must be clamped between ZSTD_SEARCHLENGTH_MIN and ZSTD_SEARCHLENGTH_MAX.
7830c16b537SWarner Losh                              * Note that currently, for all strategies < btopt, effective minimum is 4.
784*19fcbaf1SConrad Meyer                              *                    , for all strategies > fast, effective maximum is 6.
785*19fcbaf1SConrad Meyer                              * Special: value 0 means "use default minMatchLength". */
786*19fcbaf1SConrad Meyer    ZSTD_p_targetLength,     </b>/* Impact of this field depends on strategy.<b>
787*19fcbaf1SConrad Meyer                              * For strategies btopt & btultra:
7880c16b537SWarner Losh                              *     Length of Match considered "good enough" to stop search.
789*19fcbaf1SConrad Meyer                              *     Larger values make compression stronger, and slower.
790*19fcbaf1SConrad Meyer                              * For strategy fast:
791*19fcbaf1SConrad Meyer                              *     Distance between match sampling.
792*19fcbaf1SConrad Meyer                              *     Larger values make compression faster, and weaker.
793*19fcbaf1SConrad Meyer                              * Special: value 0 means "use default targetLength". */
7940c16b537SWarner Losh    ZSTD_p_compressionStrategy, </b>/* See ZSTD_strategy enum definition.<b>
7950c16b537SWarner Losh                              * Cast selected strategy as unsigned for ZSTD_CCtx_setParameter() compatibility.
7960c16b537SWarner Losh                              * The higher the value of selected strategy, the more complex it is,
7970c16b537SWarner Losh                              * resulting in stronger and slower compression.
798*19fcbaf1SConrad Meyer                              * Special: value 0 means "use default strategy". */
799*19fcbaf1SConrad Meyer
800*19fcbaf1SConrad Meyer    ZSTD_p_enableLongDistanceMatching=160, </b>/* Enable long distance matching.<b>
801*19fcbaf1SConrad Meyer                                         * This parameter is designed to improve compression ratio
802*19fcbaf1SConrad Meyer                                         * for large inputs, by finding large matches at long distance.
803*19fcbaf1SConrad Meyer                                         * It increases memory usage and window size.
804*19fcbaf1SConrad Meyer                                         * Note: enabling this parameter increases ZSTD_p_windowLog to 128 MB
805*19fcbaf1SConrad Meyer                                         * except when expressly set to a different value. */
806*19fcbaf1SConrad Meyer    ZSTD_p_ldmHashLog,       </b>/* Size of the table for long distance matching, as a power of 2.<b>
807*19fcbaf1SConrad Meyer                              * Larger values increase memory usage and compression ratio,
808*19fcbaf1SConrad Meyer                              * but decrease compression speed.
809*19fcbaf1SConrad Meyer                              * Must be clamped between ZSTD_HASHLOG_MIN and ZSTD_HASHLOG_MAX
810*19fcbaf1SConrad Meyer                              * default: windowlog - 7.
811*19fcbaf1SConrad Meyer                              * Special: value 0 means "automatically determine hashlog". */
812*19fcbaf1SConrad Meyer    ZSTD_p_ldmMinMatch,      </b>/* Minimum match size for long distance matcher.<b>
813*19fcbaf1SConrad Meyer                              * Larger/too small values usually decrease compression ratio.
814*19fcbaf1SConrad Meyer                              * Must be clamped between ZSTD_LDM_MINMATCH_MIN and ZSTD_LDM_MINMATCH_MAX.
815*19fcbaf1SConrad Meyer                              * Special: value 0 means "use default value" (default: 64). */
816*19fcbaf1SConrad Meyer    ZSTD_p_ldmBucketSizeLog, </b>/* Log size of each bucket in the LDM hash table for collision resolution.<b>
817*19fcbaf1SConrad Meyer                              * Larger values improve collision resolution but decrease compression speed.
818*19fcbaf1SConrad Meyer                              * The maximum value is ZSTD_LDM_BUCKETSIZELOG_MAX .
819*19fcbaf1SConrad Meyer                              * Special: value 0 means "use default value" (default: 3). */
820*19fcbaf1SConrad Meyer    ZSTD_p_ldmHashEveryLog,  </b>/* Frequency of inserting/looking up entries in the LDM hash table.<b>
821*19fcbaf1SConrad Meyer                              * Must be clamped between 0 and (ZSTD_WINDOWLOG_MAX - ZSTD_HASHLOG_MIN).
822*19fcbaf1SConrad Meyer                              * Default is MAX(0, (windowLog - ldmHashLog)), optimizing hash table usage.
823*19fcbaf1SConrad Meyer                              * Larger values improve compression speed.
824*19fcbaf1SConrad Meyer                              * Deviating far from default value will likely result in a compression ratio decrease.
825*19fcbaf1SConrad Meyer                              * Special: value 0 means "automatically determine hashEveryLog". */
8260c16b537SWarner Losh
8270c16b537SWarner Losh    </b>/* frame parameters */<b>
828052d3c12SConrad Meyer    ZSTD_p_contentSizeFlag=200, </b>/* Content size will be written into frame header _whenever known_ (default:1)<b>
829052d3c12SConrad Meyer                              * Content size must be known at the beginning of compression,
830052d3c12SConrad Meyer                              * it is provided using ZSTD_CCtx_setPledgedSrcSize() */
8310c16b537SWarner Losh    ZSTD_p_checksumFlag,     </b>/* A 32-bits checksum of content is written at end of frame (default:0) */<b>
832052d3c12SConrad Meyer    ZSTD_p_dictIDFlag,       </b>/* When applicable, dictionary's ID is written into frame header (default:1) */<b>
8330c16b537SWarner Losh
8340c16b537SWarner Losh    </b>/* multi-threading parameters */<b>
835*19fcbaf1SConrad Meyer    </b>/* These parameters are only useful if multi-threading is enabled (ZSTD_MULTITHREAD).<b>
836*19fcbaf1SConrad Meyer     * They return an error otherwise. */
837*19fcbaf1SConrad Meyer    ZSTD_p_nbWorkers=400,    </b>/* Select how many threads will be spawned to compress in parallel.<b>
838*19fcbaf1SConrad Meyer                              * When nbWorkers >= 1, triggers asynchronous mode :
839*19fcbaf1SConrad Meyer                              * ZSTD_compress_generic() consumes some input, flush some output if possible, and immediately gives back control to caller,
840*19fcbaf1SConrad Meyer                              * while compression work is performed in parallel, within worker threads.
841*19fcbaf1SConrad Meyer                              * (note : a strong exception to this rule is when first invocation sets ZSTD_e_end : it becomes a blocking call).
842*19fcbaf1SConrad Meyer                              * More workers improve speed, but also increase memory usage.
843*19fcbaf1SConrad Meyer                              * Default value is `0`, aka "single-threaded mode" : no worker is spawned, compression is performed inside Caller's thread, all invocations are blocking */
844*19fcbaf1SConrad Meyer    ZSTD_p_jobSize,          </b>/* Size of a compression job. This value is enforced only in non-blocking mode.<b>
845*19fcbaf1SConrad Meyer                              * Each compression job is completed in parallel, so this value indirectly controls the nb of active threads.
8460c16b537SWarner Losh                              * 0 means default, which is dynamically determined based on compression parameters.
847*19fcbaf1SConrad Meyer                              * Job size must be a minimum of overlapSize, or 1 MB, whichever is largest.
8480c16b537SWarner Losh                              * The minimum size is automatically and transparently enforced */
8490c16b537SWarner Losh    ZSTD_p_overlapSizeLog,   </b>/* Size of previous input reloaded at the beginning of each job.<b>
8500c16b537SWarner Losh                              * 0 => no overlap, 6(default) => use 1/8th of windowSize, >=9 => use full windowSize */
8510c16b537SWarner Losh
852*19fcbaf1SConrad Meyer    </b>/* =================================================================== */<b>
853*19fcbaf1SConrad Meyer    </b>/* experimental parameters - no stability guaranteed                   */<b>
854*19fcbaf1SConrad Meyer    </b>/* =================================================================== */<b>
855*19fcbaf1SConrad Meyer
856*19fcbaf1SConrad Meyer    ZSTD_p_compressLiterals=1000, </b>/* control huffman compression of literals (enabled) by default.<b>
857*19fcbaf1SConrad Meyer                              * disabling it improves speed and decreases compression ratio by a large amount.
858*19fcbaf1SConrad Meyer                              * note : this setting is automatically updated when changing compression level.
859*19fcbaf1SConrad Meyer                              *        positive compression levels set ZSTD_p_compressLiterals to 1.
860*19fcbaf1SConrad Meyer                              *        negative compression levels set ZSTD_p_compressLiterals to 0. */
861*19fcbaf1SConrad Meyer
8620c16b537SWarner Losh    ZSTD_p_forceMaxWindow=1100, </b>/* Force back-reference distances to remain < windowSize,<b>
8630c16b537SWarner Losh                              * even when referencing into Dictionary content (default:0) */
8640c16b537SWarner Losh
8650c16b537SWarner Losh} ZSTD_cParameter;
8660c16b537SWarner Losh</b></pre><BR>
8670c16b537SWarner Losh<pre><b>size_t ZSTD_CCtx_setParameter(ZSTD_CCtx* cctx, ZSTD_cParameter param, unsigned value);
8680c16b537SWarner Losh</b><p>  Set one compression parameter, selected by enum ZSTD_cParameter.
869*19fcbaf1SConrad Meyer  Setting a parameter is generally only possible during frame initialization (before starting compression),
870*19fcbaf1SConrad Meyer  except for a few exceptions which can be updated during compression: compressionLevel, hashLog, chainLog, searchLog, minMatch, targetLength and strategy.
8710c16b537SWarner Losh  Note : when `value` is an enum, cast it to unsigned for proper type checking.
872*19fcbaf1SConrad Meyer  @result : informational value (typically, value being set clamped correctly),
873052d3c12SConrad Meyer            or an error code (which can be tested with ZSTD_isError()).
8740c16b537SWarner Losh</p></pre><BR>
8750c16b537SWarner Losh
8760c16b537SWarner Losh<pre><b>size_t ZSTD_CCtx_setPledgedSrcSize(ZSTD_CCtx* cctx, unsigned long long pledgedSrcSize);
8770c16b537SWarner Losh</b><p>  Total input data size to be compressed as a single frame.
8780c16b537SWarner Losh  This value will be controlled at the end, and result in error if not respected.
8790c16b537SWarner Losh @result : 0, or an error code (which can be tested with ZSTD_isError()).
8800c16b537SWarner Losh  Note 1 : 0 means zero, empty.
8810c16b537SWarner Losh           In order to mean "unknown content size", pass constant ZSTD_CONTENTSIZE_UNKNOWN.
882052d3c12SConrad Meyer           ZSTD_CONTENTSIZE_UNKNOWN is default value for any new compression job.
8830c16b537SWarner Losh  Note 2 : If all data is provided and consumed in a single round,
8840c16b537SWarner Losh           this value is overriden by srcSize instead.
8850c16b537SWarner Losh</p></pre><BR>
8860c16b537SWarner Losh
8870c16b537SWarner Losh<pre><b>size_t ZSTD_CCtx_loadDictionary(ZSTD_CCtx* cctx, const void* dict, size_t dictSize);
8880c16b537SWarner Loshsize_t ZSTD_CCtx_loadDictionary_byReference(ZSTD_CCtx* cctx, const void* dict, size_t dictSize);
889*19fcbaf1SConrad Meyersize_t ZSTD_CCtx_loadDictionary_advanced(ZSTD_CCtx* cctx, const void* dict, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictContentType_e dictContentType);
890*19fcbaf1SConrad Meyer</b><p>  Create an internal CDict from `dict` buffer.
891*19fcbaf1SConrad Meyer  Decompression will have to use same dictionary.
8920c16b537SWarner Losh @result : 0, or an error code (which can be tested with ZSTD_isError()).
893*19fcbaf1SConrad Meyer  Special: Adding a NULL (or 0-size) dictionary invalidates previous dictionary,
8940c16b537SWarner Losh           meaning "return to no-dictionary mode".
895*19fcbaf1SConrad Meyer  Note 1 : Dictionary will be used for all future compression jobs.
896*19fcbaf1SConrad Meyer           To return to "no-dictionary" situation, load a NULL dictionary
8970c16b537SWarner Losh  Note 2 : Loading a dictionary involves building tables, which are dependent on compression parameters.
8980c16b537SWarner Losh           For this reason, compression parameters cannot be changed anymore after loading a dictionary.
899*19fcbaf1SConrad Meyer           It's also a CPU consuming operation, with non-negligible impact on latency.
900*19fcbaf1SConrad Meyer  Note 3 :`dict` content will be copied internally.
901*19fcbaf1SConrad Meyer           Use ZSTD_CCtx_loadDictionary_byReference() to reference dictionary content instead.
902*19fcbaf1SConrad Meyer           In such a case, dictionary buffer must outlive its users.
903*19fcbaf1SConrad Meyer  Note 4 : Use ZSTD_CCtx_loadDictionary_advanced()
904*19fcbaf1SConrad Meyer           to precisely select how dictionary content must be interpreted.
9050c16b537SWarner Losh</p></pre><BR>
9060c16b537SWarner Losh
9070c16b537SWarner Losh<pre><b>size_t ZSTD_CCtx_refCDict(ZSTD_CCtx* cctx, const ZSTD_CDict* cdict);
9080c16b537SWarner Losh</b><p>  Reference a prepared dictionary, to be used for all next compression jobs.
9090c16b537SWarner Losh  Note that compression parameters are enforced from within CDict,
9100c16b537SWarner Losh  and supercede any compression parameter previously set within CCtx.
9110c16b537SWarner Losh  The dictionary will remain valid for future compression jobs using same CCtx.
9120c16b537SWarner Losh @result : 0, or an error code (which can be tested with ZSTD_isError()).
9130c16b537SWarner Losh  Special : adding a NULL CDict means "return to no-dictionary mode".
9140c16b537SWarner Losh  Note 1 : Currently, only one dictionary can be managed.
9150c16b537SWarner Losh           Adding a new dictionary effectively "discards" any previous one.
9160c16b537SWarner Losh  Note 2 : CDict is just referenced, its lifetime must outlive CCtx.
9170c16b537SWarner Losh</p></pre><BR>
9180c16b537SWarner Losh
9190c16b537SWarner Losh<pre><b>size_t ZSTD_CCtx_refPrefix(ZSTD_CCtx* cctx, const void* prefix, size_t prefixSize);
920*19fcbaf1SConrad Meyersize_t ZSTD_CCtx_refPrefix_advanced(ZSTD_CCtx* cctx, const void* prefix, size_t prefixSize, ZSTD_dictContentType_e dictContentType);
9210c16b537SWarner Losh</b><p>  Reference a prefix (single-usage dictionary) for next compression job.
9220c16b537SWarner Losh  Decompression need same prefix to properly regenerate data.
9230c16b537SWarner Losh  Prefix is **only used once**. Tables are discarded at end of compression job.
9240c16b537SWarner Losh  Subsequent compression jobs will be done without prefix (if none is explicitly referenced).
9250c16b537SWarner Losh  If there is a need to use same prefix multiple times, consider embedding it into a ZSTD_CDict instead.
9260c16b537SWarner Losh @result : 0, or an error code (which can be tested with ZSTD_isError()).
9270c16b537SWarner Losh  Special: Adding any prefix (including NULL) invalidates any previous prefix or dictionary
9280c16b537SWarner Losh  Note 1 : Prefix buffer is referenced. It must outlive compression job.
9290c16b537SWarner Losh  Note 2 : Referencing a prefix involves building tables, which are dependent on compression parameters.
930*19fcbaf1SConrad Meyer           It's a CPU consuming operation, with non-negligible impact on latency.
931*19fcbaf1SConrad Meyer  Note 3 : By default, the prefix is treated as raw content (ZSTD_dm_rawContent).
932*19fcbaf1SConrad Meyer           Use ZSTD_CCtx_refPrefix_advanced() to alter dictMode.
933*19fcbaf1SConrad Meyer</p></pre><BR>
934*19fcbaf1SConrad Meyer
935*19fcbaf1SConrad Meyer<pre><b>void ZSTD_CCtx_reset(ZSTD_CCtx* cctx);
936*19fcbaf1SConrad Meyer</b><p>  Return a CCtx to clean state.
937*19fcbaf1SConrad Meyer  Useful after an error, or to interrupt an ongoing compression job and start a new one.
938*19fcbaf1SConrad Meyer  Any internal data not yet flushed is cancelled.
939*19fcbaf1SConrad Meyer  Dictionary (if any) is dropped.
940*19fcbaf1SConrad Meyer  All parameters are back to default values.
941*19fcbaf1SConrad Meyer  It's possible to modify compression parameters after a reset.
942*19fcbaf1SConrad Meyer
9430c16b537SWarner Losh</p></pre><BR>
9440c16b537SWarner Losh
9450c16b537SWarner Losh<pre><b>typedef enum {
946*19fcbaf1SConrad Meyer    ZSTD_e_continue=0, </b>/* collect more data, encoder decides when to output compressed result, for optimal conditions */<b>
9470c16b537SWarner Losh    ZSTD_e_flush,      </b>/* flush any data provided so far - frame will continue, future data can still reference previous data for better compression */<b>
9480c16b537SWarner Losh    ZSTD_e_end         </b>/* flush any remaining data and close current frame. Any additional data starts a new frame. */<b>
9490c16b537SWarner Losh} ZSTD_EndDirective;
9500c16b537SWarner Losh</b></pre><BR>
9510c16b537SWarner Losh<pre><b>size_t ZSTD_compress_generic (ZSTD_CCtx* cctx,
9520c16b537SWarner Losh                              ZSTD_outBuffer* output,
9530c16b537SWarner Losh                              ZSTD_inBuffer* input,
9540c16b537SWarner Losh                              ZSTD_EndDirective endOp);
9550c16b537SWarner Losh</b><p>  Behave about the same as ZSTD_compressStream. To note :
9560c16b537SWarner Losh  - Compression parameters are pushed into CCtx before starting compression, using ZSTD_CCtx_setParameter()
9570c16b537SWarner Losh  - Compression parameters cannot be changed once compression is started.
9580c16b537SWarner Losh  - outpot->pos must be <= dstCapacity, input->pos must be <= srcSize
9590c16b537SWarner Losh  - outpot->pos and input->pos will be updated. They are guaranteed to remain below their respective limit.
960052d3c12SConrad Meyer  - In single-thread mode (default), function is blocking : it completed its job before returning to caller.
961052d3c12SConrad Meyer  - In multi-thread mode, function is non-blocking : it just acquires a copy of input, and distribute job to internal worker threads,
962052d3c12SConrad Meyer                                                     and then immediately returns, just indicating that there is some data remaining to be flushed.
963052d3c12SConrad Meyer                                                     The function nonetheless guarantees forward progress : it will return only after it reads or write at least 1+ byte.
964052d3c12SConrad Meyer  - Exception : in multi-threading mode, if the first call requests a ZSTD_e_end directive, it is blocking : it will complete compression before giving back control to caller.
965*19fcbaf1SConrad Meyer  - @return provides a minimum amount of data remaining to be flushed from internal buffers
9660c16b537SWarner Losh            or an error code, which can be tested using ZSTD_isError().
967052d3c12SConrad Meyer            if @return != 0, flush is not fully completed, there is still some data left within internal buffers.
968*19fcbaf1SConrad Meyer            This is useful for ZSTD_e_flush, since in this case more flushes are necessary to empty all buffers.
969*19fcbaf1SConrad Meyer            For ZSTD_e_end, @return == 0 when internal buffers are fully flushed and frame is completed.
970052d3c12SConrad Meyer  - after a ZSTD_e_end directive, if internal buffer is not fully flushed (@return != 0),
9710c16b537SWarner Losh            only ZSTD_e_end or ZSTD_e_flush operations are allowed.
972052d3c12SConrad Meyer            Before starting a new compression job, or changing compression parameters,
973052d3c12SConrad Meyer            it is required to fully flush internal buffers.
9740c16b537SWarner Losh
9750c16b537SWarner Losh</p></pre><BR>
9760c16b537SWarner Losh
9770c16b537SWarner Losh<pre><b>size_t ZSTD_compress_generic_simpleArgs (
9780c16b537SWarner Losh                ZSTD_CCtx* cctx,
9790c16b537SWarner Losh                void* dst, size_t dstCapacity, size_t* dstPos,
9800c16b537SWarner Losh          const void* src, size_t srcSize, size_t* srcPos,
9810c16b537SWarner Losh                ZSTD_EndDirective endOp);
9820c16b537SWarner Losh</b><p>  Same as ZSTD_compress_generic(),
9830c16b537SWarner Losh  but using only integral types as arguments.
9840c16b537SWarner Losh  Argument list is larger than ZSTD_{in,out}Buffer,
9850c16b537SWarner Losh  but can be helpful for binders from dynamic languages
9860c16b537SWarner Losh  which have troubles handling structures containing memory pointers.
9870c16b537SWarner Losh
9880c16b537SWarner Losh</p></pre><BR>
9890c16b537SWarner Losh
9900c16b537SWarner Losh<pre><b>ZSTD_CCtx_params* ZSTD_createCCtxParams(void);
991*19fcbaf1SConrad Meyersize_t ZSTD_freeCCtxParams(ZSTD_CCtx_params* params);
9920c16b537SWarner Losh</b><p>  Quick howto :
9930c16b537SWarner Losh  - ZSTD_createCCtxParams() : Create a ZSTD_CCtx_params structure
9940c16b537SWarner Losh  - ZSTD_CCtxParam_setParameter() : Push parameters one by one into
9950c16b537SWarner Losh                                    an existing ZSTD_CCtx_params structure.
9960c16b537SWarner Losh                                    This is similar to
9970c16b537SWarner Losh                                    ZSTD_CCtx_setParameter().
9980c16b537SWarner Losh  - ZSTD_CCtx_setParametersUsingCCtxParams() : Apply parameters to
9990c16b537SWarner Losh                                    an existing CCtx.
10000c16b537SWarner Losh                                    These parameters will be applied to
10010c16b537SWarner Losh                                    all subsequent compression jobs.
10020c16b537SWarner Losh  - ZSTD_compress_generic() : Do compression using the CCtx.
10030c16b537SWarner Losh  - ZSTD_freeCCtxParams() : Free the memory.
10040c16b537SWarner Losh
10050c16b537SWarner Losh  This can be used with ZSTD_estimateCCtxSize_advanced_usingCCtxParams()
10060c16b537SWarner Losh  for static allocation for single-threaded compression.
10070c16b537SWarner Losh
10080c16b537SWarner Losh</p></pre><BR>
10090c16b537SWarner Losh
1010*19fcbaf1SConrad Meyer<pre><b>size_t ZSTD_CCtxParams_reset(ZSTD_CCtx_params* params);
1011*19fcbaf1SConrad Meyer</b><p>  Reset params to default values.
10120c16b537SWarner Losh
10130c16b537SWarner Losh</p></pre><BR>
10140c16b537SWarner Losh
1015*19fcbaf1SConrad Meyer<pre><b>size_t ZSTD_CCtxParams_init(ZSTD_CCtx_params* cctxParams, int compressionLevel);
10160c16b537SWarner Losh</b><p>  Initializes the compression parameters of cctxParams according to
10170c16b537SWarner Losh  compression level. All other parameters are reset to their default values.
10180c16b537SWarner Losh
10190c16b537SWarner Losh</p></pre><BR>
10200c16b537SWarner Losh
1021*19fcbaf1SConrad Meyer<pre><b>size_t ZSTD_CCtxParams_init_advanced(ZSTD_CCtx_params* cctxParams, ZSTD_parameters params);
10220c16b537SWarner Losh</b><p>  Initializes the compression and frame parameters of cctxParams according to
10230c16b537SWarner Losh  params. All other parameters are reset to their default values.
10240c16b537SWarner Losh
10250c16b537SWarner Losh</p></pre><BR>
10260c16b537SWarner Losh
10270c16b537SWarner Losh<pre><b>size_t ZSTD_CCtxParam_setParameter(ZSTD_CCtx_params* params, ZSTD_cParameter param, unsigned value);
10280c16b537SWarner Losh</b><p>  Similar to ZSTD_CCtx_setParameter.
10290c16b537SWarner Losh  Set one compression parameter, selected by enum ZSTD_cParameter.
10300c16b537SWarner Losh  Parameters must be applied to a ZSTD_CCtx using ZSTD_CCtx_setParametersUsingCCtxParams().
10310c16b537SWarner Losh  Note : when `value` is an enum, cast it to unsigned for proper type checking.
10320c16b537SWarner Losh @result : 0, or an error code (which can be tested with ZSTD_isError()).
10330c16b537SWarner Losh
10340c16b537SWarner Losh</p></pre><BR>
10350c16b537SWarner Losh
10360c16b537SWarner Losh<pre><b>size_t ZSTD_CCtx_setParametersUsingCCtxParams(
10370c16b537SWarner Losh        ZSTD_CCtx* cctx, const ZSTD_CCtx_params* params);
10380c16b537SWarner Losh</b><p>  Apply a set of ZSTD_CCtx_params to the compression context.
1039*19fcbaf1SConrad Meyer  This can be done even after compression is started,
1040*19fcbaf1SConrad Meyer    if nbWorkers==0, this will have no impact until a new compression is started.
1041*19fcbaf1SConrad Meyer    if nbWorkers>=1, new parameters will be picked up at next job,
1042*19fcbaf1SConrad Meyer       with a few restrictions (windowLog, pledgedSrcSize, nbWorkers, jobSize, and overlapLog are not updated).
10430c16b537SWarner Losh
10440c16b537SWarner Losh</p></pre><BR>
10450c16b537SWarner Losh
10460c16b537SWarner Losh<h3>Advanced parameters for decompression API</h3><pre></pre><b><pre></pre></b><BR>
1047*19fcbaf1SConrad Meyer<pre><b>size_t ZSTD_DCtx_loadDictionary(ZSTD_DCtx* dctx, const void* dict, size_t dictSize);
1048*19fcbaf1SConrad Meyersize_t ZSTD_DCtx_loadDictionary_byReference(ZSTD_DCtx* dctx, const void* dict, size_t dictSize);
1049*19fcbaf1SConrad Meyersize_t ZSTD_DCtx_loadDictionary_advanced(ZSTD_DCtx* dctx, const void* dict, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictContentType_e dictContentType);
10500c16b537SWarner Losh</b><p>  Create an internal DDict from dict buffer,
10510c16b537SWarner Losh  to be used to decompress next frames.
10520c16b537SWarner Losh @result : 0, or an error code (which can be tested with ZSTD_isError()).
10530c16b537SWarner Losh  Special : Adding a NULL (or 0-size) dictionary invalidates any previous dictionary,
10540c16b537SWarner Losh            meaning "return to no-dictionary mode".
10550c16b537SWarner Losh  Note 1 : `dict` content will be copied internally.
10560c16b537SWarner Losh            Use ZSTD_DCtx_loadDictionary_byReference()
10570c16b537SWarner Losh            to reference dictionary content instead.
10580c16b537SWarner Losh            In which case, the dictionary buffer must outlive its users.
10590c16b537SWarner Losh  Note 2 : Loading a dictionary involves building tables,
10600c16b537SWarner Losh           which has a non-negligible impact on CPU usage and latency.
10610c16b537SWarner Losh  Note 3 : Use ZSTD_DCtx_loadDictionary_advanced() to select
10620c16b537SWarner Losh           how dictionary content will be interpreted and loaded.
10630c16b537SWarner Losh
10640c16b537SWarner Losh</p></pre><BR>
10650c16b537SWarner Losh
1066*19fcbaf1SConrad Meyer<pre><b>size_t ZSTD_DCtx_refDDict(ZSTD_DCtx* dctx, const ZSTD_DDict* ddict);
10670c16b537SWarner Losh</b><p>  Reference a prepared dictionary, to be used to decompress next frames.
10680c16b537SWarner Losh  The dictionary remains active for decompression of future frames using same DCtx.
10690c16b537SWarner Losh @result : 0, or an error code (which can be tested with ZSTD_isError()).
10700c16b537SWarner Losh  Note 1 : Currently, only one dictionary can be managed.
10710c16b537SWarner Losh           Referencing a new dictionary effectively "discards" any previous one.
10720c16b537SWarner Losh  Special : adding a NULL DDict means "return to no-dictionary mode".
10730c16b537SWarner Losh  Note 2 : DDict is just referenced, its lifetime must outlive its usage from DCtx.
10740c16b537SWarner Losh
10750c16b537SWarner Losh</p></pre><BR>
10760c16b537SWarner Losh
1077*19fcbaf1SConrad Meyer<pre><b>size_t ZSTD_DCtx_refPrefix(ZSTD_DCtx* dctx, const void* prefix, size_t prefixSize);
1078*19fcbaf1SConrad Meyersize_t ZSTD_DCtx_refPrefix_advanced(ZSTD_DCtx* dctx, const void* prefix, size_t prefixSize, ZSTD_dictContentType_e dictContentType);
10790c16b537SWarner Losh</b><p>  Reference a prefix (single-usage dictionary) for next compression job.
10800c16b537SWarner Losh  Prefix is **only used once**. It must be explicitly referenced before each frame.
10810c16b537SWarner Losh  If there is a need to use same prefix multiple times, consider embedding it into a ZSTD_DDict instead.
10820c16b537SWarner Losh @result : 0, or an error code (which can be tested with ZSTD_isError()).
10830c16b537SWarner Losh  Note 1 : Adding any prefix (including NULL) invalidates any previously set prefix or dictionary
10840c16b537SWarner Losh  Note 2 : Prefix buffer is referenced. It must outlive compression job.
10850c16b537SWarner Losh  Note 3 : By default, the prefix is treated as raw content (ZSTD_dm_rawContent).
10860c16b537SWarner Losh           Use ZSTD_CCtx_refPrefix_advanced() to alter dictMode.
10870c16b537SWarner Losh  Note 4 : Referencing a raw content prefix has almost no cpu nor memory cost.
10880c16b537SWarner Losh
10890c16b537SWarner Losh</p></pre><BR>
10900c16b537SWarner Losh
10910c16b537SWarner Losh<pre><b>size_t ZSTD_DCtx_setMaxWindowSize(ZSTD_DCtx* dctx, size_t maxWindowSize);
10920c16b537SWarner Losh</b><p>  Refuses allocating internal buffers for frames requiring a window size larger than provided limit.
10930c16b537SWarner Losh  This is useful to prevent a decoder context from reserving too much memory for itself (potential attack scenario).
10940c16b537SWarner Losh  This parameter is only useful in streaming mode, since no internal buffer is allocated in direct mode.
10950c16b537SWarner Losh  By default, a decompression context accepts all window sizes <= (1 << ZSTD_WINDOWLOG_MAX)
10960c16b537SWarner Losh @return : 0, or an error code (which can be tested using ZSTD_isError()).
10970c16b537SWarner Losh
10980c16b537SWarner Losh</p></pre><BR>
10990c16b537SWarner Losh
11000c16b537SWarner Losh<pre><b>size_t ZSTD_DCtx_setFormat(ZSTD_DCtx* dctx, ZSTD_format_e format);
11010c16b537SWarner Losh</b><p>  Instruct the decoder context about what kind of data to decode next.
11020c16b537SWarner Losh  This instruction is mandatory to decode data without a fully-formed header,
11030c16b537SWarner Losh  such ZSTD_f_zstd1_magicless for example.
11040c16b537SWarner Losh @return : 0, or an error code (which can be tested using ZSTD_isError()).
11050c16b537SWarner Losh
11060c16b537SWarner Losh</p></pre><BR>
11070c16b537SWarner Losh
11080c16b537SWarner Losh<pre><b>size_t ZSTD_decompress_generic(ZSTD_DCtx* dctx,
11090c16b537SWarner Losh                               ZSTD_outBuffer* output,
11100c16b537SWarner Losh                               ZSTD_inBuffer* input);
11110c16b537SWarner Losh</b><p>  Behave the same as ZSTD_decompressStream.
11120c16b537SWarner Losh  Decompression parameters cannot be changed once decompression is started.
11130c16b537SWarner Losh @return : an error code, which can be tested using ZSTD_isError()
11140c16b537SWarner Losh           if >0, a hint, nb of expected input bytes for next invocation.
11150c16b537SWarner Losh           `0` means : a frame has just been fully decoded and flushed.
11160c16b537SWarner Losh
11170c16b537SWarner Losh</p></pre><BR>
11180c16b537SWarner Losh
11190c16b537SWarner Losh<pre><b>size_t ZSTD_decompress_generic_simpleArgs (
11200c16b537SWarner Losh                ZSTD_DCtx* dctx,
11210c16b537SWarner Losh                void* dst, size_t dstCapacity, size_t* dstPos,
11220c16b537SWarner Losh          const void* src, size_t srcSize, size_t* srcPos);
11230c16b537SWarner Losh</b><p>  Same as ZSTD_decompress_generic(),
11240c16b537SWarner Losh  but using only integral types as arguments.
11250c16b537SWarner Losh  Argument list is larger than ZSTD_{in,out}Buffer,
11260c16b537SWarner Losh  but can be helpful for binders from dynamic languages
11270c16b537SWarner Losh  which have troubles handling structures containing memory pointers.
11280c16b537SWarner Losh
11290c16b537SWarner Losh</p></pre><BR>
11300c16b537SWarner Losh
11310c16b537SWarner Losh<pre><b>void ZSTD_DCtx_reset(ZSTD_DCtx* dctx);
11320c16b537SWarner Losh</b><p>  Return a DCtx to clean state.
11330c16b537SWarner Losh  If a decompression was ongoing, any internal data not yet flushed is cancelled.
11340c16b537SWarner Losh  All parameters are back to default values, including sticky ones.
11350c16b537SWarner Losh  Dictionary (if any) is dropped.
11360c16b537SWarner Losh  Parameters can be modified again after a reset.
11370c16b537SWarner Losh
11380c16b537SWarner Losh</p></pre><BR>
11390c16b537SWarner Losh
1140*19fcbaf1SConrad Meyer<a name="Chapter21"></a><h2>Block level API</h2><pre></pre>
11410c16b537SWarner Losh
11420c16b537SWarner Losh<pre><b></b><p>    Frame metadata cost is typically ~18 bytes, which can be non-negligible for very small blocks (< 100 bytes).
11430c16b537SWarner Losh    User will have to take in charge required information to regenerate data, such as compressed and content sizes.
11440c16b537SWarner Losh
11450c16b537SWarner Losh    A few rules to respect :
11460c16b537SWarner Losh    - Compressing and decompressing require a context structure
11470c16b537SWarner Losh      + Use ZSTD_createCCtx() and ZSTD_createDCtx()
11480c16b537SWarner Losh    - It is necessary to init context before starting
11490c16b537SWarner Losh      + compression : any ZSTD_compressBegin*() variant, including with dictionary
11500c16b537SWarner Losh      + decompression : any ZSTD_decompressBegin*() variant, including with dictionary
11510c16b537SWarner Losh      + copyCCtx() and copyDCtx() can be used too
11520c16b537SWarner Losh    - Block size is limited, it must be <= ZSTD_getBlockSize() <= ZSTD_BLOCKSIZE_MAX == 128 KB
11530c16b537SWarner Losh      + If input is larger than a block size, it's necessary to split input data into multiple blocks
11540c16b537SWarner Losh      + For inputs larger than a single block size, consider using the regular ZSTD_compress() instead.
11550c16b537SWarner Losh        Frame metadata is not that costly, and quickly becomes negligible as source size grows larger.
11560c16b537SWarner Losh    - When a block is considered not compressible enough, ZSTD_compressBlock() result will be zero.
11570c16b537SWarner Losh      In which case, nothing is produced into `dst`.
11580c16b537SWarner Losh      + User must test for such outcome and deal directly with uncompressed data
11590c16b537SWarner Losh      + ZSTD_decompressBlock() doesn't accept uncompressed data as input !!!
11600c16b537SWarner Losh      + In case of multiple successive blocks, should some of them be uncompressed,
11610c16b537SWarner Losh        decoder must be informed of their existence in order to follow proper history.
11620c16b537SWarner Losh        Use ZSTD_insertBlock() for such a case.
11630c16b537SWarner Losh</p></pre><BR>
11640c16b537SWarner Losh
11650c16b537SWarner Losh<h3>Raw zstd block functions</h3><pre></pre><b><pre>size_t ZSTD_getBlockSize   (const ZSTD_CCtx* cctx);
11660c16b537SWarner Loshsize_t ZSTD_compressBlock  (ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize);
11670c16b537SWarner Loshsize_t ZSTD_decompressBlock(ZSTD_DCtx* dctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize);
1168*19fcbaf1SConrad Meyersize_t ZSTD_insertBlock    (ZSTD_DCtx* dctx, const void* blockStart, size_t blockSize);  </b>/**< insert uncompressed block into `dctx` history. Useful for multi-blocks decompression. */<b>
11690c16b537SWarner Losh</pre></b><BR>
11700c16b537SWarner Losh</html>
11710c16b537SWarner Losh</body>
1172