• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
4<title>zstd 1.5.7 Manual</title>
5</head>
6<body>
7<h1>zstd 1.5.7 Manual</h1>
8Note: the content of this file has been automatically generated by parsing "zstd.h"
9<hr>
10<a name="Contents"></a><h2>Contents</h2>
11<ol>
12<li><a href="#Chapter1">Introduction</a></li>
13<li><a href="#Chapter2">Version</a></li>
14<li><a href="#Chapter3">Simple Core API</a></li>
15<li><a href="#Chapter4">Explicit context</a></li>
16<li><a href="#Chapter5">Advanced compression API (Requires v1.4.0+)</a></li>
17<li><a href="#Chapter6">Advanced decompression API (Requires v1.4.0+)</a></li>
18<li><a href="#Chapter7">Streaming</a></li>
19<li><a href="#Chapter8">Streaming compression - HowTo</a></li>
20<li><a href="#Chapter9">Streaming decompression - HowTo</a></li>
21<li><a href="#Chapter10">Simple dictionary API</a></li>
22<li><a href="#Chapter11">Bulk processing dictionary API</a></li>
23<li><a href="#Chapter12">Dictionary helper functions</a></li>
24<li><a href="#Chapter13">Advanced dictionary and prefix API (Requires v1.4.0+)</a></li>
25<li><a href="#Chapter14">experimental API (static linking only)</a></li>
26<li><a href="#Chapter15">Frame header and size functions</a></li>
27<li><a href="#Chapter16">Memory management</a></li>
28<li><a href="#Chapter17">Advanced compression functions</a></li>
29<li><a href="#Chapter18">Advanced decompression functions</a></li>
30<li><a href="#Chapter19">Advanced streaming functions</a></li>
31<li><a href="#Chapter20">Buffer-less and synchronous inner streaming functions (DEPRECATED)</a></li>
32<li><a href="#Chapter21">Buffer-less streaming compression (synchronous mode)</a></li>
33<li><a href="#Chapter22">Buffer-less streaming decompression (synchronous mode)</a></li>
34<li><a href="#Chapter23">Block level API (DEPRECATED)</a></li>
35</ol>
36<hr>
37<a name="Chapter1"></a><h2>Introduction</h2><pre>
38  zstd, short for Zstandard, is a fast lossless compression algorithm, targeting
39  real-time compression scenarios at zlib-level and better compression ratios.
40  The zstd compression library provides in-memory compression and decompression
41  functions.
42
43  The library supports regular compression levels from 1 up to ZSTD_maxCLevel(),
44  which is currently 22. Levels >= 20, labeled `--ultra`, should be used with
45  caution, as they require more memory. The library also offers negative
46  compression levels, which extend the range of speed vs. ratio preferences.
47  The lower the level, the faster the speed (at the cost of compression).
48
49  Compression can be done in:
50    - a single step (described as Simple API)
51    - a single step, reusing a context (described as Explicit context)
52    - unbounded multiple steps (described as Streaming compression)
53
54  The compression ratio achievable on small data can be highly improved using
55  a dictionary. Dictionary compression can be performed in:
56    - a single step (described as Simple dictionary API)
57    - a single step, reusing a dictionary (described as Bulk-processing
58      dictionary API)
59
60  Advanced experimental functions can be accessed using
61  `#define ZSTD_STATIC_LINKING_ONLY` before including zstd.h.
62
63  Advanced experimental APIs should never be used with a dynamically-linked
64  library. They are not "stable"; their definitions or signatures may change in
65  the future. Only static linking is allowed.
66<BR></pre>
67
68<a name="Chapter2"></a><h2>Version</h2><pre></pre>
69
70<pre><b>unsigned ZSTD_versionNumber(void);
71</b><p>  Return runtime library version, the value is (MAJOR*100*100 + MINOR*100 + RELEASE).
72</p></pre><BR>
73
74<pre><b>const char* ZSTD_versionString(void);
75</b><p>  Return runtime library version, like "1.4.5". Requires v1.3.0+.
76</p></pre><BR>
77
78<a name="Chapter3"></a><h2>Simple Core API</h2><pre></pre>
79
80<pre><b>size_t ZSTD_compress( void* dst, size_t dstCapacity,
81                const void* src, size_t srcSize,
82                      int compressionLevel);
83</b><p>  Compresses `src` content as a single zstd compressed frame into already allocated `dst`.
84  NOTE: Providing `dstCapacity >= ZSTD_compressBound(srcSize)` guarantees that zstd will have
85        enough space to successfully compress the data.
86  @return : compressed size written into `dst` (<= `dstCapacity),
87            or an error code if it fails (which can be tested using ZSTD_isError()).
88</p></pre><BR>
89
90<pre><b>size_t ZSTD_decompress( void* dst, size_t dstCapacity,
91                  const void* src, size_t compressedSize);
92</b><p> `compressedSize` : must be the _exact_ size of some number of compressed and/or skippable frames.
93  Multiple compressed frames can be decompressed at once with this method.
94  The result will be the concatenation of all decompressed frames, back to back.
95 `dstCapacity` is an upper bound of originalSize to regenerate.
96  First frame's decompressed size can be extracted using ZSTD_getFrameContentSize().
97  If maximum upper bound isn't known, prefer using streaming mode to decompress data.
98 @return : the number of bytes decompressed into `dst` (<= `dstCapacity`),
99           or an errorCode if it fails (which can be tested using ZSTD_isError()).
100</p></pre><BR>
101
102<h3>Decompression helper functions</h3><pre></pre><b><pre></pre></b><BR>
103<pre><b>#define ZSTD_CONTENTSIZE_UNKNOWN (0ULL - 1)
104#define ZSTD_CONTENTSIZE_ERROR   (0ULL - 2)
105unsigned long long ZSTD_getFrameContentSize(const void *src, size_t srcSize);
106</b><p> `src` should point to the start of a ZSTD encoded frame.
107 `srcSize` must be at least as large as the frame header.
108           hint : any size >= `ZSTD_frameHeaderSize_max` is large enough.
109 @return : - decompressed size of `src` frame content, if known
110           - ZSTD_CONTENTSIZE_UNKNOWN if the size cannot be determined
111           - ZSTD_CONTENTSIZE_ERROR if an error occurred (e.g. invalid magic number, srcSize too small)
112  note 1 : a 0 return value means the frame is valid but "empty".
113  note 2 : decompressed size is an optional field, it may not be present (typically in streaming mode).
114           When `return==ZSTD_CONTENTSIZE_UNKNOWN`, data to decompress could be any size.
115           In which case, it's necessary to use streaming mode to decompress data.
116           Optionally, application can rely on some implicit limit,
117           as ZSTD_decompress() only needs an upper bound of decompressed size.
118           (For example, data could be necessarily cut into blocks <= 16 KB).
119  note 3 : decompressed size is always present when compression is completed using single-pass functions,
120           such as ZSTD_compress(), ZSTD_compressCCtx() ZSTD_compress_usingDict() or ZSTD_compress_usingCDict().
121  note 4 : decompressed size can be very large (64-bits value),
122           potentially larger than what local system can handle as a single memory segment.
123           In which case, it's necessary to use streaming mode to decompress data.
124  note 5 : If source is untrusted, decompressed size could be wrong or intentionally modified.
125           Always ensure return value fits within application's authorized limits.
126           Each application can set its own limits.
127  note 6 : This function replaces ZSTD_getDecompressedSize()
128</p></pre><BR>
129
130<pre><b>ZSTD_DEPRECATED("Replaced by ZSTD_getFrameContentSize")
131ZSTDLIB_API
132unsigned long long ZSTD_getDecompressedSize(const void* src, size_t srcSize);
133</b><p>  NOTE: This function is now obsolete, in favor of ZSTD_getFrameContentSize().
134  Both functions work the same way, but ZSTD_getDecompressedSize() blends
135  "empty", "unknown" and "error" results to the same return value (0),
136  while ZSTD_getFrameContentSize() gives them separate return values.
137 @return : decompressed size of `src` frame content _if known and not empty_, 0 otherwise.
138</p></pre><BR>
139
140<pre><b>size_t ZSTD_findFrameCompressedSize(const void* src, size_t srcSize);
141</b><p> `src` should point to the start of a ZSTD frame or skippable frame.
142 `srcSize` must be >= first frame size
143 @return : the compressed size of the first frame starting at `src`,
144           suitable to pass as `srcSize` to `ZSTD_decompress` or similar,
145        or an error code if input is invalid
146</p></pre><BR>
147
148<h3>Compression helper functions</h3><pre></pre><b><pre></pre></b><BR>
149<pre><b>#define ZSTD_MAX_INPUT_SIZE ((sizeof(size_t)==8) ? 0xFF00FF00FF00FF00ULL : 0xFF00FF00U)
150#define ZSTD_COMPRESSBOUND(srcSize)   (((size_t)(srcSize) >= ZSTD_MAX_INPUT_SIZE) ? 0 : (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>
151size_t ZSTD_compressBound(size_t srcSize); </b>/*!< maximum compressed size in worst case single-pass scenario */<b>
152</b><p> maximum compressed size in worst case single-pass scenario.
153 When invoking `ZSTD_compress()`, or any other one-pass compression function,
154 it's recommended to provide @dstCapacity >= ZSTD_compressBound(srcSize)
155 as it eliminates one potential failure scenario,
156 aka not enough room in dst buffer to write the compressed frame.
157 Note : ZSTD_compressBound() itself can fail, if @srcSize >= ZSTD_MAX_INPUT_SIZE .
158        In which case, ZSTD_compressBound() will return an error code
159        which can be tested using ZSTD_isError().
160
161 ZSTD_COMPRESSBOUND() :
162 same as ZSTD_compressBound(), but as a macro.
163 It can be used to produce constants, which can be useful for static allocation,
164 for example to size a static array on stack.
165 Will produce constant value 0 if srcSize is too large.
166
167</p></pre><BR>
168
169<h3>Error helper functions</h3><pre></pre><b><pre>#include "zstd_errors.h" </b>/* list of errors */<b>
170</b>/* ZSTD_isError() :<b>
171 * Most ZSTD_* functions returning a size_t value can be tested for error,
172 * using ZSTD_isError().
173 * @return 1 if error, 0 otherwise
174 */
175unsigned     ZSTD_isError(size_t result);      </b>/*!< tells if a `size_t` function result is an error code */<b>
176ZSTD_ErrorCode ZSTD_getErrorCode(size_t functionResult); </b>/* convert a result into an error code, which can be compared to error enum list */<b>
177const char*  ZSTD_getErrorName(size_t result); </b>/*!< provides readable string from a function result */<b>
178int          ZSTD_minCLevel(void);             </b>/*!< minimum negative compression level allowed, requires v1.4.0+ */<b>
179int          ZSTD_maxCLevel(void);             </b>/*!< maximum compression level available */<b>
180int          ZSTD_defaultCLevel(void);         </b>/*!< default compression level, specified by ZSTD_CLEVEL_DEFAULT, requires v1.5.0+ */<b>
181</pre></b><BR>
182<a name="Chapter4"></a><h2>Explicit context</h2><pre></pre>
183
184<h3>Compression context</h3><pre>  When compressing many times,
185  it is recommended to allocate a compression context just once,
186  and reuse it for each successive compression operation.
187  This will make the workload easier for system's memory.
188  Note : re-using context is just a speed / resource optimization.
189         It doesn't change the compression ratio, which remains identical.
190  Note 2: For parallel execution in multi-threaded environments,
191         use one different context per thread .
192
193</pre><b><pre>typedef struct ZSTD_CCtx_s ZSTD_CCtx;
194ZSTD_CCtx* ZSTD_createCCtx(void);
195size_t     ZSTD_freeCCtx(ZSTD_CCtx* cctx);  </b>/* compatible with NULL pointer */<b>
196</pre></b><BR>
197<pre><b>size_t ZSTD_compressCCtx(ZSTD_CCtx* cctx,
198                         void* dst, size_t dstCapacity,
199                   const void* src, size_t srcSize,
200                         int compressionLevel);
201</b><p>  Same as ZSTD_compress(), using an explicit ZSTD_CCtx.
202  Important : in order to mirror `ZSTD_compress()` behavior,
203  this function compresses at the requested compression level,
204  __ignoring any other advanced parameter__ .
205  If any advanced parameter was set using the advanced API,
206  they will all be reset. Only @compressionLevel remains.
207
208</p></pre><BR>
209
210<h3>Decompression context</h3><pre>  When decompressing many times,
211  it is recommended to allocate a context only once,
212  and reuse it for each successive compression operation.
213  This will make workload friendlier for system's memory.
214  Use one context per thread for parallel execution.
215</pre><b><pre>typedef struct ZSTD_DCtx_s ZSTD_DCtx;
216ZSTD_DCtx* ZSTD_createDCtx(void);
217size_t     ZSTD_freeDCtx(ZSTD_DCtx* dctx);  </b>/* accept NULL pointer */<b>
218</pre></b><BR>
219<pre><b>size_t ZSTD_decompressDCtx(ZSTD_DCtx* dctx,
220                           void* dst, size_t dstCapacity,
221                     const void* src, size_t srcSize);
222</b><p>  Same as ZSTD_decompress(),
223  requires an allocated ZSTD_DCtx.
224  Compatible with sticky parameters (see below).
225
226</p></pre><BR>
227
228<a name="Chapter5"></a><h2>Advanced compression API (Requires v1.4.0+)</h2><pre></pre>
229
230<pre><b>typedef enum { ZSTD_fast=1,
231               ZSTD_dfast=2,
232               ZSTD_greedy=3,
233               ZSTD_lazy=4,
234               ZSTD_lazy2=5,
235               ZSTD_btlazy2=6,
236               ZSTD_btopt=7,
237               ZSTD_btultra=8,
238               ZSTD_btultra2=9
239               </b>/* note : new strategies _might_ be added in the future.<b>
240                         Only the order (from fast to strong) is guaranteed */
241} ZSTD_strategy;
242</b></pre><BR>
243<pre><b>typedef enum {
244
245    </b>/* compression parameters<b>
246     * Note: When compressing with a ZSTD_CDict these parameters are superseded
247     * by the parameters used to construct the ZSTD_CDict.
248     * See ZSTD_CCtx_refCDict() for more info (superseded-by-cdict). */
249    ZSTD_c_compressionLevel=100, </b>/* Set compression parameters according to pre-defined cLevel table.<b>
250                              * Note that exact compression parameters are dynamically determined,
251                              * depending on both compression level and srcSize (when known).
252                              * Default level is ZSTD_CLEVEL_DEFAULT==3.
253                              * Special: value 0 means default, which is controlled by ZSTD_CLEVEL_DEFAULT.
254                              * Note 1 : it's possible to pass a negative compression level.
255                              * Note 2 : setting a level does not automatically set all other compression parameters
256                              *   to default. Setting this will however eventually dynamically impact the compression
257                              *   parameters which have not been manually set. The manually set
258                              *   ones will 'stick'. */
259    </b>/* Advanced compression parameters :<b>
260     * It's possible to pin down compression parameters to some specific values.
261     * In which case, these values are no longer dynamically selected by the compressor */
262    ZSTD_c_windowLog=101,    </b>/* Maximum allowed back-reference distance, expressed as power of 2.<b>
263                              * This will set a memory budget for streaming decompression,
264                              * with larger values requiring more memory
265                              * and typically compressing more.
266                              * Must be clamped between ZSTD_WINDOWLOG_MIN and ZSTD_WINDOWLOG_MAX.
267                              * Special: value 0 means "use default windowLog".
268                              * Note: Using a windowLog greater than ZSTD_WINDOWLOG_LIMIT_DEFAULT
269                              *       requires explicitly allowing such size at streaming decompression stage. */
270    ZSTD_c_hashLog=102,      </b>/* Size of the initial probe table, as a power of 2.<b>
271                              * Resulting memory usage is (1 << (hashLog+2)).
272                              * Must be clamped between ZSTD_HASHLOG_MIN and ZSTD_HASHLOG_MAX.
273                              * Larger tables improve compression ratio of strategies <= dFast,
274                              * and improve speed of strategies > dFast.
275                              * Special: value 0 means "use default hashLog". */
276    ZSTD_c_chainLog=103,     </b>/* Size of the multi-probe search table, as a power of 2.<b>
277                              * Resulting memory usage is (1 << (chainLog+2)).
278                              * Must be clamped between ZSTD_CHAINLOG_MIN and ZSTD_CHAINLOG_MAX.
279                              * Larger tables result in better and slower compression.
280                              * This parameter is useless for "fast" strategy.
281                              * It's still useful when using "dfast" strategy,
282                              * in which case it defines a secondary probe table.
283                              * Special: value 0 means "use default chainLog". */
284    ZSTD_c_searchLog=104,    </b>/* Number of search attempts, as a power of 2.<b>
285                              * More attempts result in better and slower compression.
286                              * This parameter is useless for "fast" and "dFast" strategies.
287                              * Special: value 0 means "use default searchLog". */
288    ZSTD_c_minMatch=105,     </b>/* Minimum size of searched matches.<b>
289                              * Note that Zstandard can still find matches of smaller size,
290                              * it just tweaks its search algorithm to look for this size and larger.
291                              * Larger values increase compression and decompression speed, but decrease ratio.
292                              * Must be clamped between ZSTD_MINMATCH_MIN and ZSTD_MINMATCH_MAX.
293                              * Note that currently, for all strategies < btopt, effective minimum is 4.
294                              *                    , for all strategies > fast, effective maximum is 6.
295                              * Special: value 0 means "use default minMatchLength". */
296    ZSTD_c_targetLength=106, </b>/* Impact of this field depends on strategy.<b>
297                              * For strategies btopt, btultra & btultra2:
298                              *     Length of Match considered "good enough" to stop search.
299                              *     Larger values make compression stronger, and slower.
300                              * For strategy fast:
301                              *     Distance between match sampling.
302                              *     Larger values make compression faster, and weaker.
303                              * Special: value 0 means "use default targetLength". */
304    ZSTD_c_strategy=107,     </b>/* See ZSTD_strategy enum definition.<b>
305                              * The higher the value of selected strategy, the more complex it is,
306                              * resulting in stronger and slower compression.
307                              * Special: value 0 means "use default strategy". */
308
309    ZSTD_c_targetCBlockSize=130, </b>/* v1.5.6+<b>
310                                  * Attempts to fit compressed block size into approximately targetCBlockSize.
311                                  * Bound by ZSTD_TARGETCBLOCKSIZE_MIN and ZSTD_TARGETCBLOCKSIZE_MAX.
312                                  * Note that it's not a guarantee, just a convergence target (default:0).
313                                  * No target when targetCBlockSize == 0.
314                                  * This is helpful in low bandwidth streaming environments to improve end-to-end latency,
315                                  * when a client can make use of partial documents (a prominent example being Chrome).
316                                  * Note: this parameter is stable since v1.5.6.
317                                  * It was present as an experimental parameter in earlier versions,
318                                  * but it's not recommended using it with earlier library versions
319                                  * due to massive performance regressions.
320                                  */
321    </b>/* LDM mode parameters */<b>
322    ZSTD_c_enableLongDistanceMatching=160, </b>/* Enable long distance matching.<b>
323                                     * This parameter is designed to improve compression ratio
324                                     * for large inputs, by finding large matches at long distance.
325                                     * It increases memory usage and window size.
326                                     * Note: enabling this parameter increases default ZSTD_c_windowLog to 128 MB
327                                     * except when expressly set to a different value.
328                                     * Note: will be enabled by default if ZSTD_c_windowLog >= 128 MB and
329                                     * compression strategy >= ZSTD_btopt (== compression level 16+) */
330    ZSTD_c_ldmHashLog=161,   </b>/* Size of the table for long distance matching, as a power of 2.<b>
331                              * Larger values increase memory usage and compression ratio,
332                              * but decrease compression speed.
333                              * Must be clamped between ZSTD_HASHLOG_MIN and ZSTD_HASHLOG_MAX
334                              * default: windowlog - 7.
335                              * Special: value 0 means "automatically determine hashlog". */
336    ZSTD_c_ldmMinMatch=162,  </b>/* Minimum match size for long distance matcher.<b>
337                              * Larger/too small values usually decrease compression ratio.
338                              * Must be clamped between ZSTD_LDM_MINMATCH_MIN and ZSTD_LDM_MINMATCH_MAX.
339                              * Special: value 0 means "use default value" (default: 64). */
340    ZSTD_c_ldmBucketSizeLog=163, </b>/* Log size of each bucket in the LDM hash table for collision resolution.<b>
341                              * Larger values improve collision resolution but decrease compression speed.
342                              * The maximum value is ZSTD_LDM_BUCKETSIZELOG_MAX.
343                              * Special: value 0 means "use default value" (default: 3). */
344    ZSTD_c_ldmHashRateLog=164, </b>/* Frequency of inserting/looking up entries into the LDM hash table.<b>
345                              * Must be clamped between 0 and (ZSTD_WINDOWLOG_MAX - ZSTD_HASHLOG_MIN).
346                              * Default is MAX(0, (windowLog - ldmHashLog)), optimizing hash table usage.
347                              * Larger values improve compression speed.
348                              * Deviating far from default value will likely result in a compression ratio decrease.
349                              * Special: value 0 means "automatically determine hashRateLog". */
350
351    </b>/* frame parameters */<b>
352    ZSTD_c_contentSizeFlag=200, </b>/* Content size will be written into frame header _whenever known_ (default:1)<b>
353                              * Content size must be known at the beginning of compression.
354                              * This is automatically the case when using ZSTD_compress2(),
355                              * For streaming scenarios, content size must be provided with ZSTD_CCtx_setPledgedSrcSize() */
356    ZSTD_c_checksumFlag=201, </b>/* A 32-bits checksum of content is written at end of frame (default:0) */<b>
357    ZSTD_c_dictIDFlag=202,   </b>/* When applicable, dictionary's ID is written into frame header (default:1) */<b>
358
359    </b>/* multi-threading parameters */<b>
360    </b>/* These parameters are only active if multi-threading is enabled (compiled with build macro ZSTD_MULTITHREAD).<b>
361     * Otherwise, trying to set any other value than default (0) will be a no-op and return an error.
362     * In a situation where it's unknown if the linked library supports multi-threading or not,
363     * setting ZSTD_c_nbWorkers to any value >= 1 and consulting the return value provides a quick way to check this property.
364     */
365    ZSTD_c_nbWorkers=400,    </b>/* Select how many threads will be spawned to compress in parallel.<b>
366                              * When nbWorkers >= 1, triggers asynchronous mode when invoking ZSTD_compressStream*() :
367                              * ZSTD_compressStream*() consumes input and flush output if possible, but immediately gives back control to caller,
368                              * while compression is performed in parallel, within worker thread(s).
369                              * (note : a strong exception to this rule is when first invocation of ZSTD_compressStream2() sets ZSTD_e_end :
370                              *  in which case, ZSTD_compressStream2() delegates to ZSTD_compress2(), which is always a blocking call).
371                              * More workers improve speed, but also increase memory usage.
372                              * Default value is `0`, aka "single-threaded mode" : no worker is spawned,
373                              * compression is performed inside Caller's thread, and all invocations are blocking */
374    ZSTD_c_jobSize=401,      </b>/* Size of a compression job. This value is enforced only when nbWorkers >= 1.<b>
375                              * Each compression job is completed in parallel, so this value can indirectly impact the nb of active threads.
376                              * 0 means default, which is dynamically determined based on compression parameters.
377                              * Job size must be a minimum of overlap size, or ZSTDMT_JOBSIZE_MIN (= 512 KB), whichever is largest.
378                              * The minimum size is automatically and transparently enforced. */
379    ZSTD_c_overlapLog=402,   </b>/* Control the overlap size, as a fraction of window size.<b>
380                              * The overlap size is an amount of data reloaded from previous job at the beginning of a new job.
381                              * It helps preserve compression ratio, while each job is compressed in parallel.
382                              * This value is enforced only when nbWorkers >= 1.
383                              * Larger values increase compression ratio, but decrease speed.
384                              * Possible values range from 0 to 9 :
385                              * - 0 means "default" : value will be determined by the library, depending on strategy
386                              * - 1 means "no overlap"
387                              * - 9 means "full overlap", using a full window size.
388                              * Each intermediate rank increases/decreases load size by a factor 2 :
389                              * 9: full window;  8: w/2;  7: w/4;  6: w/8;  5:w/16;  4: w/32;  3:w/64;  2:w/128;  1:no overlap;  0:default
390                              * default value varies between 6 and 9, depending on strategy */
391
392    </b>/* note : additional experimental parameters are also available<b>
393     * within the experimental section of the API.
394     * At the time of this writing, they include :
395     * ZSTD_c_rsyncable
396     * ZSTD_c_format
397     * ZSTD_c_forceMaxWindow
398     * ZSTD_c_forceAttachDict
399     * ZSTD_c_literalCompressionMode
400     * ZSTD_c_srcSizeHint
401     * ZSTD_c_enableDedicatedDictSearch
402     * ZSTD_c_stableInBuffer
403     * ZSTD_c_stableOutBuffer
404     * ZSTD_c_blockDelimiters
405     * ZSTD_c_validateSequences
406     * ZSTD_c_blockSplitterLevel
407     * ZSTD_c_splitAfterSequences
408     * ZSTD_c_useRowMatchFinder
409     * ZSTD_c_prefetchCDictTables
410     * ZSTD_c_enableSeqProducerFallback
411     * ZSTD_c_maxBlockSize
412     * Because they are not stable, it's necessary to define ZSTD_STATIC_LINKING_ONLY to access them.
413     * note : never ever use experimentalParam? names directly;
414     *        also, the enums values themselves are unstable and can still change.
415     */
416     ZSTD_c_experimentalParam1=500,
417     ZSTD_c_experimentalParam2=10,
418     ZSTD_c_experimentalParam3=1000,
419     ZSTD_c_experimentalParam4=1001,
420     ZSTD_c_experimentalParam5=1002,
421     </b>/* was ZSTD_c_experimentalParam6=1003; is now ZSTD_c_targetCBlockSize */<b>
422     ZSTD_c_experimentalParam7=1004,
423     ZSTD_c_experimentalParam8=1005,
424     ZSTD_c_experimentalParam9=1006,
425     ZSTD_c_experimentalParam10=1007,
426     ZSTD_c_experimentalParam11=1008,
427     ZSTD_c_experimentalParam12=1009,
428     ZSTD_c_experimentalParam13=1010,
429     ZSTD_c_experimentalParam14=1011,
430     ZSTD_c_experimentalParam15=1012,
431     ZSTD_c_experimentalParam16=1013,
432     ZSTD_c_experimentalParam17=1014,
433     ZSTD_c_experimentalParam18=1015,
434     ZSTD_c_experimentalParam19=1016,
435     ZSTD_c_experimentalParam20=1017
436} ZSTD_cParameter;
437</b></pre><BR>
438<pre><b>typedef struct {
439    size_t error;
440    int lowerBound;
441    int upperBound;
442} ZSTD_bounds;
443</b></pre><BR>
444<pre><b>ZSTD_bounds ZSTD_cParam_getBounds(ZSTD_cParameter cParam);
445</b><p>  All parameters must belong to an interval with lower and upper bounds,
446  otherwise they will either trigger an error or be automatically clamped.
447 @return : a structure, ZSTD_bounds, which contains
448         - an error status field, which must be tested using ZSTD_isError()
449         - lower and upper bounds, both inclusive
450
451</p></pre><BR>
452
453<pre><b>size_t ZSTD_CCtx_setParameter(ZSTD_CCtx* cctx, ZSTD_cParameter param, int value);
454</b><p>  Set one compression parameter, selected by enum ZSTD_cParameter.
455  All parameters have valid bounds. Bounds can be queried using ZSTD_cParam_getBounds().
456  Providing a value beyond bound will either clamp it, or trigger an error (depending on parameter).
457  Setting a parameter is generally only possible during frame initialization (before starting compression).
458  Exception : when using multi-threading mode (nbWorkers >= 1),
459              the following parameters can be updated _during_ compression (within same frame):
460              => compressionLevel, hashLog, chainLog, searchLog, minMatch, targetLength and strategy.
461              new parameters will be active for next job only (after a flush()).
462 @return : an error code (which can be tested using ZSTD_isError()).
463
464</p></pre><BR>
465
466<pre><b>size_t ZSTD_CCtx_setPledgedSrcSize(ZSTD_CCtx* cctx, unsigned long long pledgedSrcSize);
467</b><p>  Total input data size to be compressed as a single frame.
468  Value will be written in frame header, unless if explicitly forbidden using ZSTD_c_contentSizeFlag.
469  This value will also be controlled at end of frame, and trigger an error if not respected.
470 @result : 0, or an error code (which can be tested with ZSTD_isError()).
471  Note 1 : pledgedSrcSize==0 actually means zero, aka an empty frame.
472           In order to mean "unknown content size", pass constant ZSTD_CONTENTSIZE_UNKNOWN.
473           ZSTD_CONTENTSIZE_UNKNOWN is default value for any new frame.
474  Note 2 : pledgedSrcSize is only valid once, for the next frame.
475           It's discarded at the end of the frame, and replaced by ZSTD_CONTENTSIZE_UNKNOWN.
476  Note 3 : Whenever all input data is provided and consumed in a single round,
477           for example with ZSTD_compress2(),
478           or invoking immediately ZSTD_compressStream2(,,,ZSTD_e_end),
479           this value is automatically overridden by srcSize instead.
480
481</p></pre><BR>
482
483<pre><b>typedef enum {
484    ZSTD_reset_session_only = 1,
485    ZSTD_reset_parameters = 2,
486    ZSTD_reset_session_and_parameters = 3
487} ZSTD_ResetDirective;
488</b></pre><BR>
489<pre><b>size_t ZSTD_CCtx_reset(ZSTD_CCtx* cctx, ZSTD_ResetDirective reset);
490</b><p>  There are 2 different things that can be reset, independently or jointly :
491  - The session : will stop compressing current frame, and make CCtx ready to start a new one.
492                  Useful after an error, or to interrupt any ongoing compression.
493                  Any internal data not yet flushed is cancelled.
494                  Compression parameters and dictionary remain unchanged.
495                  They will be used to compress next frame.
496                  Resetting session never fails.
497  - The parameters : changes all parameters back to "default".
498                  This also removes any reference to any dictionary or external sequence producer.
499                  Parameters can only be changed between 2 sessions (i.e. no compression is currently ongoing)
500                  otherwise the reset fails, and function returns an error value (which can be tested using ZSTD_isError())
501  - Both : similar to resetting the session, followed by resetting parameters.
502
503</p></pre><BR>
504
505<pre><b>size_t ZSTD_compress2( ZSTD_CCtx* cctx,
506                       void* dst, size_t dstCapacity,
507                 const void* src, size_t srcSize);
508</b><p>  Behave the same as ZSTD_compressCCtx(), but compression parameters are set using the advanced API.
509  (note that this entry point doesn't even expose a compression level parameter).
510  ZSTD_compress2() always starts a new frame.
511  Should cctx hold data from a previously unfinished frame, everything about it is forgotten.
512  - Compression parameters are pushed into CCtx before starting compression, using ZSTD_CCtx_set*()
513  - The function is always blocking, returns when compression is completed.
514  NOTE: Providing `dstCapacity >= ZSTD_compressBound(srcSize)` guarantees that zstd will have
515        enough space to successfully compress the data, though it is possible it fails for other reasons.
516 @return : compressed size written into `dst` (<= `dstCapacity),
517           or an error code if it fails (which can be tested using ZSTD_isError()).
518
519</p></pre><BR>
520
521<a name="Chapter6"></a><h2>Advanced decompression API (Requires v1.4.0+)</h2><pre></pre>
522
523<pre><b>typedef enum {
524
525    ZSTD_d_windowLogMax=100, </b>/* Select a size limit (in power of 2) beyond which<b>
526                              * the streaming API will refuse to allocate memory buffer
527                              * in order to protect the host from unreasonable memory requirements.
528                              * This parameter is only useful in streaming mode, since no internal buffer is allocated in single-pass mode.
529                              * By default, a decompression context accepts window sizes <= (1 << ZSTD_WINDOWLOG_LIMIT_DEFAULT).
530                              * Special: value 0 means "use default maximum windowLog". */
531
532    </b>/* note : additional experimental parameters are also available<b>
533     * within the experimental section of the API.
534     * At the time of this writing, they include :
535     * ZSTD_d_format
536     * ZSTD_d_stableOutBuffer
537     * ZSTD_d_forceIgnoreChecksum
538     * ZSTD_d_refMultipleDDicts
539     * ZSTD_d_disableHuffmanAssembly
540     * ZSTD_d_maxBlockSize
541     * Because they are not stable, it's necessary to define ZSTD_STATIC_LINKING_ONLY to access them.
542     * note : never ever use experimentalParam? names directly
543     */
544     ZSTD_d_experimentalParam1=1000,
545     ZSTD_d_experimentalParam2=1001,
546     ZSTD_d_experimentalParam3=1002,
547     ZSTD_d_experimentalParam4=1003,
548     ZSTD_d_experimentalParam5=1004,
549     ZSTD_d_experimentalParam6=1005
550
551} ZSTD_dParameter;
552</b></pre><BR>
553<pre><b>ZSTD_bounds ZSTD_dParam_getBounds(ZSTD_dParameter dParam);
554</b><p>  All parameters must belong to an interval with lower and upper bounds,
555  otherwise they will either trigger an error or be automatically clamped.
556 @return : a structure, ZSTD_bounds, which contains
557         - an error status field, which must be tested using ZSTD_isError()
558         - both lower and upper bounds, inclusive
559
560</p></pre><BR>
561
562<pre><b>size_t ZSTD_DCtx_setParameter(ZSTD_DCtx* dctx, ZSTD_dParameter param, int value);
563</b><p>  Set one compression parameter, selected by enum ZSTD_dParameter.
564  All parameters have valid bounds. Bounds can be queried using ZSTD_dParam_getBounds().
565  Providing a value beyond bound will either clamp it, or trigger an error (depending on parameter).
566  Setting a parameter is only possible during frame initialization (before starting decompression).
567 @return : 0, or an error code (which can be tested using ZSTD_isError()).
568
569</p></pre><BR>
570
571<pre><b>size_t ZSTD_DCtx_reset(ZSTD_DCtx* dctx, ZSTD_ResetDirective reset);
572</b><p>  Return a DCtx to clean state.
573  Session and parameters can be reset jointly or separately.
574  Parameters can only be reset when no active frame is being decompressed.
575 @return : 0, or an error code, which can be tested with ZSTD_isError()
576
577</p></pre><BR>
578
579<a name="Chapter7"></a><h2>Streaming</h2><pre></pre>
580
581<pre><b>typedef struct ZSTD_inBuffer_s {
582  const void* src;    </b>/**< start of input buffer */<b>
583  size_t size;        </b>/**< size of input buffer */<b>
584  size_t pos;         </b>/**< position where reading stopped. Will be updated. Necessarily 0 <= pos <= size */<b>
585} ZSTD_inBuffer;
586</b></pre><BR>
587<pre><b>typedef struct ZSTD_outBuffer_s {
588  void*  dst;         </b>/**< start of output buffer */<b>
589  size_t size;        </b>/**< size of output buffer */<b>
590  size_t pos;         </b>/**< position where writing stopped. Will be updated. Necessarily 0 <= pos <= size */<b>
591} ZSTD_outBuffer;
592</b></pre><BR>
593<a name="Chapter8"></a><h2>Streaming compression - HowTo</h2><pre>
594  A ZSTD_CStream object is required to track streaming operation.
595  Use ZSTD_createCStream() and ZSTD_freeCStream() to create/release resources.
596  ZSTD_CStream objects can be reused multiple times on consecutive compression operations.
597  It is recommended to reuse ZSTD_CStream since it will play nicer with system's memory, by re-using already allocated memory.
598
599  For parallel execution, use one separate ZSTD_CStream per thread.
600
601  note : since v1.3.0, ZSTD_CStream and ZSTD_CCtx are the same thing.
602
603  Parameters are sticky : when starting a new compression on the same context,
604  it will reuse the same sticky parameters as previous compression session.
605  When in doubt, it's recommended to fully initialize the context before usage.
606  Use ZSTD_CCtx_reset() to reset the context and ZSTD_CCtx_setParameter(),
607  ZSTD_CCtx_setPledgedSrcSize(), or ZSTD_CCtx_loadDictionary() and friends to
608  set more specific parameters, the pledged source size, or load a dictionary.
609
610  Use ZSTD_compressStream2() with ZSTD_e_continue as many times as necessary to
611  consume input stream. The function will automatically update both `pos`
612  fields within `input` and `output`.
613  Note that the function may not consume the entire input, for example, because
614  the output buffer is already full, in which case `input.pos < input.size`.
615  The caller must check if input has been entirely consumed.
616  If not, the caller must make some room to receive more compressed data,
617  and then present again remaining input data.
618  note: ZSTD_e_continue is guaranteed to make some forward progress when called,
619        but doesn't guarantee maximal forward progress. This is especially relevant
620        when compressing with multiple threads. The call won't block if it can
621        consume some input, but if it can't it will wait for some, but not all,
622        output to be flushed.
623 @return : provides a minimum amount of data remaining to be flushed from internal buffers
624           or an error code, which can be tested using ZSTD_isError().
625
626  At any moment, it's possible to flush whatever data might remain stuck within internal buffer,
627  using ZSTD_compressStream2() with ZSTD_e_flush. `output->pos` will be updated.
628  Note that, if `output->size` is too small, a single invocation with ZSTD_e_flush might not be enough (return code > 0).
629  In which case, make some room to receive more compressed data, and call again ZSTD_compressStream2() with ZSTD_e_flush.
630  You must continue calling ZSTD_compressStream2() with ZSTD_e_flush until it returns 0, at which point you can change the
631  operation.
632  note: ZSTD_e_flush will flush as much output as possible, meaning when compressing with multiple threads, it will
633        block until the flush is complete or the output buffer is full.
634  @return : 0 if internal buffers are entirely flushed,
635            >0 if some data still present within internal buffer (the value is minimal estimation of remaining size),
636            or an error code, which can be tested using ZSTD_isError().
637
638  Calling ZSTD_compressStream2() with ZSTD_e_end instructs to finish a frame.
639  It will perform a flush and write frame epilogue.
640  The epilogue is required for decoders to consider a frame completed.
641  flush operation is the same, and follows same rules as calling ZSTD_compressStream2() with ZSTD_e_flush.
642  You must continue calling ZSTD_compressStream2() with ZSTD_e_end until it returns 0, at which point you are free to
643  start a new frame.
644  note: ZSTD_e_end will flush as much output as possible, meaning when compressing with multiple threads, it will
645        block until the flush is complete or the output buffer is full.
646  @return : 0 if frame fully completed and fully flushed,
647            >0 if some data still present within internal buffer (the value is minimal estimation of remaining size),
648            or an error code, which can be tested using ZSTD_isError().
649
650
651<BR></pre>
652
653<pre><b>typedef ZSTD_CCtx ZSTD_CStream;  </b>/**< CCtx and CStream are now effectively same object (>= v1.3.0) */<b>
654</b></pre><BR>
655<h3>ZSTD_CStream management functions</h3><pre></pre><b><pre>ZSTD_CStream* ZSTD_createCStream(void);
656size_t ZSTD_freeCStream(ZSTD_CStream* zcs);  </b>/* accept NULL pointer */<b>
657</pre></b><BR>
658<h3>Streaming compression functions</h3><pre></pre><b><pre>typedef enum {
659    ZSTD_e_continue=0, </b>/* collect more data, encoder decides when to output compressed result, for optimal compression ratio */<b>
660    ZSTD_e_flush=1,    </b>/* flush any data provided so far,<b>
661                        * it creates (at least) one new block, that can be decoded immediately on reception;
662                        * frame will continue: any future data can still reference previously compressed data, improving compression.
663                        * note : multithreaded compression will block to flush as much output as possible. */
664    ZSTD_e_end=2       </b>/* flush any remaining data _and_ close current frame.<b>
665                        * note that frame is only closed after compressed data is fully flushed (return value == 0).
666                        * After that point, any additional data starts a new frame.
667                        * note : each frame is independent (does not reference any content from previous frame).
668                        : note : multithreaded compression will block to flush as much output as possible. */
669} ZSTD_EndDirective;
670</pre></b><BR>
671<pre><b>size_t ZSTD_compressStream2( ZSTD_CCtx* cctx,
672                             ZSTD_outBuffer* output,
673                             ZSTD_inBuffer* input,
674                             ZSTD_EndDirective endOp);
675</b><p>  Behaves about the same as ZSTD_compressStream, with additional control on end directive.
676  - Compression parameters are pushed into CCtx before starting compression, using ZSTD_CCtx_set*()
677  - Compression parameters cannot be changed once compression is started (save a list of exceptions in multi-threading mode)
678  - output->pos must be <= dstCapacity, input->pos must be <= srcSize
679  - output->pos and input->pos will be updated. They are guaranteed to remain below their respective limit.
680  - endOp must be a valid directive
681  - When nbWorkers==0 (default), function is blocking : it completes its job before returning to caller.
682  - When nbWorkers>=1, function is non-blocking : it copies a portion of input, distributes jobs to internal worker threads, flush to output whatever is available,
683                                                  and then immediately returns, just indicating that there is some data remaining to be flushed.
684                                                  The function nonetheless guarantees forward progress : it will return only after it reads or write at least 1+ byte.
685  - Exception : if the first call requests a ZSTD_e_end directive and provides enough dstCapacity, the function delegates to ZSTD_compress2() which is always blocking.
686  - @return provides a minimum amount of data remaining to be flushed from internal buffers
687            or an error code, which can be tested using ZSTD_isError().
688            if @return != 0, flush is not fully completed, there is still some data left within internal buffers.
689            This is useful for ZSTD_e_flush, since in this case more flushes are necessary to empty all buffers.
690            For ZSTD_e_end, @return == 0 when internal buffers are fully flushed and frame is completed.
691  - after a ZSTD_e_end directive, if internal buffer is not fully flushed (@return != 0),
692            only ZSTD_e_end or ZSTD_e_flush operations are allowed.
693            Before starting a new compression job, or changing compression parameters,
694            it is required to fully flush internal buffers.
695  - note: if an operation ends with an error, it may leave @cctx in an undefined state.
696          Therefore, it's UB to invoke ZSTD_compressStream2() of ZSTD_compressStream() on such a state.
697          In order to be re-employed after an error, a state must be reset,
698          which can be done explicitly (ZSTD_CCtx_reset()),
699          or is sometimes implied by methods starting a new compression job (ZSTD_initCStream(), ZSTD_compressCCtx())
700
701</p></pre><BR>
702
703<pre><b>size_t ZSTD_CStreamInSize(void);    </b>/**< recommended size for input buffer */<b>
704</b></pre><BR>
705<pre><b>size_t ZSTD_CStreamOutSize(void);   </b>/**< recommended size for output buffer. Guarantee to successfully flush at least one complete compressed block. */<b>
706</b></pre><BR>
707<pre><b>size_t ZSTD_initCStream(ZSTD_CStream* zcs, int compressionLevel);
708</b>/*!<b>
709 * Alternative for ZSTD_compressStream2(zcs, output, input, ZSTD_e_continue).
710 * NOTE: The return value is different. ZSTD_compressStream() returns a hint for
711 * the next read size (if non-zero and not an error). ZSTD_compressStream2()
712 * returns the minimum nb of bytes left to flush (if non-zero and not an error).
713 */
714size_t ZSTD_compressStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output, ZSTD_inBuffer* input);
715</b>/*! Equivalent to ZSTD_compressStream2(zcs, output, &emptyInput, ZSTD_e_flush). */<b>
716size_t ZSTD_flushStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output);
717</b>/*! Equivalent to ZSTD_compressStream2(zcs, output, &emptyInput, ZSTD_e_end). */<b>
718size_t ZSTD_endStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output);
719</b><p>
720     ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
721     ZSTD_CCtx_refCDict(zcs, NULL); // clear the dictionary (if any)
722     ZSTD_CCtx_setParameter(zcs, ZSTD_c_compressionLevel, compressionLevel);
723
724 Note that ZSTD_initCStream() clears any previously set dictionary. Use the new API
725 to compress with a dictionary.
726
727</p></pre><BR>
728
729<a name="Chapter9"></a><h2>Streaming decompression - HowTo</h2><pre>
730  A ZSTD_DStream object is required to track streaming operations.
731  Use ZSTD_createDStream() and ZSTD_freeDStream() to create/release resources.
732  ZSTD_DStream objects can be re-employed multiple times.
733
734  Use ZSTD_initDStream() to start a new decompression operation.
735 @return : recommended first input size
736  Alternatively, use advanced API to set specific properties.
737
738  Use ZSTD_decompressStream() repetitively to consume your input.
739  The function will update both `pos` fields.
740  If `input.pos < input.size`, some input has not been consumed.
741  It's up to the caller to present again remaining data.
742
743  The function tries to flush all data decoded immediately, respecting output buffer size.
744  If `output.pos < output.size`, decoder has flushed everything it could.
745
746  However, when `output.pos == output.size`, it's more difficult to know.
747  If @return > 0, the frame is not complete, meaning
748  either there is still some data left to flush within internal buffers,
749  or there is more input to read to complete the frame (or both).
750  In which case, call ZSTD_decompressStream() again to flush whatever remains in the buffer.
751  Note : with no additional input provided, amount of data flushed is necessarily <= ZSTD_BLOCKSIZE_MAX.
752 @return : 0 when a frame is completely decoded and fully flushed,
753        or an error code, which can be tested using ZSTD_isError(),
754        or any other value > 0, which means there is still some decoding or flushing to do to complete current frame :
755                                the return value is a suggested next input size (just a hint for better latency)
756                                that will never request more than the remaining content of the compressed frame.
757
758<BR></pre>
759
760<pre><b>typedef ZSTD_DCtx ZSTD_DStream;  </b>/**< DCtx and DStream are now effectively same object (>= v1.3.0) */<b>
761</b></pre><BR>
762<h3>ZSTD_DStream management functions</h3><pre></pre><b><pre>ZSTD_DStream* ZSTD_createDStream(void);
763size_t ZSTD_freeDStream(ZSTD_DStream* zds);  </b>/* accept NULL pointer */<b>
764</pre></b><BR>
765<h3>Streaming decompression functions</h3><pre></pre><b><pre></pre></b><BR>
766<pre><b>size_t ZSTD_initDStream(ZSTD_DStream* zds);
767</b><p> Initialize/reset DStream state for new decompression operation.
768 Call before new decompression operation using same DStream.
769
770 Note : This function is redundant with the advanced API and equivalent to:
771     ZSTD_DCtx_reset(zds, ZSTD_reset_session_only);
772     ZSTD_DCtx_refDDict(zds, NULL);
773
774</p></pre><BR>
775
776<pre><b>size_t ZSTD_decompressStream(ZSTD_DStream* zds, ZSTD_outBuffer* output, ZSTD_inBuffer* input);
777</b><p> Streaming decompression function.
778 Call repetitively to consume full input updating it as necessary.
779 Function will update both input and output `pos` fields exposing current state via these fields:
780 - `input.pos < input.size`, some input remaining and caller should provide remaining input
781   on the next call.
782 - `output.pos < output.size`, decoder flushed internal output buffer.
783 - `output.pos == output.size`, unflushed data potentially present in the internal buffers,
784   check ZSTD_decompressStream() @return value,
785   if > 0, invoke it again to flush remaining data to output.
786 Note : with no additional input, amount of data flushed <= ZSTD_BLOCKSIZE_MAX.
787
788 @return : 0 when a frame is completely decoded and fully flushed,
789           or an error code, which can be tested using ZSTD_isError(),
790           or any other value > 0, which means there is some decoding or flushing to do to complete current frame.
791
792 Note: when an operation returns with an error code, the @zds state may be left in undefined state.
793       It's UB to invoke `ZSTD_decompressStream()` on such a state.
794       In order to re-use such a state, it must be first reset,
795       which can be done explicitly (`ZSTD_DCtx_reset()`),
796       or is implied for operations starting some new decompression job (`ZSTD_initDStream`, `ZSTD_decompressDCtx()`, `ZSTD_decompress_usingDict()`)
797
798</p></pre><BR>
799
800<pre><b>size_t ZSTD_DStreamInSize(void);    </b>/*!< recommended size for input buffer */<b>
801</b></pre><BR>
802<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>
803</b></pre><BR>
804<a name="Chapter10"></a><h2>Simple dictionary API</h2><pre></pre>
805
806<pre><b>size_t ZSTD_compress_usingDict(ZSTD_CCtx* ctx,
807                               void* dst, size_t dstCapacity,
808                         const void* src, size_t srcSize,
809                         const void* dict,size_t dictSize,
810                               int compressionLevel);
811</b><p>  Compression at an explicit compression level using a Dictionary.
812  A dictionary can be any arbitrary data segment (also called a prefix),
813  or a buffer with specified information (see zdict.h).
814  Note : This function loads the dictionary, resulting in significant startup delay.
815         It's intended for a dictionary used only once.
816  Note 2 : When `dict == NULL || dictSize < 8` no dictionary is used.
817</p></pre><BR>
818
819<pre><b>size_t ZSTD_decompress_usingDict(ZSTD_DCtx* dctx,
820                                 void* dst, size_t dstCapacity,
821                           const void* src, size_t srcSize,
822                           const void* dict,size_t dictSize);
823</b><p>  Decompression using a known Dictionary.
824  Dictionary must be identical to the one used during compression.
825  Note : This function loads the dictionary, resulting in significant startup delay.
826         It's intended for a dictionary used only once.
827  Note : When `dict == NULL || dictSize < 8` no dictionary is used.
828</p></pre><BR>
829
830<a name="Chapter11"></a><h2>Bulk processing dictionary API</h2><pre></pre>
831
832<pre><b>ZSTD_CDict* ZSTD_createCDict(const void* dictBuffer, size_t dictSize,
833                             int compressionLevel);
834</b><p>  When compressing multiple messages or blocks using the same dictionary,
835  it's recommended to digest the dictionary only once, since it's a costly operation.
836  ZSTD_createCDict() will create a state from digesting a dictionary.
837  The resulting state can be used for future compression operations with very limited startup cost.
838  ZSTD_CDict can be created once and shared by multiple threads concurrently, since its usage is read-only.
839 @dictBuffer can be released after ZSTD_CDict creation, because its content is copied within CDict.
840  Note 1 : Consider experimental function `ZSTD_createCDict_byReference()` if you prefer to not duplicate @dictBuffer content.
841  Note 2 : A ZSTD_CDict can be created from an empty @dictBuffer,
842      in which case the only thing that it transports is the @compressionLevel.
843      This can be useful in a pipeline featuring ZSTD_compress_usingCDict() exclusively,
844      expecting a ZSTD_CDict parameter with any data, including those without a known dictionary.
845</p></pre><BR>
846
847<pre><b>size_t      ZSTD_freeCDict(ZSTD_CDict* CDict);
848</b><p>  Function frees memory allocated by ZSTD_createCDict().
849  If a NULL pointer is passed, no operation is performed.
850</p></pre><BR>
851
852<pre><b>size_t ZSTD_compress_usingCDict(ZSTD_CCtx* cctx,
853                                void* dst, size_t dstCapacity,
854                          const void* src, size_t srcSize,
855                          const ZSTD_CDict* cdict);
856</b><p>  Compression using a digested Dictionary.
857  Recommended when same dictionary is used multiple times.
858  Note : compression level is _decided at dictionary creation time_,
859     and frame parameters are hardcoded (dictID=yes, contentSize=yes, checksum=no)
860</p></pre><BR>
861
862<pre><b>ZSTD_DDict* ZSTD_createDDict(const void* dictBuffer, size_t dictSize);
863</b><p>  Create a digested dictionary, ready to start decompression operation without startup delay.
864  dictBuffer can be released after DDict creation, as its content is copied inside DDict.
865</p></pre><BR>
866
867<pre><b>size_t      ZSTD_freeDDict(ZSTD_DDict* ddict);
868</b><p>  Function frees memory allocated with ZSTD_createDDict()
869  If a NULL pointer is passed, no operation is performed.
870</p></pre><BR>
871
872<pre><b>size_t ZSTD_decompress_usingDDict(ZSTD_DCtx* dctx,
873                                  void* dst, size_t dstCapacity,
874                            const void* src, size_t srcSize,
875                            const ZSTD_DDict* ddict);
876</b><p>  Decompression using a digested Dictionary.
877  Recommended when same dictionary is used multiple times.
878</p></pre><BR>
879
880<a name="Chapter12"></a><h2>Dictionary helper functions</h2><pre></pre>
881
882<pre><b>unsigned ZSTD_getDictID_fromDict(const void* dict, size_t dictSize);
883</b><p>  Provides the dictID stored within dictionary.
884  if @return == 0, the dictionary is not conformant with Zstandard specification.
885  It can still be loaded, but as a content-only dictionary.
886</p></pre><BR>
887
888<pre><b>unsigned ZSTD_getDictID_fromCDict(const ZSTD_CDict* cdict);
889</b><p>  Provides the dictID of the dictionary loaded into `cdict`.
890  If @return == 0, the dictionary is not conformant to Zstandard specification, or empty.
891  Non-conformant dictionaries can still be loaded, but as content-only dictionaries.
892</p></pre><BR>
893
894<pre><b>unsigned ZSTD_getDictID_fromDDict(const ZSTD_DDict* ddict);
895</b><p>  Provides the dictID of the dictionary loaded into `ddict`.
896  If @return == 0, the dictionary is not conformant to Zstandard specification, or empty.
897  Non-conformant dictionaries can still be loaded, but as content-only dictionaries.
898</p></pre><BR>
899
900<pre><b>unsigned ZSTD_getDictID_fromFrame(const void* src, size_t srcSize);
901</b><p>  Provides the dictID required to decompressed the frame stored within `src`.
902  If @return == 0, the dictID could not be decoded.
903  This could for one of the following reasons :
904  - The frame does not require a dictionary to be decoded (most common case).
905  - The frame was built with dictID intentionally removed. Whatever dictionary is necessary is a hidden piece of information.
906    Note : this use case also happens when using a non-conformant dictionary.
907  - `srcSize` is too small, and as a result, the frame header could not be decoded (only possible if `srcSize < ZSTD_FRAMEHEADERSIZE_MAX`).
908  - This is not a Zstandard frame.
909  When identifying the exact failure cause, it's possible to use ZSTD_getFrameHeader(), which will provide a more precise error code.
910</p></pre><BR>
911
912<a name="Chapter13"></a><h2>Advanced dictionary and prefix API (Requires v1.4.0+)</h2><pre>
913 This API allows dictionaries to be used with ZSTD_compress2(),
914 ZSTD_compressStream2(), and ZSTD_decompressDCtx().
915 Dictionaries are sticky, they remain valid when same context is reused,
916 they only reset when the context is reset
917 with ZSTD_reset_parameters or ZSTD_reset_session_and_parameters.
918 In contrast, Prefixes are single-use.
919<BR></pre>
920
921<pre><b>size_t ZSTD_CCtx_loadDictionary(ZSTD_CCtx* cctx, const void* dict, size_t dictSize);
922</b><p>  Create an internal CDict from `dict` buffer.
923  Decompression will have to use same dictionary.
924 @result : 0, or an error code (which can be tested with ZSTD_isError()).
925  Special: Loading a NULL (or 0-size) dictionary invalidates previous dictionary,
926           meaning "return to no-dictionary mode".
927  Note 1 : Dictionary is sticky, it will be used for all future compressed frames,
928           until parameters are reset, a new dictionary is loaded, or the dictionary
929           is explicitly invalidated by loading a NULL dictionary.
930  Note 2 : Loading a dictionary involves building tables.
931           It's also a CPU consuming operation, with non-negligible impact on latency.
932           Tables are dependent on compression parameters, and for this reason,
933           compression parameters can no longer be changed after loading a dictionary.
934  Note 3 :`dict` content will be copied internally.
935           Use experimental ZSTD_CCtx_loadDictionary_byReference() to reference content instead.
936           In such a case, dictionary buffer must outlive its users.
937  Note 4 : Use ZSTD_CCtx_loadDictionary_advanced()
938           to precisely select how dictionary content must be interpreted.
939  Note 5 : This method does not benefit from LDM (long distance mode).
940           If you want to employ LDM on some large dictionary content,
941           prefer employing ZSTD_CCtx_refPrefix() described below.
942
943</p></pre><BR>
944
945<pre><b>size_t ZSTD_CCtx_refCDict(ZSTD_CCtx* cctx, const ZSTD_CDict* cdict);
946</b><p>  Reference a prepared dictionary, to be used for all future compressed frames.
947  Note that compression parameters are enforced from within CDict,
948  and supersede any compression parameter previously set within CCtx.
949  The parameters ignored are labelled as "superseded-by-cdict" in the ZSTD_cParameter enum docs.
950  The ignored parameters will be used again if the CCtx is returned to no-dictionary mode.
951  The dictionary will remain valid for future compressed frames using same CCtx.
952 @result : 0, or an error code (which can be tested with ZSTD_isError()).
953  Special : Referencing a NULL CDict means "return to no-dictionary mode".
954  Note 1 : Currently, only one dictionary can be managed.
955           Referencing a new dictionary effectively "discards" any previous one.
956  Note 2 : CDict is just referenced, its lifetime must outlive its usage within CCtx.
957</p></pre><BR>
958
959<pre><b>size_t ZSTD_CCtx_refPrefix(ZSTD_CCtx* cctx,
960                     const void* prefix, size_t prefixSize);
961</b><p>  Reference a prefix (single-usage dictionary) for next compressed frame.
962  A prefix is **only used once**. Tables are discarded at end of frame (ZSTD_e_end).
963  Decompression will need same prefix to properly regenerate data.
964  Compressing with a prefix is similar in outcome as performing a diff and compressing it,
965  but performs much faster, especially during decompression (compression speed is tunable with compression level).
966  This method is compatible with LDM (long distance mode).
967 @result : 0, or an error code (which can be tested with ZSTD_isError()).
968  Special: Adding any prefix (including NULL) invalidates any previous prefix or dictionary
969  Note 1 : Prefix buffer is referenced. It **must** outlive compression.
970           Its content must remain unmodified during compression.
971  Note 2 : If the intention is to diff some large src data blob with some prior version of itself,
972           ensure that the window size is large enough to contain the entire source.
973           See ZSTD_c_windowLog.
974  Note 3 : Referencing a prefix involves building tables, which are dependent on compression parameters.
975           It's a CPU consuming operation, with non-negligible impact on latency.
976           If there is a need to use the same prefix multiple times, consider loadDictionary instead.
977  Note 4 : By default, the prefix is interpreted as raw content (ZSTD_dct_rawContent).
978           Use experimental ZSTD_CCtx_refPrefix_advanced() to alter dictionary interpretation.
979</p></pre><BR>
980
981<pre><b>size_t ZSTD_DCtx_loadDictionary(ZSTD_DCtx* dctx, const void* dict, size_t dictSize);
982</b><p>  Create an internal DDict from dict buffer, to be used to decompress all future frames.
983  The dictionary remains valid for all future frames, until explicitly invalidated, or
984  a new dictionary is loaded.
985 @result : 0, or an error code (which can be tested with ZSTD_isError()).
986  Special : Adding a NULL (or 0-size) dictionary invalidates any previous dictionary,
987            meaning "return to no-dictionary mode".
988  Note 1 : Loading a dictionary involves building tables,
989           which has a non-negligible impact on CPU usage and latency.
990           It's recommended to "load once, use many times", to amortize the cost
991  Note 2 :`dict` content will be copied internally, so `dict` can be released after loading.
992           Use ZSTD_DCtx_loadDictionary_byReference() to reference dictionary content instead.
993  Note 3 : Use ZSTD_DCtx_loadDictionary_advanced() to take control of
994           how dictionary content is loaded and interpreted.
995
996</p></pre><BR>
997
998<pre><b>size_t ZSTD_DCtx_refDDict(ZSTD_DCtx* dctx, const ZSTD_DDict* ddict);
999</b><p>  Reference a prepared dictionary, to be used to decompress next frames.
1000  The dictionary remains active for decompression of future frames using same DCtx.
1001
1002  If called with ZSTD_d_refMultipleDDicts enabled, repeated calls of this function
1003  will store the DDict references in a table, and the DDict used for decompression
1004  will be determined at decompression time, as per the dict ID in the frame.
1005  The memory for the table is allocated on the first call to refDDict, and can be
1006  freed with ZSTD_freeDCtx().
1007
1008  If called with ZSTD_d_refMultipleDDicts disabled (the default), only one dictionary
1009  will be managed, and referencing a dictionary effectively "discards" any previous one.
1010
1011 @result : 0, or an error code (which can be tested with ZSTD_isError()).
1012  Special: referencing a NULL DDict means "return to no-dictionary mode".
1013  Note 2 : DDict is just referenced, its lifetime must outlive its usage from DCtx.
1014
1015</p></pre><BR>
1016
1017<pre><b>size_t ZSTD_DCtx_refPrefix(ZSTD_DCtx* dctx,
1018                     const void* prefix, size_t prefixSize);
1019</b><p>  Reference a prefix (single-usage dictionary) to decompress next frame.
1020  This is the reverse operation of ZSTD_CCtx_refPrefix(),
1021  and must use the same prefix as the one used during compression.
1022  Prefix is **only used once**. Reference is discarded at end of frame.
1023  End of frame is reached when ZSTD_decompressStream() returns 0.
1024 @result : 0, or an error code (which can be tested with ZSTD_isError()).
1025  Note 1 : Adding any prefix (including NULL) invalidates any previously set prefix or dictionary
1026  Note 2 : Prefix buffer is referenced. It **must** outlive decompression.
1027           Prefix buffer must remain unmodified up to the end of frame,
1028           reached when ZSTD_decompressStream() returns 0.
1029  Note 3 : By default, the prefix is treated as raw content (ZSTD_dct_rawContent).
1030           Use ZSTD_CCtx_refPrefix_advanced() to alter dictMode (Experimental section)
1031  Note 4 : Referencing a raw content prefix has almost no cpu nor memory cost.
1032           A full dictionary is more costly, as it requires building tables.
1033
1034</p></pre><BR>
1035
1036<pre><b>size_t ZSTD_sizeof_CCtx(const ZSTD_CCtx* cctx);
1037size_t ZSTD_sizeof_DCtx(const ZSTD_DCtx* dctx);
1038size_t ZSTD_sizeof_CStream(const ZSTD_CStream* zcs);
1039size_t ZSTD_sizeof_DStream(const ZSTD_DStream* zds);
1040size_t ZSTD_sizeof_CDict(const ZSTD_CDict* cdict);
1041size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict);
1042</b><p>  These functions give the _current_ memory usage of selected object.
1043  Note that object memory usage can evolve (increase or decrease) over time.
1044</p></pre><BR>
1045
1046<a name="Chapter14"></a><h2>experimental API (static linking only)</h2><pre>
1047 The following symbols and constants
1048 are not planned to join "stable API" status in the near future.
1049 They can still change in future versions.
1050 Some of them are planned to remain in the static_only section indefinitely.
1051 Some of them might be removed in the future (especially when redundant with existing stable functions)
1052
1053<BR></pre>
1054
1055<pre><b>typedef struct {
1056    unsigned int offset;      </b>/* The offset of the match. (NOT the same as the offset code)<b>
1057                               * If offset == 0 and matchLength == 0, this sequence represents the last
1058                               * literals in the block of litLength size.
1059                               */
1060
1061    unsigned int litLength;   </b>/* Literal length of the sequence. */<b>
1062    unsigned int matchLength; </b>/* Match length of the sequence. */<b>
1063
1064                              </b>/* Note: Users of this API may provide a sequence with matchLength == litLength == offset == 0.<b>
1065                               * In this case, we will treat the sequence as a marker for a block boundary.
1066                               */
1067
1068    unsigned int rep;         </b>/* Represents which repeat offset is represented by the field 'offset'.<b>
1069                               * Ranges from [0, 3].
1070                               *
1071                               * Repeat offsets are essentially previous offsets from previous sequences sorted in
1072                               * recency order. For more detail, see doc/zstd_compression_format.md
1073                               *
1074                               * If rep == 0, then 'offset' does not contain a repeat offset.
1075                               * If rep > 0:
1076                               *  If litLength != 0:
1077                               *      rep == 1 --> offset == repeat_offset_1
1078                               *      rep == 2 --> offset == repeat_offset_2
1079                               *      rep == 3 --> offset == repeat_offset_3
1080                               *  If litLength == 0:
1081                               *      rep == 1 --> offset == repeat_offset_2
1082                               *      rep == 2 --> offset == repeat_offset_3
1083                               *      rep == 3 --> offset == repeat_offset_1 - 1
1084                               *
1085                               * Note: This field is optional. ZSTD_generateSequences() will calculate the value of
1086                               * 'rep', but repeat offsets do not necessarily need to be calculated from an external
1087                               * sequence provider perspective. For example, ZSTD_compressSequences() does not
1088                               * use this 'rep' field at all (as of now).
1089                               */
1090} ZSTD_Sequence;
1091</b></pre><BR>
1092<pre><b>typedef struct {
1093    unsigned windowLog;       </b>/**< largest match distance : larger == more compression, more memory needed during decompression */<b>
1094    unsigned chainLog;        </b>/**< fully searched segment : larger == more compression, slower, more memory (useless for fast) */<b>
1095    unsigned hashLog;         </b>/**< dispatch table : larger == faster, more memory */<b>
1096    unsigned searchLog;       </b>/**< nb of searches : larger == more compression, slower */<b>
1097    unsigned minMatch;        </b>/**< match length searched : larger == faster decompression, sometimes less compression */<b>
1098    unsigned targetLength;    </b>/**< acceptable match size for optimal parser (only) : larger == more compression, slower */<b>
1099    ZSTD_strategy strategy;   </b>/**< see ZSTD_strategy definition above */<b>
1100} ZSTD_compressionParameters;
1101</b></pre><BR>
1102<pre><b>typedef struct {
1103    int contentSizeFlag; </b>/**< 1: content size will be in frame header (when known) */<b>
1104    int checksumFlag;    </b>/**< 1: generate a 32-bits checksum using XXH64 algorithm at end of frame, for error detection */<b>
1105    int noDictIDFlag;    </b>/**< 1: no dictID will be saved into frame header (dictID is only useful for dictionary compression) */<b>
1106} ZSTD_frameParameters;
1107</b></pre><BR>
1108<pre><b>typedef struct {
1109    ZSTD_compressionParameters cParams;
1110    ZSTD_frameParameters fParams;
1111} ZSTD_parameters;
1112</b></pre><BR>
1113<pre><b>typedef enum {
1114    ZSTD_dct_auto = 0,       </b>/* dictionary is "full" when starting with ZSTD_MAGIC_DICTIONARY, otherwise it is "rawContent" */<b>
1115    ZSTD_dct_rawContent = 1, </b>/* ensures dictionary is always loaded as rawContent, even if it starts with ZSTD_MAGIC_DICTIONARY */<b>
1116    ZSTD_dct_fullDict = 2    </b>/* refuses to load a dictionary if it does not respect Zstandard's specification, starting with ZSTD_MAGIC_DICTIONARY */<b>
1117} ZSTD_dictContentType_e;
1118</b></pre><BR>
1119<pre><b>typedef enum {
1120    ZSTD_dlm_byCopy = 0,  </b>/**< Copy dictionary content internally */<b>
1121    ZSTD_dlm_byRef = 1    </b>/**< Reference dictionary content -- the dictionary buffer must outlive its users. */<b>
1122} ZSTD_dictLoadMethod_e;
1123</b></pre><BR>
1124<pre><b>typedef enum {
1125    ZSTD_f_zstd1 = 0,           </b>/* zstd frame format, specified in zstd_compression_format.md (default) */<b>
1126    ZSTD_f_zstd1_magicless = 1  </b>/* Variant of zstd frame format, without initial 4-bytes magic number.<b>
1127                                 * Useful to save 4 bytes per generated frame.
1128                                 * Decoder cannot recognise automatically this format, requiring this instruction. */
1129} ZSTD_format_e;
1130</b></pre><BR>
1131<pre><b>typedef enum {
1132    </b>/* Note: this enum controls ZSTD_d_forceIgnoreChecksum */<b>
1133    ZSTD_d_validateChecksum = 0,
1134    ZSTD_d_ignoreChecksum = 1
1135} ZSTD_forceIgnoreChecksum_e;
1136</b></pre><BR>
1137<pre><b>typedef enum {
1138    </b>/* Note: this enum controls ZSTD_d_refMultipleDDicts */<b>
1139    ZSTD_rmd_refSingleDDict = 0,
1140    ZSTD_rmd_refMultipleDDicts = 1
1141} ZSTD_refMultipleDDicts_e;
1142</b></pre><BR>
1143<pre><b>typedef enum {
1144    </b>/* Note: this enum and the behavior it controls are effectively internal<b>
1145     * implementation details of the compressor. They are expected to continue
1146     * to evolve and should be considered only in the context of extremely
1147     * advanced performance tuning.
1148     *
1149     * Zstd currently supports the use of a CDict in three ways:
1150     *
1151     * - The contents of the CDict can be copied into the working context. This
1152     *   means that the compression can search both the dictionary and input
1153     *   while operating on a single set of internal tables. This makes
1154     *   the compression faster per-byte of input. However, the initial copy of
1155     *   the CDict's tables incurs a fixed cost at the beginning of the
1156     *   compression. For small compressions (< 8 KB), that copy can dominate
1157     *   the cost of the compression.
1158     *
1159     * - The CDict's tables can be used in-place. In this model, compression is
1160     *   slower per input byte, because the compressor has to search two sets of
1161     *   tables. However, this model incurs no start-up cost (as long as the
1162     *   working context's tables can be reused). For small inputs, this can be
1163     *   faster than copying the CDict's tables.
1164     *
1165     * - The CDict's tables are not used at all, and instead we use the working
1166     *   context alone to reload the dictionary and use params based on the source
1167     *   size. See ZSTD_compress_insertDictionary() and ZSTD_compress_usingDict().
1168     *   This method is effective when the dictionary sizes are very small relative
1169     *   to the input size, and the input size is fairly large to begin with.
1170     *
1171     * Zstd has a simple internal heuristic that selects which strategy to use
1172     * at the beginning of a compression. However, if experimentation shows that
1173     * Zstd is making poor choices, it is possible to override that choice with
1174     * this enum.
1175     */
1176    ZSTD_dictDefaultAttach = 0, </b>/* Use the default heuristic. */<b>
1177    ZSTD_dictForceAttach   = 1, </b>/* Never copy the dictionary. */<b>
1178    ZSTD_dictForceCopy     = 2, </b>/* Always copy the dictionary. */<b>
1179    ZSTD_dictForceLoad     = 3  </b>/* Always reload the dictionary */<b>
1180} ZSTD_dictAttachPref_e;
1181</b></pre><BR>
1182<pre><b>typedef enum {
1183  ZSTD_lcm_auto = 0,          </b>/**< Automatically determine the compression mode based on the compression level.<b>
1184                               *   Negative compression levels will be uncompressed, and positive compression
1185                               *   levels will be compressed. */
1186  ZSTD_lcm_huffman = 1,       </b>/**< Always attempt Huffman compression. Uncompressed literals will still be<b>
1187                               *   emitted if Huffman compression is not profitable. */
1188  ZSTD_lcm_uncompressed = 2   </b>/**< Always emit uncompressed literals. */<b>
1189} ZSTD_literalCompressionMode_e;
1190</b></pre><BR>
1191<pre><b>typedef enum {
1192  </b>/* Note: This enum controls features which are conditionally beneficial.<b>
1193   * Zstd can take a decision on whether or not to enable the feature (ZSTD_ps_auto),
1194   * but setting the switch to ZSTD_ps_enable or ZSTD_ps_disable force enable/disable the feature.
1195   */
1196  ZSTD_ps_auto = 0,         </b>/* Let the library automatically determine whether the feature shall be enabled */<b>
1197  ZSTD_ps_enable = 1,       </b>/* Force-enable the feature */<b>
1198  ZSTD_ps_disable = 2       </b>/* Do not use the feature */<b>
1199} ZSTD_ParamSwitch_e;
1200</b></pre><BR>
1201<a name="Chapter15"></a><h2>Frame header and size functions</h2><pre></pre>
1202
1203<pre><b>ZSTDLIB_STATIC_API unsigned long long ZSTD_findDecompressedSize(const void* src, size_t srcSize);
1204</b><p>  `src` should point to the start of a series of ZSTD encoded and/or skippable frames
1205  `srcSize` must be the _exact_ size of this series
1206       (i.e. there should be a frame boundary at `src + srcSize`)
1207  @return : - decompressed size of all data in all successive frames
1208            - if the decompressed size cannot be determined: ZSTD_CONTENTSIZE_UNKNOWN
1209            - if an error occurred: ZSTD_CONTENTSIZE_ERROR
1210
1211   note 1 : decompressed size is an optional field, that may not be present, especially in streaming mode.
1212            When `return==ZSTD_CONTENTSIZE_UNKNOWN`, data to decompress could be any size.
1213            In which case, it's necessary to use streaming mode to decompress data.
1214   note 2 : decompressed size is always present when compression is done with ZSTD_compress()
1215   note 3 : decompressed size can be very large (64-bits value),
1216            potentially larger than what local system can handle as a single memory segment.
1217            In which case, it's necessary to use streaming mode to decompress data.
1218   note 4 : If source is untrusted, decompressed size could be wrong or intentionally modified.
1219            Always ensure result fits within application's authorized limits.
1220            Each application can set its own limits.
1221   note 5 : ZSTD_findDecompressedSize handles multiple frames, and so it must traverse the input to
1222            read each contained frame header.  This is fast as most of the data is skipped,
1223            however it does mean that all frame data must be present and valid.
1224</p></pre><BR>
1225
1226<pre><b>ZSTDLIB_STATIC_API unsigned long long ZSTD_decompressBound(const void* src, size_t srcSize);
1227</b><p>  `src` should point to the start of a series of ZSTD encoded and/or skippable frames
1228  `srcSize` must be the _exact_ size of this series
1229       (i.e. there should be a frame boundary at `src + srcSize`)
1230  @return : - upper-bound for the decompressed size of all data in all successive frames
1231            - if an error occurred: ZSTD_CONTENTSIZE_ERROR
1232
1233  note 1  : an error can occur if `src` contains an invalid or incorrectly formatted frame.
1234  note 2  : the upper-bound is exact when the decompressed size field is available in every ZSTD encoded frame of `src`.
1235            in this case, `ZSTD_findDecompressedSize` and `ZSTD_decompressBound` return the same value.
1236  note 3  : when the decompressed size field isn't available, the upper-bound for that frame is calculated by:
1237              upper-bound = # blocks * min(128 KB, Window_Size)
1238
1239</p></pre><BR>
1240
1241<pre><b>ZSTDLIB_STATIC_API size_t ZSTD_frameHeaderSize(const void* src, size_t srcSize);
1242</b><p>  srcSize must be >= ZSTD_FRAMEHEADERSIZE_PREFIX.
1243 @return : size of the Frame Header,
1244           or an error code (if srcSize is too small)
1245</p></pre><BR>
1246
1247<pre><b>typedef enum { ZSTD_frame, ZSTD_skippableFrame } ZSTD_FrameType_e;
1248</b></pre><BR>
1249<pre><b>typedef struct {
1250    unsigned long long frameContentSize; </b>/* if == ZSTD_CONTENTSIZE_UNKNOWN, it means this field is not available. 0 means "empty" */<b>
1251    unsigned long long windowSize;       </b>/* can be very large, up to <= frameContentSize */<b>
1252    unsigned blockSizeMax;
1253    ZSTD_FrameType_e frameType;          </b>/* if == ZSTD_skippableFrame, frameContentSize is the size of skippable content */<b>
1254    unsigned headerSize;
1255    unsigned dictID;
1256    unsigned checksumFlag;
1257    unsigned _reserved1;
1258    unsigned _reserved2;
1259} ZSTD_frameHeader;
1260</b></pre><BR>
1261<pre><b>ZSTDLIB_STATIC_API size_t ZSTD_getFrameHeader(ZSTD_FrameHeader* zfhPtr, const void* src, size_t srcSize);   </b>/**< doesn't consume input */<b>
1262</b>/*! ZSTD_getFrameHeader_advanced() :<b>
1263 *  same as ZSTD_getFrameHeader(),
1264 *  with added capability to select a format (like ZSTD_f_zstd1_magicless) */
1265ZSTDLIB_STATIC_API size_t ZSTD_getFrameHeader_advanced(ZSTD_FrameHeader* zfhPtr, const void* src, size_t srcSize, ZSTD_format_e format);
1266</b><p>  decode Frame Header, or requires larger `srcSize`.
1267 @return : 0, `zfhPtr` is correctly filled,
1268          >0, `srcSize` is too small, value is wanted `srcSize` amount,
1269           or an error code, which can be tested using ZSTD_isError()
1270</p></pre><BR>
1271
1272<pre><b>ZSTDLIB_STATIC_API size_t ZSTD_decompressionMargin(const void* src, size_t srcSize);
1273</b><p> Zstd supports in-place decompression, where the input and output buffers overlap.
1274 In this case, the output buffer must be at least (Margin + Output_Size) bytes large,
1275 and the input buffer must be at the end of the output buffer.
1276
1277  _______________________ Output Buffer ________________________
1278 |                                                              |
1279 |                                        ____ Input Buffer ____|
1280 |                                       |                      |
1281 v                                       v                      v
1282 |---------------------------------------|-----------|----------|
1283 ^                                                   ^          ^
1284 |___________________ Output_Size ___________________|_ Margin _|
1285
1286 NOTE: See also ZSTD_DECOMPRESSION_MARGIN().
1287 NOTE: This applies only to single-pass decompression through ZSTD_decompress() or
1288 ZSTD_decompressDCtx().
1289 NOTE: This function supports multi-frame input.
1290
1291 @param src The compressed frame(s)
1292 @param srcSize The size of the compressed frame(s)
1293 @returns The decompression margin or an error that can be checked with ZSTD_isError().
1294
1295</p></pre><BR>
1296
1297<pre><b>#define ZSTD_DECOMPRESSION_MARGIN(originalSize, blockSize) ((size_t)(                                              \
1298        ZSTD_FRAMEHEADERSIZE_MAX                                                              </b>/* Frame header */ + \<b>
1299        4                                                                                         </b>/* checksum */ + \<b>
1300        ((originalSize) == 0 ? 0 : 3 * (((originalSize) + (blockSize) - 1) / blockSize)) </b>/* 3 bytes per block */ + \<b>
1301        (blockSize)                                                                    </b>/* One block of margin */   \<b>
1302    ))
1303</b><p> Similar to ZSTD_decompressionMargin(), but instead of computing the margin from
1304 the compressed frame, compute it from the original size and the blockSizeLog.
1305 See ZSTD_decompressionMargin() for details.
1306
1307 WARNING: This macro does not support multi-frame input, the input must be a single
1308 zstd frame. If you need that support use the function, or implement it yourself.
1309
1310 @param originalSize The original uncompressed size of the data.
1311 @param blockSize    The block size == MIN(windowSize, ZSTD_BLOCKSIZE_MAX).
1312                     Unless you explicitly set the windowLog smaller than
1313                     ZSTD_BLOCKSIZELOG_MAX you can just use ZSTD_BLOCKSIZE_MAX.
1314
1315</p></pre><BR>
1316
1317<pre><b>typedef enum {
1318  ZSTD_sf_noBlockDelimiters = 0,         </b>/* ZSTD_Sequence[] has no block delimiters, just sequences */<b>
1319  ZSTD_sf_explicitBlockDelimiters = 1    </b>/* ZSTD_Sequence[] contains explicit block delimiters */<b>
1320} ZSTD_SequenceFormat_e;
1321</b></pre><BR>
1322<pre><b>ZSTDLIB_STATIC_API size_t ZSTD_sequenceBound(size_t srcSize);
1323</b><p> `srcSize` : size of the input buffer
1324  @return : upper-bound for the number of sequences that can be generated
1325            from a buffer of srcSize bytes
1326
1327  note : returns number of sequences - to get bytes, multiply by sizeof(ZSTD_Sequence).
1328
1329</p></pre><BR>
1330
1331<pre><b>ZSTD_DEPRECATED("For debugging only, will be replaced by ZSTD_extractSequences()")
1332ZSTDLIB_STATIC_API size_t
1333ZSTD_generateSequences(ZSTD_CCtx* zc,
1334           ZSTD_Sequence* outSeqs, size_t outSeqsCapacity,
1335           const void* src, size_t srcSize);
1336</b><p> WARNING: This function is meant for debugging and informational purposes ONLY!
1337 Its implementation is flawed, and it will be deleted in a future version.
1338 It is not guaranteed to succeed, as there are several cases where it will give
1339 up and fail. You should NOT use this function in production code.
1340
1341 This function is deprecated, and will be removed in a future version.
1342
1343 Generate sequences using ZSTD_compress2(), given a source buffer.
1344
1345 @param zc The compression context to be used for ZSTD_compress2(). Set any
1346           compression parameters you need on this context.
1347 @param outSeqs The output sequences buffer of size @p outSeqsSize
1348 @param outSeqsCapacity The size of the output sequences buffer.
1349                    ZSTD_sequenceBound(srcSize) is an upper bound on the number
1350                    of sequences that can be generated.
1351 @param src The source buffer to generate sequences from of size @p srcSize.
1352 @param srcSize The size of the source buffer.
1353
1354 Each block will end with a dummy sequence
1355 with offset == 0, matchLength == 0, and litLength == length of last literals.
1356 litLength may be == 0, and if so, then the sequence of (of: 0 ml: 0 ll: 0)
1357 simply acts as a block delimiter.
1358
1359 @returns The number of sequences generated, necessarily less than
1360          ZSTD_sequenceBound(srcSize), or an error code that can be checked
1361          with ZSTD_isError().
1362
1363</p></pre><BR>
1364
1365<pre><b>ZSTDLIB_STATIC_API size_t ZSTD_mergeBlockDelimiters(ZSTD_Sequence* sequences, size_t seqsSize);
1366</b><p> Given an array of ZSTD_Sequence, remove all sequences that represent block delimiters/last literals
1367 by merging them into the literals of the next sequence.
1368
1369 As such, the final generated result has no explicit representation of block boundaries,
1370 and the final last literals segment is not represented in the sequences.
1371
1372 The output of this function can be fed into ZSTD_compressSequences() with CCtx
1373 setting of ZSTD_c_blockDelimiters as ZSTD_sf_noBlockDelimiters
1374 @return : number of sequences left after merging
1375
1376</p></pre><BR>
1377
1378<pre><b>ZSTDLIB_STATIC_API size_t
1379ZSTD_compressSequences(ZSTD_CCtx* cctx,
1380           void* dst, size_t dstCapacity,
1381     const ZSTD_Sequence* inSeqs, size_t inSeqsSize,
1382     const void* src, size_t srcSize);
1383</b><p> Compress an array of ZSTD_Sequence, associated with @src buffer, into dst.
1384 @src contains the entire input (not just the literals).
1385 If @srcSize > sum(sequence.length), the remaining bytes are considered all literals
1386 If a dictionary is included, then the cctx should reference the dict (see: ZSTD_CCtx_refCDict(), ZSTD_CCtx_loadDictionary(), etc.).
1387 The entire source is compressed into a single frame.
1388
1389 The compression behavior changes based on cctx params. In particular:
1390    If ZSTD_c_blockDelimiters == ZSTD_sf_noBlockDelimiters, the array of ZSTD_Sequence is expected to contain
1391    no block delimiters (defined in ZSTD_Sequence). Block boundaries are roughly determined based on
1392    the block size derived from the cctx, and sequences may be split. This is the default setting.
1393
1394    If ZSTD_c_blockDelimiters == ZSTD_sf_explicitBlockDelimiters, the array of ZSTD_Sequence is expected to contain
1395    valid block delimiters (defined in ZSTD_Sequence). Behavior is undefined if no block delimiters are provided.
1396
1397    When ZSTD_c_blockDelimiters == ZSTD_sf_explicitBlockDelimiters, it's possible to decide generating repcodes
1398    using the advanced parameter ZSTD_c_repcodeResolution. Repcodes will improve compression ratio, though the benefit
1399    can vary greatly depending on Sequences. On the other hand, repcode resolution is an expensive operation.
1400    By default, it's disabled at low (<10) compression levels, and enabled above the threshold (>=10).
1401    ZSTD_c_repcodeResolution makes it possible to directly manage this processing in either direction.
1402
1403    If ZSTD_c_validateSequences == 0, this function blindly accepts the Sequences provided. Invalid Sequences cause undefined
1404    behavior. If ZSTD_c_validateSequences == 1, then the function will detect invalid Sequences (see doc/zstd_compression_format.md for
1405    specifics regarding offset/matchlength requirements) and then bail out and return an error.
1406
1407    In addition to the two adjustable experimental params, there are other important cctx params.
1408    - ZSTD_c_minMatch MUST be set as less than or equal to the smallest match generated by the match finder. It has a minimum value of ZSTD_MINMATCH_MIN.
1409    - ZSTD_c_compressionLevel accordingly adjusts the strength of the entropy coder, as it would in typical compression.
1410    - ZSTD_c_windowLog affects offset validation: this function will return an error at higher debug levels if a provided offset
1411      is larger than what the spec allows for a given window log and dictionary (if present). See: doc/zstd_compression_format.md
1412
1413 Note: Repcodes are, as of now, always re-calculated within this function, ZSTD_Sequence.rep is effectively unused.
1414 Dev Note: Once ability to ingest repcodes become available, the explicit block delims mode must respect those repcodes exactly,
1415         and cannot emit an RLE block that disagrees with the repcode history.
1416 @return : final compressed size, or a ZSTD error code.
1417
1418</p></pre><BR>
1419
1420<pre><b>ZSTDLIB_STATIC_API size_t
1421ZSTD_compressSequencesAndLiterals(ZSTD_CCtx* cctx,
1422                      void* dst, size_t dstCapacity,
1423                const ZSTD_Sequence* inSeqs, size_t nbSequences,
1424                const void* literals, size_t litSize, size_t litCapacity,
1425                size_t decompressedSize);
1426</b><p> This is a variant of ZSTD_compressSequences() which,
1427 instead of receiving (src,srcSize) as input parameter, receives (literals,litSize),
1428 aka all the literals, already extracted and laid out into a single continuous buffer.
1429 This can be useful if the process generating the sequences also happens to generate the buffer of literals,
1430 thus skipping an extraction + caching stage.
1431 It's a speed optimization, useful when the right conditions are met,
1432 but it also features the following limitations:
1433 - Only supports explicit delimiter mode
1434 - Currently does not support Sequences validation (so input Sequences are trusted)
1435 - Not compatible with frame checksum, which must be disabled
1436 - If any block is incompressible, will fail and return an error
1437 - @litSize must be == sum of all @.litLength fields in @inSeqs. Any discrepancy will generate an error.
1438 - the buffer @literals must have a size @litCapacity which is larger than @litSize by at least 8 bytes.
1439 - @decompressedSize must be correct, and correspond to the sum of all Sequences. Any discrepancy will generate an error.
1440 @return : final compressed size, or a ZSTD error code.
1441
1442</p></pre><BR>
1443
1444<pre><b>ZSTDLIB_STATIC_API size_t ZSTD_writeSkippableFrame(void* dst, size_t dstCapacity,
1445                                const void* src, size_t srcSize, unsigned magicVariant);
1446</b><p> Generates a zstd skippable frame containing data given by src, and writes it to dst buffer.
1447
1448 Skippable frames begin with a 4-byte magic number. There are 16 possible choices of magic number,
1449 ranging from ZSTD_MAGIC_SKIPPABLE_START to ZSTD_MAGIC_SKIPPABLE_START+15.
1450 As such, the parameter magicVariant controls the exact skippable frame magic number variant used, so
1451 the magic number used will be ZSTD_MAGIC_SKIPPABLE_START + magicVariant.
1452
1453 Returns an error if destination buffer is not large enough, if the source size is not representable
1454 with a 4-byte unsigned int, or if the parameter magicVariant is greater than 15 (and therefore invalid).
1455
1456 @return : number of bytes written or a ZSTD error.
1457
1458</p></pre><BR>
1459
1460<pre><b>size_t ZSTD_readSkippableFrame(void* dst, size_t dstCapacity, unsigned* magicVariant,
1461                                const void* src, size_t srcSize);
1462</b><p> Retrieves a zstd skippable frame containing data given by src, and writes it to dst buffer.
1463
1464 The parameter magicVariant will receive the magicVariant that was supplied when the frame was written,
1465 i.e. magicNumber - ZSTD_MAGIC_SKIPPABLE_START.  This can be NULL if the caller is not interested
1466 in the magicVariant.
1467
1468 Returns an error if destination buffer is not large enough, or if the frame is not skippable.
1469
1470 @return : number of bytes written or a ZSTD error.
1471
1472</p></pre><BR>
1473
1474<pre><b>unsigned ZSTD_isSkippableFrame(const void* buffer, size_t size);
1475</b><p>  Tells if the content of `buffer` starts with a valid Frame Identifier for a skippable frame.
1476
1477</p></pre><BR>
1478
1479<a name="Chapter16"></a><h2>Memory management</h2><pre></pre>
1480
1481<pre><b>ZSTDLIB_STATIC_API size_t ZSTD_estimateCCtxSize(int maxCompressionLevel);
1482ZSTDLIB_STATIC_API size_t ZSTD_estimateCCtxSize_usingCParams(ZSTD_compressionParameters cParams);
1483ZSTDLIB_STATIC_API size_t ZSTD_estimateCCtxSize_usingCCtxParams(const ZSTD_CCtx_params* params);
1484ZSTDLIB_STATIC_API size_t ZSTD_estimateDCtxSize(void);
1485</b><p>  These functions make it possible to estimate memory usage
1486  of a future {D,C}Ctx, before its creation.
1487  This is useful in combination with ZSTD_initStatic(),
1488  which makes it possible to employ a static buffer for ZSTD_CCtx* state.
1489
1490  ZSTD_estimateCCtxSize() will provide a memory budget large enough
1491  to compress data of any size using one-shot compression ZSTD_compressCCtx() or ZSTD_compress2()
1492  associated with any compression level up to max specified one.
1493  The estimate will assume the input may be arbitrarily large,
1494  which is the worst case.
1495
1496  Note that the size estimation is specific for one-shot compression,
1497  it is not valid for streaming (see ZSTD_estimateCStreamSize*())
1498  nor other potential ways of using a ZSTD_CCtx* state.
1499
1500  When srcSize can be bound by a known and rather "small" value,
1501  this knowledge can be used to provide a tighter budget estimation
1502  because the ZSTD_CCtx* state will need less memory for small inputs.
1503  This tighter estimation can be provided by employing more advanced functions
1504  ZSTD_estimateCCtxSize_usingCParams(), which can be used in tandem with ZSTD_getCParams(),
1505  and ZSTD_estimateCCtxSize_usingCCtxParams(), which can be used in tandem with ZSTD_CCtxParams_setParameter().
1506  Both can be used to estimate memory using custom compression parameters and arbitrary srcSize limits.
1507
1508  Note : only single-threaded compression is supported.
1509  ZSTD_estimateCCtxSize_usingCCtxParams() will return an error code if ZSTD_c_nbWorkers is >= 1.
1510
1511</p></pre><BR>
1512
1513<pre><b>ZSTDLIB_STATIC_API size_t ZSTD_estimateCStreamSize(int maxCompressionLevel);
1514ZSTDLIB_STATIC_API size_t ZSTD_estimateCStreamSize_usingCParams(ZSTD_compressionParameters cParams);
1515ZSTDLIB_STATIC_API size_t ZSTD_estimateCStreamSize_usingCCtxParams(const ZSTD_CCtx_params* params);
1516ZSTDLIB_STATIC_API size_t ZSTD_estimateDStreamSize(size_t maxWindowSize);
1517ZSTDLIB_STATIC_API size_t ZSTD_estimateDStreamSize_fromFrame(const void* src, size_t srcSize);
1518</b><p>  ZSTD_estimateCStreamSize() will provide a memory budget large enough for streaming compression
1519  using any compression level up to the max specified one.
1520  It will also consider src size to be arbitrarily "large", which is a worst case scenario.
1521  If srcSize is known to always be small, ZSTD_estimateCStreamSize_usingCParams() can provide a tighter estimation.
1522  ZSTD_estimateCStreamSize_usingCParams() can be used in tandem with ZSTD_getCParams() to create cParams from compressionLevel.
1523  ZSTD_estimateCStreamSize_usingCCtxParams() can be used in tandem with ZSTD_CCtxParams_setParameter(). Only single-threaded compression is supported. This function will return an error code if ZSTD_c_nbWorkers is >= 1.
1524  Note : CStream size estimation is only correct for single-threaded compression.
1525  ZSTD_estimateCStreamSize_usingCCtxParams() will return an error code if ZSTD_c_nbWorkers is >= 1.
1526  Note 2 : ZSTD_estimateCStreamSize* functions are not compatible with the Block-Level Sequence Producer API at this time.
1527  Size estimates assume that no external sequence producer is registered.
1528
1529  ZSTD_DStream memory budget depends on frame's window Size.
1530  This information can be passed manually, using ZSTD_estimateDStreamSize,
1531  or deducted from a valid frame Header, using ZSTD_estimateDStreamSize_fromFrame();
1532  Any frame requesting a window size larger than max specified one will be rejected.
1533  Note : if streaming is init with function ZSTD_init?Stream_usingDict(),
1534         an internal ?Dict will be created, which additional size is not estimated here.
1535         In this case, get total size by adding ZSTD_estimate?DictSize
1536
1537</p></pre><BR>
1538
1539<pre><b>ZSTDLIB_STATIC_API size_t ZSTD_estimateCDictSize(size_t dictSize, int compressionLevel);
1540ZSTDLIB_STATIC_API size_t ZSTD_estimateCDictSize_advanced(size_t dictSize, ZSTD_compressionParameters cParams, ZSTD_dictLoadMethod_e dictLoadMethod);
1541ZSTDLIB_STATIC_API size_t ZSTD_estimateDDictSize(size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod);
1542</b><p>  ZSTD_estimateCDictSize() will bet that src size is relatively "small", and content is copied, like ZSTD_createCDict().
1543  ZSTD_estimateCDictSize_advanced() makes it possible to control compression parameters precisely, like ZSTD_createCDict_advanced().
1544  Note : dictionaries created by reference (`ZSTD_dlm_byRef`) are logically smaller.
1545
1546</p></pre><BR>
1547
1548<pre><b>ZSTDLIB_STATIC_API ZSTD_CCtx*    ZSTD_initStaticCCtx(void* workspace, size_t workspaceSize);
1549ZSTDLIB_STATIC_API ZSTD_CStream* ZSTD_initStaticCStream(void* workspace, size_t workspaceSize);    </b>/**< same as ZSTD_initStaticCCtx() */<b>
1550</b><p>  Initialize an object using a pre-allocated fixed-size buffer.
1551  workspace: The memory area to emplace the object into.
1552             Provided pointer *must be 8-bytes aligned*.
1553             Buffer must outlive object.
1554  workspaceSize: Use ZSTD_estimate*Size() to determine
1555                 how large workspace must be to support target scenario.
1556 @return : pointer to object (same address as workspace, just different type),
1557           or NULL if error (size too small, incorrect alignment, etc.)
1558  Note : zstd will never resize nor malloc() when using a static buffer.
1559         If the object requires more memory than available,
1560         zstd will just error out (typically ZSTD_error_memory_allocation).
1561  Note 2 : there is no corresponding "free" function.
1562           Since workspace is allocated externally, it must be freed externally too.
1563  Note 3 : cParams : use ZSTD_getCParams() to convert a compression level
1564           into its associated cParams.
1565  Limitation 1 : currently not compatible with internal dictionary creation, triggered by
1566                 ZSTD_CCtx_loadDictionary(), ZSTD_initCStream_usingDict() or ZSTD_initDStream_usingDict().
1567  Limitation 2 : static cctx currently not compatible with multi-threading.
1568  Limitation 3 : static dctx is incompatible with legacy support.
1569
1570</p></pre><BR>
1571
1572<pre><b>ZSTDLIB_STATIC_API ZSTD_DStream* ZSTD_initStaticDStream(void* workspace, size_t workspaceSize);    </b>/**< same as ZSTD_initStaticDCtx() */<b>
1573</b></pre><BR>
1574<pre><b>typedef void* (*ZSTD_allocFunction) (void* opaque, size_t size);
1575typedef void  (*ZSTD_freeFunction) (void* opaque, void* address);
1576typedef struct { ZSTD_allocFunction customAlloc; ZSTD_freeFunction customFree; void* opaque; } ZSTD_customMem;
1577static
1578#ifdef __GNUC__
1579__attribute__((__unused__))
1580#endif
1581</b><p>  These prototypes make it possible to pass your own allocation/free functions.
1582  ZSTD_customMem is provided at creation time, using ZSTD_create*_advanced() variants listed below.
1583  All allocation/free operations will be completed using these custom variants instead of regular <stdlib.h> ones.
1584
1585</p></pre><BR>
1586
1587<pre><b>ZSTD_customMem const ZSTD_defaultCMem = { NULL, NULL, NULL };  </b>/**< this constant defers to stdlib's functions */<b>
1588</b></pre><BR>
1589<pre><b>typedef struct POOL_ctx_s ZSTD_threadPool;
1590ZSTDLIB_STATIC_API ZSTD_threadPool* ZSTD_createThreadPool(size_t numThreads);
1591ZSTDLIB_STATIC_API void ZSTD_freeThreadPool (ZSTD_threadPool* pool);  </b>/* accept NULL pointer */<b>
1592ZSTDLIB_STATIC_API size_t ZSTD_CCtx_refThreadPool(ZSTD_CCtx* cctx, ZSTD_threadPool* pool);
1593</b><p>  These prototypes make it possible to share a thread pool among multiple compression contexts.
1594  This can limit resources for applications with multiple threads where each one uses
1595  a threaded compression mode (via ZSTD_c_nbWorkers parameter).
1596  ZSTD_createThreadPool creates a new thread pool with a given number of threads.
1597  Note that the lifetime of such pool must exist while being used.
1598  ZSTD_CCtx_refThreadPool assigns a thread pool to a context (use NULL argument value
1599  to use an internal thread pool).
1600  ZSTD_freeThreadPool frees a thread pool, accepts NULL pointer.
1601
1602</p></pre><BR>
1603
1604<a name="Chapter17"></a><h2>Advanced compression functions</h2><pre></pre>
1605
1606<pre><b>ZSTDLIB_STATIC_API ZSTD_CDict* ZSTD_createCDict_byReference(const void* dictBuffer, size_t dictSize, int compressionLevel);
1607</b><p>  Create a digested dictionary for compression
1608  Dictionary content is just referenced, not duplicated.
1609  As a consequence, `dictBuffer` **must** outlive CDict,
1610  and its content must remain unmodified throughout the lifetime of CDict.
1611  note: equivalent to ZSTD_createCDict_advanced(), with dictLoadMethod==ZSTD_dlm_byRef
1612</p></pre><BR>
1613
1614<pre><b>ZSTDLIB_STATIC_API ZSTD_compressionParameters ZSTD_getCParams(int compressionLevel, unsigned long long estimatedSrcSize, size_t dictSize);
1615</b><p> @return ZSTD_compressionParameters structure for a selected compression level and estimated srcSize.
1616 `estimatedSrcSize` value is optional, select 0 if not known
1617</p></pre><BR>
1618
1619<pre><b>ZSTDLIB_STATIC_API ZSTD_parameters ZSTD_getParams(int compressionLevel, unsigned long long estimatedSrcSize, size_t dictSize);
1620</b><p>  same as ZSTD_getCParams(), but @return a full `ZSTD_parameters` object instead of sub-component `ZSTD_compressionParameters`.
1621  All fields of `ZSTD_frameParameters` are set to default : contentSize=1, checksum=0, noDictID=0
1622</p></pre><BR>
1623
1624<pre><b>ZSTDLIB_STATIC_API size_t ZSTD_checkCParams(ZSTD_compressionParameters params);
1625</b><p>  Ensure param values remain within authorized range.
1626 @return 0 on success, or an error code (can be checked with ZSTD_isError())
1627</p></pre><BR>
1628
1629<pre><b>ZSTDLIB_STATIC_API ZSTD_compressionParameters ZSTD_adjustCParams(ZSTD_compressionParameters cPar, unsigned long long srcSize, size_t dictSize);
1630</b><p>  optimize params for a given `srcSize` and `dictSize`.
1631 `srcSize` can be unknown, in which case use ZSTD_CONTENTSIZE_UNKNOWN.
1632 `dictSize` must be `0` when there is no dictionary.
1633  cPar can be invalid : all parameters will be clamped within valid range in the @return struct.
1634  This function never fails (wide contract)
1635</p></pre><BR>
1636
1637<pre><b>ZSTDLIB_STATIC_API size_t ZSTD_CCtx_setCParams(ZSTD_CCtx* cctx, ZSTD_compressionParameters cparams);
1638</b><p>  Set all parameters provided within @p cparams into the working @p cctx.
1639  Note : if modifying parameters during compression (MT mode only),
1640         note that changes to the .windowLog parameter will be ignored.
1641 @return 0 on success, or an error code (can be checked with ZSTD_isError()).
1642         On failure, no parameters are updated.
1643
1644</p></pre><BR>
1645
1646<pre><b>ZSTDLIB_STATIC_API size_t ZSTD_CCtx_setFParams(ZSTD_CCtx* cctx, ZSTD_frameParameters fparams);
1647</b><p>  Set all parameters provided within @p fparams into the working @p cctx.
1648 @return 0 on success, or an error code (can be checked with ZSTD_isError()).
1649
1650</p></pre><BR>
1651
1652<pre><b>ZSTDLIB_STATIC_API size_t ZSTD_CCtx_setParams(ZSTD_CCtx* cctx, ZSTD_parameters params);
1653</b><p>  Set all parameters provided within @p params into the working @p cctx.
1654 @return 0 on success, or an error code (can be checked with ZSTD_isError()).
1655
1656</p></pre><BR>
1657
1658<pre><b>ZSTD_DEPRECATED("use ZSTD_compress2")
1659ZSTDLIB_STATIC_API
1660size_t ZSTD_compress_advanced(ZSTD_CCtx* cctx,
1661                  void* dst, size_t dstCapacity,
1662            const void* src, size_t srcSize,
1663            const void* dict,size_t dictSize,
1664                  ZSTD_parameters params);
1665</b><p>  Note : this function is now DEPRECATED.
1666         It can be replaced by ZSTD_compress2(), in combination with ZSTD_CCtx_setParameter() and other parameter setters.
1667  This prototype will generate compilation warnings.
1668</p></pre><BR>
1669
1670<pre><b>ZSTD_DEPRECATED("use ZSTD_compress2 with ZSTD_CCtx_loadDictionary")
1671ZSTDLIB_STATIC_API
1672size_t ZSTD_compress_usingCDict_advanced(ZSTD_CCtx* cctx,
1673                                  void* dst, size_t dstCapacity,
1674                            const void* src, size_t srcSize,
1675                            const ZSTD_CDict* cdict,
1676                                  ZSTD_frameParameters fParams);
1677</b><p>  Note : this function is now DEPRECATED.
1678         It can be replaced by ZSTD_compress2(), in combination with ZSTD_CCtx_loadDictionary() and other parameter setters.
1679  This prototype will generate compilation warnings.
1680</p></pre><BR>
1681
1682<pre><b>ZSTDLIB_STATIC_API size_t ZSTD_CCtx_loadDictionary_byReference(ZSTD_CCtx* cctx, const void* dict, size_t dictSize);
1683</b><p>  Same as ZSTD_CCtx_loadDictionary(), but dictionary content is referenced, instead of being copied into CCtx.
1684  It saves some memory, but also requires that `dict` outlives its usage within `cctx`
1685</p></pre><BR>
1686
1687<pre><b>ZSTDLIB_STATIC_API size_t ZSTD_CCtx_loadDictionary_advanced(ZSTD_CCtx* cctx, const void* dict, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictContentType_e dictContentType);
1688</b><p>  Same as ZSTD_CCtx_loadDictionary(), but gives finer control over
1689  how to load the dictionary (by copy ? by reference ?)
1690  and how to interpret it (automatic ? force raw mode ? full mode only ?)
1691</p></pre><BR>
1692
1693<pre><b>ZSTDLIB_STATIC_API size_t ZSTD_CCtx_refPrefix_advanced(ZSTD_CCtx* cctx, const void* prefix, size_t prefixSize, ZSTD_dictContentType_e dictContentType);
1694</b><p>  Same as ZSTD_CCtx_refPrefix(), but gives finer control over
1695  how to interpret prefix content (automatic ? force raw mode (default) ? full mode only ?)
1696</p></pre><BR>
1697
1698<pre><b>ZSTDLIB_STATIC_API size_t ZSTD_CCtx_getParameter(const ZSTD_CCtx* cctx, ZSTD_cParameter param, int* value);
1699</b><p>  Get the requested compression parameter value, selected by enum ZSTD_cParameter,
1700  and store it into int* value.
1701 @return : 0, or an error code (which can be tested with ZSTD_isError()).
1702
1703</p></pre><BR>
1704
1705<pre><b>ZSTDLIB_STATIC_API ZSTD_CCtx_params* ZSTD_createCCtxParams(void);
1706ZSTDLIB_STATIC_API size_t ZSTD_freeCCtxParams(ZSTD_CCtx_params* params);  </b>/* accept NULL pointer */<b>
1707</b><p>  Quick howto :
1708  - ZSTD_createCCtxParams() : Create a ZSTD_CCtx_params structure
1709  - ZSTD_CCtxParams_setParameter() : Push parameters one by one into
1710                                     an existing ZSTD_CCtx_params structure.
1711                                     This is similar to
1712                                     ZSTD_CCtx_setParameter().
1713  - ZSTD_CCtx_setParametersUsingCCtxParams() : Apply parameters to
1714                                    an existing CCtx.
1715                                    These parameters will be applied to
1716                                    all subsequent frames.
1717  - ZSTD_compressStream2() : Do compression using the CCtx.
1718  - ZSTD_freeCCtxParams() : Free the memory, accept NULL pointer.
1719
1720  This can be used with ZSTD_estimateCCtxSize_advanced_usingCCtxParams()
1721  for static allocation of CCtx for single-threaded compression.
1722
1723</p></pre><BR>
1724
1725<pre><b>ZSTDLIB_STATIC_API size_t ZSTD_CCtxParams_reset(ZSTD_CCtx_params* params);
1726</b><p>  Reset params to default values.
1727
1728</p></pre><BR>
1729
1730<pre><b>ZSTDLIB_STATIC_API size_t ZSTD_CCtxParams_init(ZSTD_CCtx_params* cctxParams, int compressionLevel);
1731</b><p>  Initializes the compression parameters of cctxParams according to
1732  compression level. All other parameters are reset to their default values.
1733
1734</p></pre><BR>
1735
1736<pre><b>ZSTDLIB_STATIC_API size_t ZSTD_CCtxParams_init_advanced(ZSTD_CCtx_params* cctxParams, ZSTD_parameters params);
1737</b><p>  Initializes the compression and frame parameters of cctxParams according to
1738  params. All other parameters are reset to their default values.
1739
1740</p></pre><BR>
1741
1742<pre><b>ZSTDLIB_STATIC_API size_t ZSTD_CCtxParams_setParameter(ZSTD_CCtx_params* params, ZSTD_cParameter param, int value);
1743</b><p>  Similar to ZSTD_CCtx_setParameter.
1744  Set one compression parameter, selected by enum ZSTD_cParameter.
1745  Parameters must be applied to a ZSTD_CCtx using
1746  ZSTD_CCtx_setParametersUsingCCtxParams().
1747 @result : a code representing success or failure (which can be tested with
1748           ZSTD_isError()).
1749
1750</p></pre><BR>
1751
1752<pre><b>ZSTDLIB_STATIC_API size_t ZSTD_CCtxParams_getParameter(const ZSTD_CCtx_params* params, ZSTD_cParameter param, int* value);
1753</b><p> Similar to ZSTD_CCtx_getParameter.
1754 Get the requested value of one compression parameter, selected by enum ZSTD_cParameter.
1755 @result : 0, or an error code (which can be tested with ZSTD_isError()).
1756
1757</p></pre><BR>
1758
1759<pre><b>ZSTDLIB_STATIC_API size_t ZSTD_CCtx_setParametersUsingCCtxParams(
1760        ZSTD_CCtx* cctx, const ZSTD_CCtx_params* params);
1761</b><p>  Apply a set of ZSTD_CCtx_params to the compression context.
1762  This can be done even after compression is started,
1763    if nbWorkers==0, this will have no impact until a new compression is started.
1764    if nbWorkers>=1, new parameters will be picked up at next job,
1765       with a few restrictions (windowLog, pledgedSrcSize, nbWorkers, jobSize, and overlapLog are not updated).
1766
1767</p></pre><BR>
1768
1769<pre><b>ZSTDLIB_STATIC_API size_t ZSTD_compressStream2_simpleArgs (
1770                ZSTD_CCtx* cctx,
1771                void* dst, size_t dstCapacity, size_t* dstPos,
1772          const void* src, size_t srcSize, size_t* srcPos,
1773                ZSTD_EndDirective endOp);
1774</b><p>  Same as ZSTD_compressStream2(),
1775  but using only integral types as arguments.
1776  This variant might be helpful for binders from dynamic languages
1777  which have troubles handling structures containing memory pointers.
1778
1779</p></pre><BR>
1780
1781<a name="Chapter18"></a><h2>Advanced decompression functions</h2><pre></pre>
1782
1783<pre><b>ZSTDLIB_STATIC_API unsigned ZSTD_isFrame(const void* buffer, size_t size);
1784</b><p>  Tells if the content of `buffer` starts with a valid Frame Identifier.
1785  Note : Frame Identifier is 4 bytes. If `size < 4`, @return will always be 0.
1786  Note 2 : Legacy Frame Identifiers are considered valid only if Legacy Support is enabled.
1787  Note 3 : Skippable Frame Identifiers are considered valid.
1788</p></pre><BR>
1789
1790<pre><b>ZSTDLIB_STATIC_API ZSTD_DDict* ZSTD_createDDict_byReference(const void* dictBuffer, size_t dictSize);
1791</b><p>  Create a digested dictionary, ready to start decompression operation without startup delay.
1792  Dictionary content is referenced, and therefore stays in dictBuffer.
1793  It is important that dictBuffer outlives DDict,
1794  it must remain read accessible throughout the lifetime of DDict
1795</p></pre><BR>
1796
1797<pre><b>ZSTDLIB_STATIC_API size_t ZSTD_DCtx_loadDictionary_byReference(ZSTD_DCtx* dctx, const void* dict, size_t dictSize);
1798</b><p>  Same as ZSTD_DCtx_loadDictionary(),
1799  but references `dict` content instead of copying it into `dctx`.
1800  This saves memory if `dict` remains around.,
1801  However, it's imperative that `dict` remains accessible (and unmodified) while being used, so it must outlive decompression.
1802</p></pre><BR>
1803
1804<pre><b>ZSTDLIB_STATIC_API size_t ZSTD_DCtx_loadDictionary_advanced(ZSTD_DCtx* dctx, const void* dict, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictContentType_e dictContentType);
1805</b><p>  Same as ZSTD_DCtx_loadDictionary(),
1806  but gives direct control over
1807  how to load the dictionary (by copy ? by reference ?)
1808  and how to interpret it (automatic ? force raw mode ? full mode only ?).
1809</p></pre><BR>
1810
1811<pre><b>ZSTDLIB_STATIC_API size_t ZSTD_DCtx_refPrefix_advanced(ZSTD_DCtx* dctx, const void* prefix, size_t prefixSize, ZSTD_dictContentType_e dictContentType);
1812</b><p>  Same as ZSTD_DCtx_refPrefix(), but gives finer control over
1813  how to interpret prefix content (automatic ? force raw mode (default) ? full mode only ?)
1814</p></pre><BR>
1815
1816<pre><b>ZSTDLIB_STATIC_API size_t ZSTD_DCtx_setMaxWindowSize(ZSTD_DCtx* dctx, size_t maxWindowSize);
1817</b><p>  Refuses allocating internal buffers for frames requiring a window size larger than provided limit.
1818  This protects a decoder context from reserving too much memory for itself (potential attack scenario).
1819  This parameter is only useful in streaming mode, since no internal buffer is allocated in single-pass mode.
1820  By default, a decompression context accepts all window sizes <= (1 << ZSTD_WINDOWLOG_LIMIT_DEFAULT)
1821 @return : 0, or an error code (which can be tested using ZSTD_isError()).
1822
1823</p></pre><BR>
1824
1825<pre><b>ZSTDLIB_STATIC_API size_t ZSTD_DCtx_getParameter(ZSTD_DCtx* dctx, ZSTD_dParameter param, int* value);
1826</b><p>  Get the requested decompression parameter value, selected by enum ZSTD_dParameter,
1827  and store it into int* value.
1828 @return : 0, or an error code (which can be tested with ZSTD_isError()).
1829
1830</p></pre><BR>
1831
1832<pre><b>ZSTD_DEPRECATED("use ZSTD_DCtx_setParameter() instead")
1833ZSTDLIB_STATIC_API
1834size_t ZSTD_DCtx_setFormat(ZSTD_DCtx* dctx, ZSTD_format_e format);
1835</b><p>  This function is REDUNDANT. Prefer ZSTD_DCtx_setParameter().
1836  Instruct the decoder context about what kind of data to decode next.
1837  This instruction is mandatory to decode data without a fully-formed header,
1838  such ZSTD_f_zstd1_magicless for example.
1839 @return : 0, or an error code (which can be tested using ZSTD_isError()).
1840</p></pre><BR>
1841
1842<pre><b>ZSTDLIB_STATIC_API size_t ZSTD_decompressStream_simpleArgs (
1843                ZSTD_DCtx* dctx,
1844                void* dst, size_t dstCapacity, size_t* dstPos,
1845          const void* src, size_t srcSize, size_t* srcPos);
1846</b><p>  Same as ZSTD_decompressStream(),
1847  but using only integral types as arguments.
1848  This can be helpful for binders from dynamic languages
1849  which have troubles handling structures containing memory pointers.
1850
1851</p></pre><BR>
1852
1853<a name="Chapter19"></a><h2>Advanced streaming functions</h2><pre>  Warning : most of these functions are now redundant with the Advanced API.
1854  Once Advanced API reaches "stable" status,
1855  redundant functions will be deprecated, and then at some point removed.
1856<BR></pre>
1857
1858<h3>Advanced Streaming compression functions</h3><pre></pre><b><pre></pre></b><BR>
1859<pre><b>ZSTD_DEPRECATED("use ZSTD_CCtx_reset, see zstd.h for detailed instructions")
1860ZSTDLIB_STATIC_API
1861size_t ZSTD_initCStream_srcSize(ZSTD_CStream* zcs,
1862             int compressionLevel,
1863             unsigned long long pledgedSrcSize);
1864</b><p> This function is DEPRECATED, and equivalent to:
1865     ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
1866     ZSTD_CCtx_refCDict(zcs, NULL); // clear the dictionary (if any)
1867     ZSTD_CCtx_setParameter(zcs, ZSTD_c_compressionLevel, compressionLevel);
1868     ZSTD_CCtx_setPledgedSrcSize(zcs, pledgedSrcSize);
1869
1870 pledgedSrcSize must be correct. If it is not known at init time, use
1871 ZSTD_CONTENTSIZE_UNKNOWN. Note that, for compatibility with older programs,
1872 "0" also disables frame content size field. It may be enabled in the future.
1873 This prototype will generate compilation warnings.
1874
1875</p></pre><BR>
1876
1877<pre><b>ZSTD_DEPRECATED("use ZSTD_CCtx_reset, see zstd.h for detailed instructions")
1878ZSTDLIB_STATIC_API
1879size_t ZSTD_initCStream_usingDict(ZSTD_CStream* zcs,
1880         const void* dict, size_t dictSize,
1881               int compressionLevel);
1882</b><p> This function is DEPRECATED, and is equivalent to:
1883     ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
1884     ZSTD_CCtx_setParameter(zcs, ZSTD_c_compressionLevel, compressionLevel);
1885     ZSTD_CCtx_loadDictionary(zcs, dict, dictSize);
1886
1887 Creates of an internal CDict (incompatible with static CCtx), except if
1888 dict == NULL or dictSize < 8, in which case no dict is used.
1889 Note: dict is loaded with ZSTD_dct_auto (treated as a full zstd dictionary if
1890 it begins with ZSTD_MAGIC_DICTIONARY, else as raw content) and ZSTD_dlm_byCopy.
1891 This prototype will generate compilation warnings.
1892
1893</p></pre><BR>
1894
1895<pre><b>ZSTD_DEPRECATED("use ZSTD_CCtx_reset, see zstd.h for detailed instructions")
1896ZSTDLIB_STATIC_API
1897size_t ZSTD_initCStream_advanced(ZSTD_CStream* zcs,
1898        const void* dict, size_t dictSize,
1899              ZSTD_parameters params,
1900              unsigned long long pledgedSrcSize);
1901</b><p> This function is DEPRECATED, and is equivalent to:
1902     ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
1903     ZSTD_CCtx_setParams(zcs, params);
1904     ZSTD_CCtx_setPledgedSrcSize(zcs, pledgedSrcSize);
1905     ZSTD_CCtx_loadDictionary(zcs, dict, dictSize);
1906
1907 dict is loaded with ZSTD_dct_auto and ZSTD_dlm_byCopy.
1908 pledgedSrcSize must be correct.
1909 If srcSize is not known at init time, use value ZSTD_CONTENTSIZE_UNKNOWN.
1910 This prototype will generate compilation warnings.
1911
1912</p></pre><BR>
1913
1914<pre><b>ZSTD_DEPRECATED("use ZSTD_CCtx_reset and ZSTD_CCtx_refCDict, see zstd.h for detailed instructions")
1915ZSTDLIB_STATIC_API
1916size_t ZSTD_initCStream_usingCDict(ZSTD_CStream* zcs, const ZSTD_CDict* cdict);
1917</b><p> This function is DEPRECATED, and equivalent to:
1918     ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
1919     ZSTD_CCtx_refCDict(zcs, cdict);
1920
1921 note : cdict will just be referenced, and must outlive compression session
1922 This prototype will generate compilation warnings.
1923
1924</p></pre><BR>
1925
1926<pre><b>ZSTD_DEPRECATED("use ZSTD_CCtx_reset and ZSTD_CCtx_refCDict, see zstd.h for detailed instructions")
1927ZSTDLIB_STATIC_API
1928size_t ZSTD_initCStream_usingCDict_advanced(ZSTD_CStream* zcs,
1929                   const ZSTD_CDict* cdict,
1930                         ZSTD_frameParameters fParams,
1931                         unsigned long long pledgedSrcSize);
1932</b><p>   This function is DEPRECATED, and is equivalent to:
1933     ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
1934     ZSTD_CCtx_setFParams(zcs, fParams);
1935     ZSTD_CCtx_setPledgedSrcSize(zcs, pledgedSrcSize);
1936     ZSTD_CCtx_refCDict(zcs, cdict);
1937
1938 same as ZSTD_initCStream_usingCDict(), with control over frame parameters.
1939 pledgedSrcSize must be correct. If srcSize is not known at init time, use
1940 value ZSTD_CONTENTSIZE_UNKNOWN.
1941 This prototype will generate compilation warnings.
1942
1943</p></pre><BR>
1944
1945<pre><b>ZSTD_DEPRECATED("use ZSTD_CCtx_reset, see zstd.h for detailed instructions")
1946ZSTDLIB_STATIC_API
1947size_t ZSTD_resetCStream(ZSTD_CStream* zcs, unsigned long long pledgedSrcSize);
1948</b><p> This function is DEPRECATED, and is equivalent to:
1949     ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
1950     ZSTD_CCtx_setPledgedSrcSize(zcs, pledgedSrcSize);
1951 Note: ZSTD_resetCStream() interprets pledgedSrcSize == 0 as ZSTD_CONTENTSIZE_UNKNOWN, but
1952       ZSTD_CCtx_setPledgedSrcSize() does not do the same, so ZSTD_CONTENTSIZE_UNKNOWN must be
1953       explicitly specified.
1954
1955  start a new frame, using same parameters from previous frame.
1956  This is typically useful to skip dictionary loading stage, since it will reuse it in-place.
1957  Note that zcs must be init at least once before using ZSTD_resetCStream().
1958  If pledgedSrcSize is not known at reset time, use macro ZSTD_CONTENTSIZE_UNKNOWN.
1959  If pledgedSrcSize > 0, its value must be correct, as it will be written in header, and controlled at the end.
1960  For the time being, pledgedSrcSize==0 is interpreted as "srcSize unknown" for compatibility with older programs,
1961  but it will change to mean "empty" in future version, so use macro ZSTD_CONTENTSIZE_UNKNOWN instead.
1962 @return : 0, or an error code (which can be tested using ZSTD_isError())
1963  This prototype will generate compilation warnings.
1964
1965</p></pre><BR>
1966
1967<pre><b>typedef struct {
1968    unsigned long long ingested;   </b>/* nb input bytes read and buffered */<b>
1969    unsigned long long consumed;   </b>/* nb input bytes actually compressed */<b>
1970    unsigned long long produced;   </b>/* nb of compressed bytes generated and buffered */<b>
1971    unsigned long long flushed;    </b>/* nb of compressed bytes flushed : not provided; can be tracked from caller side */<b>
1972    unsigned currentJobID;         </b>/* MT only : latest started job nb */<b>
1973    unsigned nbActiveWorkers;      </b>/* MT only : nb of workers actively compressing at probe time */<b>
1974} ZSTD_frameProgression;
1975</b></pre><BR>
1976<pre><b>ZSTDLIB_STATIC_API size_t ZSTD_toFlushNow(ZSTD_CCtx* cctx);
1977</b><p>  Tell how many bytes are ready to be flushed immediately.
1978  Useful for multithreading scenarios (nbWorkers >= 1).
1979  Probe the oldest active job, defined as oldest job not yet entirely flushed,
1980  and check its output buffer.
1981 @return : amount of data stored in oldest job and ready to be flushed immediately.
1982  if @return == 0, it means either :
1983  + there is no active job (could be checked with ZSTD_frameProgression()), or
1984  + oldest job is still actively compressing data,
1985    but everything it has produced has also been flushed so far,
1986    therefore flush speed is limited by production speed of oldest job
1987    irrespective of the speed of concurrent (and newer) jobs.
1988
1989</p></pre><BR>
1990
1991<h3>Advanced Streaming decompression functions</h3><pre></pre><b><pre></pre></b><BR>
1992<pre><b>ZSTD_DEPRECATED("use ZSTD_DCtx_reset + ZSTD_DCtx_loadDictionary, see zstd.h for detailed instructions")
1993ZSTDLIB_STATIC_API size_t ZSTD_initDStream_usingDict(ZSTD_DStream* zds, const void* dict, size_t dictSize);
1994</b><p>
1995     ZSTD_DCtx_reset(zds, ZSTD_reset_session_only);
1996     ZSTD_DCtx_loadDictionary(zds, dict, dictSize);
1997
1998 note: no dictionary will be used if dict == NULL or dictSize < 8
1999
2000</p></pre><BR>
2001
2002<pre><b>ZSTD_DEPRECATED("use ZSTD_DCtx_reset + ZSTD_DCtx_refDDict, see zstd.h for detailed instructions")
2003ZSTDLIB_STATIC_API size_t ZSTD_initDStream_usingDDict(ZSTD_DStream* zds, const ZSTD_DDict* ddict);
2004</b><p>
2005     ZSTD_DCtx_reset(zds, ZSTD_reset_session_only);
2006     ZSTD_DCtx_refDDict(zds, ddict);
2007
2008 note : ddict is referenced, it must outlive decompression session
2009
2010</p></pre><BR>
2011
2012<pre><b>ZSTD_DEPRECATED("use ZSTD_DCtx_reset, see zstd.h for detailed instructions")
2013ZSTDLIB_STATIC_API size_t ZSTD_resetDStream(ZSTD_DStream* zds);
2014</b><p>
2015     ZSTD_DCtx_reset(zds, ZSTD_reset_session_only);
2016
2017 reuse decompression parameters from previous init; saves dictionary loading
2018
2019</p></pre><BR>
2020
2021<pre><b>ZSTDLIB_STATIC_API void
2022ZSTD_registerSequenceProducer(
2023  ZSTD_CCtx* cctx,
2024  void* sequenceProducerState,
2025  ZSTD_sequenceProducer_F sequenceProducer
2026);
2027</b><p> Instruct zstd to use a block-level external sequence producer function.
2028
2029 The sequenceProducerState must be initialized by the caller, and the caller is
2030 responsible for managing its lifetime. This parameter is sticky across
2031 compressions. It will remain set until the user explicitly resets compression
2032 parameters.
2033
2034 Sequence producer registration is considered to be an "advanced parameter",
2035 part of the "advanced API". This means it will only have an effect on compression
2036 APIs which respect advanced parameters, such as compress2() and compressStream2().
2037 Older compression APIs such as compressCCtx(), which predate the introduction of
2038 "advanced parameters", will ignore any external sequence producer setting.
2039
2040 The sequence producer can be "cleared" by registering a NULL function pointer. This
2041 removes all limitations described above in the "LIMITATIONS" section of the API docs.
2042
2043 The user is strongly encouraged to read the full API documentation (above) before
2044 calling this function.
2045</p></pre><BR>
2046
2047<pre><b>ZSTDLIB_STATIC_API void
2048ZSTD_CCtxParams_registerSequenceProducer(
2049  ZSTD_CCtx_params* params,
2050  void* sequenceProducerState,
2051  ZSTD_sequenceProducer_F sequenceProducer
2052);
2053</b><p> Same as ZSTD_registerSequenceProducer(), but operates on ZSTD_CCtx_params.
2054 This is used for accurate size estimation with ZSTD_estimateCCtxSize_usingCCtxParams(),
2055 which is needed when creating a ZSTD_CCtx with ZSTD_initStaticCCtx().
2056
2057 If you are using the external sequence producer API in a scenario where ZSTD_initStaticCCtx()
2058 is required, then this function is for you. Otherwise, you probably don't need it.
2059
2060 See tests/zstreamtest.c for example usage.
2061</p></pre><BR>
2062
2063<a name="Chapter20"></a><h2>Buffer-less and synchronous inner streaming functions (DEPRECATED)</h2><pre>
2064  This API is deprecated, and will be removed in a future version.
2065  It allows streaming (de)compression with user allocated buffers.
2066  However, it is hard to use, and not as well tested as the rest of
2067  our API.
2068
2069  Please use the normal streaming API instead: ZSTD_compressStream2,
2070  and ZSTD_decompressStream.
2071  If there is functionality that you need, but it doesn't provide,
2072  please open an issue on our GitHub.
2073
2074<BR></pre>
2075
2076<a name="Chapter21"></a><h2>Buffer-less streaming compression (synchronous mode)</h2><pre>
2077  A ZSTD_CCtx object is required to track streaming operations.
2078  Use ZSTD_createCCtx() / ZSTD_freeCCtx() to manage resource.
2079  ZSTD_CCtx object can be reused multiple times within successive compression operations.
2080
2081  Start by initializing a context.
2082  Use ZSTD_compressBegin(), or ZSTD_compressBegin_usingDict() for dictionary compression.
2083
2084  Then, consume your input using ZSTD_compressContinue().
2085  There are some important considerations to keep in mind when using this advanced function :
2086  - ZSTD_compressContinue() has no internal buffer. It uses externally provided buffers only.
2087  - Interface is synchronous : input is consumed entirely and produces 1+ compressed blocks.
2088  - Caller must ensure there is enough space in `dst` to store compressed data under worst case scenario.
2089    Worst case evaluation is provided by ZSTD_compressBound().
2090    ZSTD_compressContinue() doesn't guarantee recover after a failed compression.
2091  - ZSTD_compressContinue() presumes prior input ***is still accessible and unmodified*** (up to maximum distance size, see WindowLog).
2092    It remembers all previous contiguous blocks, plus one separated memory segment (which can itself consists of multiple contiguous blocks)
2093  - ZSTD_compressContinue() detects that prior input has been overwritten when `src` buffer overlaps.
2094    In which case, it will "discard" the relevant memory section from its history.
2095
2096  Finish a frame with ZSTD_compressEnd(), which will write the last block(s) and optional checksum.
2097  It's possible to use srcSize==0, in which case, it will write a final empty block to end the frame.
2098  Without last block mark, frames are considered unfinished (hence corrupted) by compliant decoders.
2099
2100  `ZSTD_CCtx` object can be reused (ZSTD_compressBegin()) to compress again.
2101<BR></pre>
2102
2103<h3>Buffer-less streaming compression functions</h3><pre></pre><b><pre>ZSTD_DEPRECATED("The buffer-less API is deprecated in favor of the normal streaming API. See docs.")
2104ZSTDLIB_STATIC_API size_t ZSTD_compressBegin(ZSTD_CCtx* cctx, int compressionLevel);
2105ZSTD_DEPRECATED("The buffer-less API is deprecated in favor of the normal streaming API. See docs.")
2106ZSTDLIB_STATIC_API size_t ZSTD_compressBegin_usingDict(ZSTD_CCtx* cctx, const void* dict, size_t dictSize, int compressionLevel);
2107ZSTD_DEPRECATED("The buffer-less API is deprecated in favor of the normal streaming API. See docs.")
2108ZSTDLIB_STATIC_API size_t ZSTD_compressBegin_usingCDict(ZSTD_CCtx* cctx, const ZSTD_CDict* cdict); </b>/**< note: fails if cdict==NULL */<b>
2109</pre></b><BR>
2110<pre><b>size_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>
2111</b></pre><BR>
2112<pre><b>size_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>
2113</b></pre><BR>
2114<a name="Chapter22"></a><h2>Buffer-less streaming decompression (synchronous mode)</h2><pre>
2115  A ZSTD_DCtx object is required to track streaming operations.
2116  Use ZSTD_createDCtx() / ZSTD_freeDCtx() to manage it.
2117  A ZSTD_DCtx object can be reused multiple times.
2118
2119  First typical operation is to retrieve frame parameters, using ZSTD_getFrameHeader().
2120  Frame header is extracted from the beginning of compressed frame, so providing only the frame's beginning is enough.
2121  Data fragment must be large enough to ensure successful decoding.
2122 `ZSTD_frameHeaderSize_max` bytes is guaranteed to always be large enough.
2123  result  : 0 : successful decoding, the `ZSTD_frameHeader` structure is correctly filled.
2124           >0 : `srcSize` is too small, please provide at least result bytes on next attempt.
2125           errorCode, which can be tested using ZSTD_isError().
2126
2127  It fills a ZSTD_FrameHeader structure with important information to correctly decode the frame,
2128  such as the dictionary ID, content size, or maximum back-reference distance (`windowSize`).
2129  Note that these values could be wrong, either because of data corruption, or because a 3rd party deliberately spoofs false information.
2130  As a consequence, check that values remain within valid application range.
2131  For example, do not allocate memory blindly, check that `windowSize` is within expectation.
2132  Each application can set its own limits, depending on local restrictions.
2133  For extended interoperability, it is recommended to support `windowSize` of at least 8 MB.
2134
2135  ZSTD_decompressContinue() needs previous data blocks during decompression, up to `windowSize` bytes.
2136  ZSTD_decompressContinue() is very sensitive to contiguity,
2137  if 2 blocks don't follow each other, make sure that either the compressor breaks contiguity at the same place,
2138  or that previous contiguous segment is large enough to properly handle maximum back-reference distance.
2139  There are multiple ways to guarantee this condition.
2140
2141  The most memory efficient way is to use a round buffer of sufficient size.
2142  Sufficient size is determined by invoking ZSTD_decodingBufferSize_min(),
2143  which can return an error code if required value is too large for current system (in 32-bits mode).
2144  In a round buffer methodology, ZSTD_decompressContinue() decompresses each block next to previous one,
2145  up to the moment there is not enough room left in the buffer to guarantee decoding another full block,
2146  which maximum size is provided in `ZSTD_frameHeader` structure, field `blockSizeMax`.
2147  At which point, decoding can resume from the beginning of the buffer.
2148  Note that already decoded data stored in the buffer should be flushed before being overwritten.
2149
2150  There are alternatives possible, for example using two or more buffers of size `windowSize` each, though they consume more memory.
2151
2152  Finally, if you control the compression process, you can also ignore all buffer size rules,
2153  as long as the encoder and decoder progress in "lock-step",
2154  aka use exactly the same buffer sizes, break contiguity at the same place, etc.
2155
2156  Once buffers are setup, start decompression, with ZSTD_decompressBegin().
2157  If decompression requires a dictionary, use ZSTD_decompressBegin_usingDict() or ZSTD_decompressBegin_usingDDict().
2158
2159  Then use ZSTD_nextSrcSizeToDecompress() and ZSTD_decompressContinue() alternatively.
2160  ZSTD_nextSrcSizeToDecompress() tells how many bytes to provide as 'srcSize' to ZSTD_decompressContinue().
2161  ZSTD_decompressContinue() requires this _exact_ amount of bytes, or it will fail.
2162
2163  result of ZSTD_decompressContinue() is the number of bytes regenerated within 'dst' (necessarily <= dstCapacity).
2164  It can be zero : it just means ZSTD_decompressContinue() has decoded some metadata item.
2165  It can also be an error code, which can be tested with ZSTD_isError().
2166
2167  A frame is fully decoded when ZSTD_nextSrcSizeToDecompress() returns zero.
2168  Context can then be reset to start a new decompression.
2169
2170  Note : it's possible to know if next input to present is a header or a block, using ZSTD_nextInputType().
2171  This information is not required to properly decode a frame.
2172
2173  == Special case : skippable frames
2174
2175  Skippable frames allow integration of user-defined data into a flow of concatenated frames.
2176  Skippable frames will be ignored (skipped) by decompressor.
2177  The format of skippable frames is as follows :
2178  a) Skippable frame ID - 4 Bytes, Little endian format, any value from 0x184D2A50 to 0x184D2A5F
2179  b) Frame Size - 4 Bytes, Little endian format, unsigned 32-bits
2180  c) Frame Content - any content (User Data) of length equal to Frame Size
2181  For skippable frames ZSTD_getFrameHeader() returns zfhPtr->frameType==ZSTD_skippableFrame.
2182  For skippable frames ZSTD_decompressContinue() always returns 0 : it only skips the content.
2183<BR></pre>
2184
2185<h3>Buffer-less streaming decompression functions</h3><pre></pre><b><pre></pre></b><BR>
2186<pre><b>ZSTDLIB_STATIC_API size_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>
2187</b></pre><BR>
2188<pre><b>typedef enum { ZSTDnit_frameHeader, ZSTDnit_blockHeader, ZSTDnit_block, ZSTDnit_lastBlock, ZSTDnit_checksum, ZSTDnit_skippableFrame } ZSTD_nextInputType_e;
2189</b></pre><BR>
2190<a name="Chapter23"></a><h2>Block level API (DEPRECATED)</h2><pre></pre>
2191
2192<pre><b></b><p>    You can get the frame header down to 2 bytes by setting:
2193      - ZSTD_c_format = ZSTD_f_zstd1_magicless
2194      - ZSTD_c_contentSizeFlag = 0
2195      - ZSTD_c_checksumFlag = 0
2196      - ZSTD_c_dictIDFlag = 0
2197
2198    This API is not as well tested as our normal API, so we recommend not using it.
2199    We will be removing it in a future version. If the normal API doesn't provide
2200    the functionality you need, please open a GitHub issue.
2201
2202    Block functions produce and decode raw zstd blocks, without frame metadata.
2203    Frame metadata cost is typically ~12 bytes, which can be non-negligible for very small blocks (< 100 bytes).
2204    But users will have to take in charge needed metadata to regenerate data, such as compressed and content sizes.
2205
2206    A few rules to respect :
2207    - Compressing and decompressing require a context structure
2208      + Use ZSTD_createCCtx() and ZSTD_createDCtx()
2209    - It is necessary to init context before starting
2210      + compression : any ZSTD_compressBegin*() variant, including with dictionary
2211      + decompression : any ZSTD_decompressBegin*() variant, including with dictionary
2212    - Block size is limited, it must be <= ZSTD_getBlockSize() <= ZSTD_BLOCKSIZE_MAX == 128 KB
2213      + If input is larger than a block size, it's necessary to split input data into multiple blocks
2214      + For inputs larger than a single block, consider using regular ZSTD_compress() instead.
2215        Frame metadata is not that costly, and quickly becomes negligible as source size grows larger than a block.
2216    - When a block is considered not compressible enough, ZSTD_compressBlock() result will be 0 (zero) !
2217      ===> In which case, nothing is produced into `dst` !
2218      + User __must__ test for such outcome and deal directly with uncompressed data
2219      + A block cannot be declared incompressible if ZSTD_compressBlock() return value was != 0.
2220        Doing so would mess up with statistics history, leading to potential data corruption.
2221      + ZSTD_decompressBlock() _doesn't accept uncompressed data as input_ !!
2222      + In case of multiple successive blocks, should some of them be uncompressed,
2223        decoder must be informed of their existence in order to follow proper history.
2224        Use ZSTD_insertBlock() for such a case.
2225</p></pre><BR>
2226
2227<h3>Raw zstd block functions</h3><pre></pre><b><pre>ZSTD_DEPRECATED("The block API is deprecated in favor of the normal compression API. See docs.")
2228ZSTDLIB_STATIC_API size_t ZSTD_getBlockSize   (const ZSTD_CCtx* cctx);
2229ZSTD_DEPRECATED("The block API is deprecated in favor of the normal compression API. See docs.")
2230ZSTDLIB_STATIC_API size_t ZSTD_compressBlock  (ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize);
2231ZSTD_DEPRECATED("The block API is deprecated in favor of the normal compression API. See docs.")
2232ZSTDLIB_STATIC_API size_t ZSTD_decompressBlock(ZSTD_DCtx* dctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize);
2233ZSTD_DEPRECATED("The block API is deprecated in favor of the normal compression API. See docs.")
2234ZSTDLIB_STATIC_API size_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>
2235</pre></b><BR>
2236</html>
2237</body>
2238