xref: /freebsd/sys/contrib/zstd/doc/zstd_manual.html (revision 0b57cec536236d46e3dba9bd041533462f33dbb7)
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
4<title>zstd 1.4.4 Manual</title>
5</head>
6<body>
7<h1>zstd 1.4.4 Manual</h1>
8<hr>
9<a name="Contents"></a><h2>Contents</h2>
10<ol>
11<li><a href="#Chapter1">Introduction</a></li>
12<li><a href="#Chapter2">Version</a></li>
13<li><a href="#Chapter3">Simple API</a></li>
14<li><a href="#Chapter4">Explicit context</a></li>
15<li><a href="#Chapter5">Advanced compression API</a></li>
16<li><a href="#Chapter6">Advanced decompression API</a></li>
17<li><a href="#Chapter7">Streaming</a></li>
18<li><a href="#Chapter8">Streaming compression - HowTo</a></li>
19<li><a href="#Chapter9">Streaming decompression - HowTo</a></li>
20<li><a href="#Chapter10">Simple dictionary API</a></li>
21<li><a href="#Chapter11">Bulk processing dictionary API</a></li>
22<li><a href="#Chapter12">Dictionary helper functions</a></li>
23<li><a href="#Chapter13">Advanced dictionary and prefix API</a></li>
24<li><a href="#Chapter14">experimental API (static linking only)</a></li>
25<li><a href="#Chapter15">Frame size functions</a></li>
26<li><a href="#Chapter16">Memory management</a></li>
27<li><a href="#Chapter17">Advanced compression functions</a></li>
28<li><a href="#Chapter18">Advanced decompression functions</a></li>
29<li><a href="#Chapter19">Advanced streaming functions</a></li>
30<li><a href="#Chapter20">! ZSTD_initCStream_usingDict() :</a></li>
31<li><a href="#Chapter21">! ZSTD_initCStream_advanced() :</a></li>
32<li><a href="#Chapter22">! ZSTD_initCStream_usingCDict() :</a></li>
33<li><a href="#Chapter23">! ZSTD_initCStream_usingCDict_advanced() :</a></li>
34<li><a href="#Chapter24">This function is deprecated, and is equivalent to:</a></li>
35<li><a href="#Chapter25">This function is deprecated, and is equivalent to:</a></li>
36<li><a href="#Chapter26">Buffer-less and synchronous inner streaming functions</a></li>
37<li><a href="#Chapter27">Buffer-less streaming compression (synchronous mode)</a></li>
38<li><a href="#Chapter28">Buffer-less streaming decompression (synchronous mode)</a></li>
39<li><a href="#Chapter29">Block level API</a></li>
40</ol>
41<hr>
42<a name="Chapter1"></a><h2>Introduction</h2><pre>
43  zstd, short for Zstandard, is a fast lossless compression algorithm, targeting
44  real-time compression scenarios at zlib-level and better compression ratios.
45  The zstd compression library provides in-memory compression and decompression
46  functions.
47
48  The library supports regular compression levels from 1 up to ZSTD_maxCLevel(),
49  which is currently 22. Levels >= 20, labeled `--ultra`, should be used with
50  caution, as they require more memory. The library also offers negative
51  compression levels, which extend the range of speed vs. ratio preferences.
52  The lower the level, the faster the speed (at the cost of compression).
53
54  Compression can be done in:
55    - a single step (described as Simple API)
56    - a single step, reusing a context (described as Explicit context)
57    - unbounded multiple steps (described as Streaming compression)
58
59  The compression ratio achievable on small data can be highly improved using
60  a dictionary. Dictionary compression can be performed in:
61    - a single step (described as Simple dictionary API)
62    - a single step, reusing a dictionary (described as Bulk-processing
63      dictionary API)
64
65  Advanced experimental functions can be accessed using
66  `#define ZSTD_STATIC_LINKING_ONLY` before including zstd.h.
67
68  Advanced experimental APIs should never be used with a dynamically-linked
69  library. They are not "stable"; their definitions or signatures may change in
70  the future. Only static linking is allowed.
71<BR></pre>
72
73<a name="Chapter2"></a><h2>Version</h2><pre></pre>
74
75<pre><b>unsigned ZSTD_versionNumber(void);   </b>/**< to check runtime library version */<b>
76</b></pre><BR>
77<a name="Chapter3"></a><h2>Simple API</h2><pre></pre>
78
79<pre><b>size_t ZSTD_compress( void* dst, size_t dstCapacity,
80                const void* src, size_t srcSize,
81                      int compressionLevel);
82</b><p>  Compresses `src` content as a single zstd compressed frame into already allocated `dst`.
83  Hint : compression runs faster if `dstCapacity` >=  `ZSTD_compressBound(srcSize)`.
84  @return : compressed size written into `dst` (<= `dstCapacity),
85            or an error code if it fails (which can be tested using ZSTD_isError()).
86</p></pre><BR>
87
88<pre><b>size_t ZSTD_decompress( void* dst, size_t dstCapacity,
89                  const void* src, size_t compressedSize);
90</b><p>  `compressedSize` : must be the _exact_ size of some number of compressed and/or skippable frames.
91  `dstCapacity` is an upper bound of originalSize to regenerate.
92  If user cannot imply a maximum upper bound, it's better to use streaming mode to decompress data.
93  @return : the number of bytes decompressed into `dst` (<= `dstCapacity`),
94            or an errorCode if it fails (which can be tested using ZSTD_isError()).
95</p></pre><BR>
96
97<pre><b>#define ZSTD_CONTENTSIZE_UNKNOWN (0ULL - 1)
98#define ZSTD_CONTENTSIZE_ERROR   (0ULL - 2)
99unsigned long long ZSTD_getFrameContentSize(const void *src, size_t srcSize);
100</b><p>  `src` should point to the start of a ZSTD encoded frame.
101  `srcSize` must be at least as large as the frame header.
102            hint : any size >= `ZSTD_frameHeaderSize_max` is large enough.
103  @return : - decompressed size of `src` frame content, if known
104            - ZSTD_CONTENTSIZE_UNKNOWN if the size cannot be determined
105            - ZSTD_CONTENTSIZE_ERROR if an error occurred (e.g. invalid magic number, srcSize too small)
106   note 1 : a 0 return value means the frame is valid but "empty".
107   note 2 : decompressed size is an optional field, it may not be present, typically in streaming mode.
108            When `return==ZSTD_CONTENTSIZE_UNKNOWN`, data to decompress could be any size.
109            In which case, it's necessary to use streaming mode to decompress data.
110            Optionally, application can rely on some implicit limit,
111            as ZSTD_decompress() only needs an upper bound of decompressed size.
112            (For example, data could be necessarily cut into blocks <= 16 KB).
113   note 3 : decompressed size is always present when compression is completed using single-pass functions,
114            such as ZSTD_compress(), ZSTD_compressCCtx() ZSTD_compress_usingDict() or ZSTD_compress_usingCDict().
115   note 4 : decompressed size can be very large (64-bits value),
116            potentially larger than what local system can handle as a single memory segment.
117            In which case, it's necessary to use streaming mode to decompress data.
118   note 5 : If source is untrusted, decompressed size could be wrong or intentionally modified.
119            Always ensure return value fits within application's authorized limits.
120            Each application can set its own limits.
121   note 6 : This function replaces ZSTD_getDecompressedSize()
122</p></pre><BR>
123
124<pre><b>unsigned long long ZSTD_getDecompressedSize(const void* src, size_t srcSize);
125</b><p>  NOTE: This function is now obsolete, in favor of ZSTD_getFrameContentSize().
126  Both functions work the same way, but ZSTD_getDecompressedSize() blends
127  "empty", "unknown" and "error" results to the same return value (0),
128  while ZSTD_getFrameContentSize() gives them separate return values.
129 @return : decompressed size of `src` frame content _if known and not empty_, 0 otherwise.
130</p></pre><BR>
131
132<pre><b>size_t ZSTD_findFrameCompressedSize(const void* src, size_t srcSize);
133</b><p> `src` should point to the start of a ZSTD frame or skippable frame.
134 `srcSize` must be >= first frame size
135 @return : the compressed size of the first frame starting at `src`,
136           suitable to pass as `srcSize` to `ZSTD_decompress` or similar,
137        or an error code if input is invalid
138</p></pre><BR>
139
140<h3>Helper functions</h3><pre></pre><b><pre>#define ZSTD_COMPRESSBOUND(srcSize)   ((srcSize) + ((srcSize)>>8) + (((srcSize) < (128<<10)) ? (((128<<10) - (srcSize)) >> 11) </b>/* margin, from 64 to 0 */ : 0))  /* this formula ensures that bound(A) + bound(B) <= bound(A+B) as long as A and B >= 128 KB */<b>
141size_t      ZSTD_compressBound(size_t srcSize); </b>/*!< maximum compressed size in worst case single-pass scenario */<b>
142unsigned    ZSTD_isError(size_t code);          </b>/*!< tells if a `size_t` function result is an error code */<b>
143const char* ZSTD_getErrorName(size_t code);     </b>/*!< provides readable string from an error code */<b>
144int         ZSTD_minCLevel(void);               </b>/*!< minimum negative compression level allowed */<b>
145int         ZSTD_maxCLevel(void);               </b>/*!< maximum compression level available */<b>
146</pre></b><BR>
147<a name="Chapter4"></a><h2>Explicit context</h2><pre></pre>
148
149<h3>Compression context</h3><pre>  When compressing many times,
150  it is recommended to allocate a context just once,
151  and re-use it for each successive compression operation.
152  This will make workload friendlier for system's memory.
153  Note : re-using context is just a speed / resource optimization.
154         It doesn't change the compression ratio, which remains identical.
155  Note 2 : In multi-threaded environments,
156         use one different context per thread for parallel execution.
157
158</pre><b><pre>typedef struct ZSTD_CCtx_s ZSTD_CCtx;
159ZSTD_CCtx* ZSTD_createCCtx(void);
160size_t     ZSTD_freeCCtx(ZSTD_CCtx* cctx);
161</pre></b><BR>
162<pre><b>size_t ZSTD_compressCCtx(ZSTD_CCtx* cctx,
163                         void* dst, size_t dstCapacity,
164                   const void* src, size_t srcSize,
165                         int compressionLevel);
166</b><p>  Same as ZSTD_compress(), using an explicit ZSTD_CCtx.
167  Important : in order to behave similarly to `ZSTD_compress()`,
168  this function compresses at requested compression level,
169  __ignoring any other parameter__ .
170  If any advanced parameter was set using the advanced API,
171  they will all be reset. Only `compressionLevel` remains.
172
173</p></pre><BR>
174
175<h3>Decompression context</h3><pre>  When decompressing many times,
176  it is recommended to allocate a context only once,
177  and re-use it for each successive compression operation.
178  This will make workload friendlier for system's memory.
179  Use one context per thread for parallel execution.
180</pre><b><pre>typedef struct ZSTD_DCtx_s ZSTD_DCtx;
181ZSTD_DCtx* ZSTD_createDCtx(void);
182size_t     ZSTD_freeDCtx(ZSTD_DCtx* dctx);
183</pre></b><BR>
184<pre><b>size_t ZSTD_decompressDCtx(ZSTD_DCtx* dctx,
185                           void* dst, size_t dstCapacity,
186                     const void* src, size_t srcSize);
187</b><p>  Same as ZSTD_decompress(),
188  requires an allocated ZSTD_DCtx.
189  Compatible with sticky parameters.
190
191</p></pre><BR>
192
193<a name="Chapter5"></a><h2>Advanced compression API</h2><pre></pre>
194
195<pre><b>typedef enum { ZSTD_fast=1,
196               ZSTD_dfast=2,
197               ZSTD_greedy=3,
198               ZSTD_lazy=4,
199               ZSTD_lazy2=5,
200               ZSTD_btlazy2=6,
201               ZSTD_btopt=7,
202               ZSTD_btultra=8,
203               ZSTD_btultra2=9
204               </b>/* note : new strategies _might_ be added in the future.<b>
205                         Only the order (from fast to strong) is guaranteed */
206} ZSTD_strategy;
207</b></pre><BR>
208<pre><b>typedef enum {
209
210    </b>/* compression parameters<b>
211     * Note: When compressing with a ZSTD_CDict these parameters are superseded
212     * by the parameters used to construct the ZSTD_CDict.
213     * See ZSTD_CCtx_refCDict() for more info (superseded-by-cdict). */
214    ZSTD_c_compressionLevel=100, </b>/* Set compression parameters according to pre-defined cLevel table.<b>
215                              * Note that exact compression parameters are dynamically determined,
216                              * depending on both compression level and srcSize (when known).
217                              * Default level is ZSTD_CLEVEL_DEFAULT==3.
218                              * Special: value 0 means default, which is controlled by ZSTD_CLEVEL_DEFAULT.
219                              * Note 1 : it's possible to pass a negative compression level.
220                              * Note 2 : setting a level resets all other compression parameters to default */
221    </b>/* Advanced compression parameters :<b>
222     * It's possible to pin down compression parameters to some specific values.
223     * In which case, these values are no longer dynamically selected by the compressor */
224    ZSTD_c_windowLog=101,    </b>/* Maximum allowed back-reference distance, expressed as power of 2.<b>
225                              * This will set a memory budget for streaming decompression,
226                              * with larger values requiring more memory
227                              * and typically compressing more.
228                              * Must be clamped between ZSTD_WINDOWLOG_MIN and ZSTD_WINDOWLOG_MAX.
229                              * Special: value 0 means "use default windowLog".
230                              * Note: Using a windowLog greater than ZSTD_WINDOWLOG_LIMIT_DEFAULT
231                              *       requires explicitly allowing such size at streaming decompression stage. */
232    ZSTD_c_hashLog=102,      </b>/* Size of the initial probe table, as a power of 2.<b>
233                              * Resulting memory usage is (1 << (hashLog+2)).
234                              * Must be clamped between ZSTD_HASHLOG_MIN and ZSTD_HASHLOG_MAX.
235                              * Larger tables improve compression ratio of strategies <= dFast,
236                              * and improve speed of strategies > dFast.
237                              * Special: value 0 means "use default hashLog". */
238    ZSTD_c_chainLog=103,     </b>/* Size of the multi-probe search table, as a power of 2.<b>
239                              * Resulting memory usage is (1 << (chainLog+2)).
240                              * Must be clamped between ZSTD_CHAINLOG_MIN and ZSTD_CHAINLOG_MAX.
241                              * Larger tables result in better and slower compression.
242                              * This parameter is useless for "fast" strategy.
243                              * It's still useful when using "dfast" strategy,
244                              * in which case it defines a secondary probe table.
245                              * Special: value 0 means "use default chainLog". */
246    ZSTD_c_searchLog=104,    </b>/* Number of search attempts, as a power of 2.<b>
247                              * More attempts result in better and slower compression.
248                              * This parameter is useless for "fast" and "dFast" strategies.
249                              * Special: value 0 means "use default searchLog". */
250    ZSTD_c_minMatch=105,     </b>/* Minimum size of searched matches.<b>
251                              * Note that Zstandard can still find matches of smaller size,
252                              * it just tweaks its search algorithm to look for this size and larger.
253                              * Larger values increase compression and decompression speed, but decrease ratio.
254                              * Must be clamped between ZSTD_MINMATCH_MIN and ZSTD_MINMATCH_MAX.
255                              * Note that currently, for all strategies < btopt, effective minimum is 4.
256                              *                    , for all strategies > fast, effective maximum is 6.
257                              * Special: value 0 means "use default minMatchLength". */
258    ZSTD_c_targetLength=106, </b>/* Impact of this field depends on strategy.<b>
259                              * For strategies btopt, btultra & btultra2:
260                              *     Length of Match considered "good enough" to stop search.
261                              *     Larger values make compression stronger, and slower.
262                              * For strategy fast:
263                              *     Distance between match sampling.
264                              *     Larger values make compression faster, and weaker.
265                              * Special: value 0 means "use default targetLength". */
266    ZSTD_c_strategy=107,     </b>/* See ZSTD_strategy enum definition.<b>
267                              * The higher the value of selected strategy, the more complex it is,
268                              * resulting in stronger and slower compression.
269                              * Special: value 0 means "use default strategy". */
270
271    </b>/* LDM mode parameters */<b>
272    ZSTD_c_enableLongDistanceMatching=160, </b>/* Enable long distance matching.<b>
273                                     * This parameter is designed to improve compression ratio
274                                     * for large inputs, by finding large matches at long distance.
275                                     * It increases memory usage and window size.
276                                     * Note: enabling this parameter increases default ZSTD_c_windowLog to 128 MB
277                                     * except when expressly set to a different value. */
278    ZSTD_c_ldmHashLog=161,   </b>/* Size of the table for long distance matching, as a power of 2.<b>
279                              * Larger values increase memory usage and compression ratio,
280                              * but decrease compression speed.
281                              * Must be clamped between ZSTD_HASHLOG_MIN and ZSTD_HASHLOG_MAX
282                              * default: windowlog - 7.
283                              * Special: value 0 means "automatically determine hashlog". */
284    ZSTD_c_ldmMinMatch=162,  </b>/* Minimum match size for long distance matcher.<b>
285                              * Larger/too small values usually decrease compression ratio.
286                              * Must be clamped between ZSTD_LDM_MINMATCH_MIN and ZSTD_LDM_MINMATCH_MAX.
287                              * Special: value 0 means "use default value" (default: 64). */
288    ZSTD_c_ldmBucketSizeLog=163, </b>/* Log size of each bucket in the LDM hash table for collision resolution.<b>
289                              * Larger values improve collision resolution but decrease compression speed.
290                              * The maximum value is ZSTD_LDM_BUCKETSIZELOG_MAX.
291                              * Special: value 0 means "use default value" (default: 3). */
292    ZSTD_c_ldmHashRateLog=164, </b>/* Frequency of inserting/looking up entries into the LDM hash table.<b>
293                              * Must be clamped between 0 and (ZSTD_WINDOWLOG_MAX - ZSTD_HASHLOG_MIN).
294                              * Default is MAX(0, (windowLog - ldmHashLog)), optimizing hash table usage.
295                              * Larger values improve compression speed.
296                              * Deviating far from default value will likely result in a compression ratio decrease.
297                              * Special: value 0 means "automatically determine hashRateLog". */
298
299    </b>/* frame parameters */<b>
300    ZSTD_c_contentSizeFlag=200, </b>/* Content size will be written into frame header _whenever known_ (default:1)<b>
301                              * Content size must be known at the beginning of compression.
302                              * This is automatically the case when using ZSTD_compress2(),
303                              * For streaming scenarios, content size must be provided with ZSTD_CCtx_setPledgedSrcSize() */
304    ZSTD_c_checksumFlag=201, </b>/* A 32-bits checksum of content is written at end of frame (default:0) */<b>
305    ZSTD_c_dictIDFlag=202,   </b>/* When applicable, dictionary's ID is written into frame header (default:1) */<b>
306
307    </b>/* multi-threading parameters */<b>
308    </b>/* These parameters are only useful if multi-threading is enabled (compiled with build macro ZSTD_MULTITHREAD).<b>
309     * They return an error otherwise. */
310    ZSTD_c_nbWorkers=400,    </b>/* Select how many threads will be spawned to compress in parallel.<b>
311                              * When nbWorkers >= 1, triggers asynchronous mode when used with ZSTD_compressStream*() :
312                              * ZSTD_compressStream*() consumes input and flush output if possible, but immediately gives back control to caller,
313                              * while compression work is performed in parallel, within worker threads.
314                              * (note : a strong exception to this rule is when first invocation of ZSTD_compressStream2() sets ZSTD_e_end :
315                              *  in which case, ZSTD_compressStream2() delegates to ZSTD_compress2(), which is always a blocking call).
316                              * More workers improve speed, but also increase memory usage.
317                              * Default value is `0`, aka "single-threaded mode" : no worker is spawned, compression is performed inside Caller's thread, all invocations are blocking */
318    ZSTD_c_jobSize=401,      </b>/* Size of a compression job. This value is enforced only when nbWorkers >= 1.<b>
319                              * Each compression job is completed in parallel, so this value can indirectly impact the nb of active threads.
320                              * 0 means default, which is dynamically determined based on compression parameters.
321                              * Job size must be a minimum of overlap size, or 1 MB, whichever is largest.
322                              * The minimum size is automatically and transparently enforced. */
323    ZSTD_c_overlapLog=402,   </b>/* Control the overlap size, as a fraction of window size.<b>
324                              * The overlap size is an amount of data reloaded from previous job at the beginning of a new job.
325                              * It helps preserve compression ratio, while each job is compressed in parallel.
326                              * This value is enforced only when nbWorkers >= 1.
327                              * Larger values increase compression ratio, but decrease speed.
328                              * Possible values range from 0 to 9 :
329                              * - 0 means "default" : value will be determined by the library, depending on strategy
330                              * - 1 means "no overlap"
331                              * - 9 means "full overlap", using a full window size.
332                              * Each intermediate rank increases/decreases load size by a factor 2 :
333                              * 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
334                              * default value varies between 6 and 9, depending on strategy */
335
336    </b>/* note : additional experimental parameters are also available<b>
337     * within the experimental section of the API.
338     * At the time of this writing, they include :
339     * ZSTD_c_rsyncable
340     * ZSTD_c_format
341     * ZSTD_c_forceMaxWindow
342     * ZSTD_c_forceAttachDict
343     * ZSTD_c_literalCompressionMode
344     * ZSTD_c_targetCBlockSize
345     * ZSTD_c_srcSizeHint
346     * Because they are not stable, it's necessary to define ZSTD_STATIC_LINKING_ONLY to access them.
347     * note : never ever use experimentalParam? names directly;
348     *        also, the enums values themselves are unstable and can still change.
349     */
350     ZSTD_c_experimentalParam1=500,
351     ZSTD_c_experimentalParam2=10,
352     ZSTD_c_experimentalParam3=1000,
353     ZSTD_c_experimentalParam4=1001,
354     ZSTD_c_experimentalParam5=1002,
355     ZSTD_c_experimentalParam6=1003,
356     ZSTD_c_experimentalParam7=1004
357} ZSTD_cParameter;
358</b></pre><BR>
359<pre><b>typedef struct {
360    size_t error;
361    int lowerBound;
362    int upperBound;
363} ZSTD_bounds;
364</b></pre><BR>
365<pre><b>ZSTD_bounds ZSTD_cParam_getBounds(ZSTD_cParameter cParam);
366</b><p>  All parameters must belong to an interval with lower and upper bounds,
367  otherwise they will either trigger an error or be automatically clamped.
368 @return : a structure, ZSTD_bounds, which contains
369         - an error status field, which must be tested using ZSTD_isError()
370         - lower and upper bounds, both inclusive
371
372</p></pre><BR>
373
374<pre><b>size_t ZSTD_CCtx_setParameter(ZSTD_CCtx* cctx, ZSTD_cParameter param, int value);
375</b><p>  Set one compression parameter, selected by enum ZSTD_cParameter.
376  All parameters have valid bounds. Bounds can be queried using ZSTD_cParam_getBounds().
377  Providing a value beyond bound will either clamp it, or trigger an error (depending on parameter).
378  Setting a parameter is generally only possible during frame initialization (before starting compression).
379  Exception : when using multi-threading mode (nbWorkers >= 1),
380              the following parameters can be updated _during_ compression (within same frame):
381              => compressionLevel, hashLog, chainLog, searchLog, minMatch, targetLength and strategy.
382              new parameters will be active for next job only (after a flush()).
383 @return : an error code (which can be tested using ZSTD_isError()).
384
385</p></pre><BR>
386
387<pre><b>size_t ZSTD_CCtx_setPledgedSrcSize(ZSTD_CCtx* cctx, unsigned long long pledgedSrcSize);
388</b><p>  Total input data size to be compressed as a single frame.
389  Value will be written in frame header, unless if explicitly forbidden using ZSTD_c_contentSizeFlag.
390  This value will also be controlled at end of frame, and trigger an error if not respected.
391 @result : 0, or an error code (which can be tested with ZSTD_isError()).
392  Note 1 : pledgedSrcSize==0 actually means zero, aka an empty frame.
393           In order to mean "unknown content size", pass constant ZSTD_CONTENTSIZE_UNKNOWN.
394           ZSTD_CONTENTSIZE_UNKNOWN is default value for any new frame.
395  Note 2 : pledgedSrcSize is only valid once, for the next frame.
396           It's discarded at the end of the frame, and replaced by ZSTD_CONTENTSIZE_UNKNOWN.
397  Note 3 : Whenever all input data is provided and consumed in a single round,
398           for example with ZSTD_compress2(),
399           or invoking immediately ZSTD_compressStream2(,,,ZSTD_e_end),
400           this value is automatically overridden by srcSize instead.
401
402</p></pre><BR>
403
404<pre><b>typedef enum {
405    ZSTD_reset_session_only = 1,
406    ZSTD_reset_parameters = 2,
407    ZSTD_reset_session_and_parameters = 3
408} ZSTD_ResetDirective;
409</b></pre><BR>
410<pre><b>size_t ZSTD_CCtx_reset(ZSTD_CCtx* cctx, ZSTD_ResetDirective reset);
411</b><p>  There are 2 different things that can be reset, independently or jointly :
412  - The session : will stop compressing current frame, and make CCtx ready to start a new one.
413                  Useful after an error, or to interrupt any ongoing compression.
414                  Any internal data not yet flushed is cancelled.
415                  Compression parameters and dictionary remain unchanged.
416                  They will be used to compress next frame.
417                  Resetting session never fails.
418  - The parameters : changes all parameters back to "default".
419                  This removes any reference to any dictionary too.
420                  Parameters can only be changed between 2 sessions (i.e. no compression is currently ongoing)
421                  otherwise the reset fails, and function returns an error value (which can be tested using ZSTD_isError())
422  - Both : similar to resetting the session, followed by resetting parameters.
423
424</p></pre><BR>
425
426<pre><b>size_t ZSTD_compress2( ZSTD_CCtx* cctx,
427                       void* dst, size_t dstCapacity,
428                 const void* src, size_t srcSize);
429</b><p>  Behave the same as ZSTD_compressCCtx(), but compression parameters are set using the advanced API.
430  ZSTD_compress2() always starts a new frame.
431  Should cctx hold data from a previously unfinished frame, everything about it is forgotten.
432  - Compression parameters are pushed into CCtx before starting compression, using ZSTD_CCtx_set*()
433  - The function is always blocking, returns when compression is completed.
434  Hint : compression runs faster if `dstCapacity` >=  `ZSTD_compressBound(srcSize)`.
435 @return : compressed size written into `dst` (<= `dstCapacity),
436           or an error code if it fails (which can be tested using ZSTD_isError()).
437
438</p></pre><BR>
439
440<a name="Chapter6"></a><h2>Advanced decompression API</h2><pre></pre>
441
442<pre><b>typedef enum {
443
444    ZSTD_d_windowLogMax=100, </b>/* Select a size limit (in power of 2) beyond which<b>
445                              * the streaming API will refuse to allocate memory buffer
446                              * in order to protect the host from unreasonable memory requirements.
447                              * This parameter is only useful in streaming mode, since no internal buffer is allocated in single-pass mode.
448                              * By default, a decompression context accepts window sizes <= (1 << ZSTD_WINDOWLOG_LIMIT_DEFAULT).
449                              * Special: value 0 means "use default maximum windowLog". */
450
451    </b>/* note : additional experimental parameters are also available<b>
452     * within the experimental section of the API.
453     * At the time of this writing, they include :
454     * ZSTD_c_format
455     * Because they are not stable, it's necessary to define ZSTD_STATIC_LINKING_ONLY to access them.
456     * note : never ever use experimentalParam? names directly
457     */
458     ZSTD_d_experimentalParam1=1000
459
460} ZSTD_dParameter;
461</b></pre><BR>
462<pre><b>ZSTD_bounds ZSTD_dParam_getBounds(ZSTD_dParameter dParam);
463</b><p>  All parameters must belong to an interval with lower and upper bounds,
464  otherwise they will either trigger an error or be automatically clamped.
465 @return : a structure, ZSTD_bounds, which contains
466         - an error status field, which must be tested using ZSTD_isError()
467         - both lower and upper bounds, inclusive
468
469</p></pre><BR>
470
471<pre><b>size_t ZSTD_DCtx_setParameter(ZSTD_DCtx* dctx, ZSTD_dParameter param, int value);
472</b><p>  Set one compression parameter, selected by enum ZSTD_dParameter.
473  All parameters have valid bounds. Bounds can be queried using ZSTD_dParam_getBounds().
474  Providing a value beyond bound will either clamp it, or trigger an error (depending on parameter).
475  Setting a parameter is only possible during frame initialization (before starting decompression).
476 @return : 0, or an error code (which can be tested using ZSTD_isError()).
477
478</p></pre><BR>
479
480<pre><b>size_t ZSTD_DCtx_reset(ZSTD_DCtx* dctx, ZSTD_ResetDirective reset);
481</b><p>  Return a DCtx to clean state.
482  Session and parameters can be reset jointly or separately.
483  Parameters can only be reset when no active frame is being decompressed.
484 @return : 0, or an error code, which can be tested with ZSTD_isError()
485
486</p></pre><BR>
487
488<a name="Chapter7"></a><h2>Streaming</h2><pre></pre>
489
490<pre><b>typedef struct ZSTD_inBuffer_s {
491  const void* src;    </b>/**< start of input buffer */<b>
492  size_t size;        </b>/**< size of input buffer */<b>
493  size_t pos;         </b>/**< position where reading stopped. Will be updated. Necessarily 0 <= pos <= size */<b>
494} ZSTD_inBuffer;
495</b></pre><BR>
496<pre><b>typedef struct ZSTD_outBuffer_s {
497  void*  dst;         </b>/**< start of output buffer */<b>
498  size_t size;        </b>/**< size of output buffer */<b>
499  size_t pos;         </b>/**< position where writing stopped. Will be updated. Necessarily 0 <= pos <= size */<b>
500} ZSTD_outBuffer;
501</b></pre><BR>
502<a name="Chapter8"></a><h2>Streaming compression - HowTo</h2><pre>
503  A ZSTD_CStream object is required to track streaming operation.
504  Use ZSTD_createCStream() and ZSTD_freeCStream() to create/release resources.
505  ZSTD_CStream objects can be reused multiple times on consecutive compression operations.
506  It is recommended to re-use ZSTD_CStream since it will play nicer with system's memory, by re-using already allocated memory.
507
508  For parallel execution, use one separate ZSTD_CStream per thread.
509
510  note : since v1.3.0, ZSTD_CStream and ZSTD_CCtx are the same thing.
511
512  Parameters are sticky : when starting a new compression on the same context,
513  it will re-use the same sticky parameters as previous compression session.
514  When in doubt, it's recommended to fully initialize the context before usage.
515  Use ZSTD_CCtx_reset() to reset the context and ZSTD_CCtx_setParameter(),
516  ZSTD_CCtx_setPledgedSrcSize(), or ZSTD_CCtx_loadDictionary() and friends to
517  set more specific parameters, the pledged source size, or load a dictionary.
518
519  Use ZSTD_compressStream2() with ZSTD_e_continue as many times as necessary to
520  consume input stream. The function will automatically update both `pos`
521  fields within `input` and `output`.
522  Note that the function may not consume the entire input, for example, because
523  the output buffer is already full, in which case `input.pos < input.size`.
524  The caller must check if input has been entirely consumed.
525  If not, the caller must make some room to receive more compressed data,
526  and then present again remaining input data.
527  note: ZSTD_e_continue is guaranteed to make some forward progress when called,
528        but doesn't guarantee maximal forward progress. This is especially relevant
529        when compressing with multiple threads. The call won't block if it can
530        consume some input, but if it can't it will wait for some, but not all,
531        output to be flushed.
532 @return : provides a minimum amount of data remaining to be flushed from internal buffers
533           or an error code, which can be tested using ZSTD_isError().
534
535  At any moment, it's possible to flush whatever data might remain stuck within internal buffer,
536  using ZSTD_compressStream2() with ZSTD_e_flush. `output->pos` will be updated.
537  Note that, if `output->size` is too small, a single invocation with ZSTD_e_flush might not be enough (return code > 0).
538  In which case, make some room to receive more compressed data, and call again ZSTD_compressStream2() with ZSTD_e_flush.
539  You must continue calling ZSTD_compressStream2() with ZSTD_e_flush until it returns 0, at which point you can change the
540  operation.
541  note: ZSTD_e_flush will flush as much output as possible, meaning when compressing with multiple threads, it will
542        block until the flush is complete or the output buffer is full.
543  @return : 0 if internal buffers are entirely flushed,
544            >0 if some data still present within internal buffer (the value is minimal estimation of remaining size),
545            or an error code, which can be tested using ZSTD_isError().
546
547  Calling ZSTD_compressStream2() with ZSTD_e_end instructs to finish a frame.
548  It will perform a flush and write frame epilogue.
549  The epilogue is required for decoders to consider a frame completed.
550  flush operation is the same, and follows same rules as calling ZSTD_compressStream2() with ZSTD_e_flush.
551  You must continue calling ZSTD_compressStream2() with ZSTD_e_end until it returns 0, at which point you are free to
552  start a new frame.
553  note: ZSTD_e_end will flush as much output as possible, meaning when compressing with multiple threads, it will
554        block until the flush is complete or the output buffer is full.
555  @return : 0 if frame fully completed and fully flushed,
556            >0 if some data still present within internal buffer (the value is minimal estimation of remaining size),
557            or an error code, which can be tested using ZSTD_isError().
558
559
560<BR></pre>
561
562<pre><b>typedef ZSTD_CCtx ZSTD_CStream;  </b>/**< CCtx and CStream are now effectively same object (>= v1.3.0) */<b>
563</b></pre><BR>
564<h3>ZSTD_CStream management functions</h3><pre></pre><b><pre>ZSTD_CStream* ZSTD_createCStream(void);
565size_t ZSTD_freeCStream(ZSTD_CStream* zcs);
566</pre></b><BR>
567<h3>Streaming compression functions</h3><pre></pre><b><pre>typedef enum {
568    ZSTD_e_continue=0, </b>/* collect more data, encoder decides when to output compressed result, for optimal compression ratio */<b>
569    ZSTD_e_flush=1,    </b>/* flush any data provided so far,<b>
570                        * it creates (at least) one new block, that can be decoded immediately on reception;
571                        * frame will continue: any future data can still reference previously compressed data, improving compression.
572                        * note : multithreaded compression will block to flush as much output as possible. */
573    ZSTD_e_end=2       </b>/* flush any remaining data _and_ close current frame.<b>
574                        * note that frame is only closed after compressed data is fully flushed (return value == 0).
575                        * After that point, any additional data starts a new frame.
576                        * note : each frame is independent (does not reference any content from previous frame).
577                        : note : multithreaded compression will block to flush as much output as possible. */
578} ZSTD_EndDirective;
579</pre></b><BR>
580<pre><b>size_t ZSTD_compressStream2( ZSTD_CCtx* cctx,
581                             ZSTD_outBuffer* output,
582                             ZSTD_inBuffer* input,
583                             ZSTD_EndDirective endOp);
584</b><p>  Behaves about the same as ZSTD_compressStream, with additional control on end directive.
585  - Compression parameters are pushed into CCtx before starting compression, using ZSTD_CCtx_set*()
586  - Compression parameters cannot be changed once compression is started (save a list of exceptions in multi-threading mode)
587  - output->pos must be <= dstCapacity, input->pos must be <= srcSize
588  - output->pos and input->pos will be updated. They are guaranteed to remain below their respective limit.
589  - When nbWorkers==0 (default), function is blocking : it completes its job before returning to caller.
590  - When nbWorkers>=1, function is non-blocking : it just acquires a copy of input, and distributes jobs to internal worker threads, flush whatever is available,
591                                                  and then immediately returns, just indicating that there is some data remaining to be flushed.
592                                                  The function nonetheless guarantees forward progress : it will return only after it reads or write at least 1+ byte.
593  - 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.
594  - @return provides a minimum amount of data remaining to be flushed from internal buffers
595            or an error code, which can be tested using ZSTD_isError().
596            if @return != 0, flush is not fully completed, there is still some data left within internal buffers.
597            This is useful for ZSTD_e_flush, since in this case more flushes are necessary to empty all buffers.
598            For ZSTD_e_end, @return == 0 when internal buffers are fully flushed and frame is completed.
599  - after a ZSTD_e_end directive, if internal buffer is not fully flushed (@return != 0),
600            only ZSTD_e_end or ZSTD_e_flush operations are allowed.
601            Before starting a new compression job, or changing compression parameters,
602            it is required to fully flush internal buffers.
603
604</p></pre><BR>
605
606<pre><b>size_t ZSTD_CStreamInSize(void);    </b>/**< recommended size for input buffer */<b>
607</b></pre><BR>
608<pre><b>size_t ZSTD_CStreamOutSize(void);   </b>/**< recommended size for output buffer. Guarantee to successfully flush at least one complete compressed block. */<b>
609</b></pre><BR>
610<pre><b>size_t ZSTD_initCStream(ZSTD_CStream* zcs, int compressionLevel);
611</b>/*!<b>
612 * Alternative for ZSTD_compressStream2(zcs, output, input, ZSTD_e_continue).
613 * NOTE: The return value is different. ZSTD_compressStream() returns a hint for
614 * the next read size (if non-zero and not an error). ZSTD_compressStream2()
615 * returns the minimum nb of bytes left to flush (if non-zero and not an error).
616 */
617size_t ZSTD_compressStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output, ZSTD_inBuffer* input);
618</b>/*! Equivalent to ZSTD_compressStream2(zcs, output, &emptyInput, ZSTD_e_flush). */<b>
619size_t ZSTD_flushStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output);
620</b>/*! Equivalent to ZSTD_compressStream2(zcs, output, &emptyInput, ZSTD_e_end). */<b>
621size_t ZSTD_endStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output);
622</b><p>
623     ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
624     ZSTD_CCtx_refCDict(zcs, NULL); // clear the dictionary (if any)
625     ZSTD_CCtx_setParameter(zcs, ZSTD_c_compressionLevel, compressionLevel);
626
627</p></pre><BR>
628
629<a name="Chapter9"></a><h2>Streaming decompression - HowTo</h2><pre>
630  A ZSTD_DStream object is required to track streaming operations.
631  Use ZSTD_createDStream() and ZSTD_freeDStream() to create/release resources.
632  ZSTD_DStream objects can be re-used multiple times.
633
634  Use ZSTD_initDStream() to start a new decompression operation.
635 @return : recommended first input size
636  Alternatively, use advanced API to set specific properties.
637
638  Use ZSTD_decompressStream() repetitively to consume your input.
639  The function will update both `pos` fields.
640  If `input.pos < input.size`, some input has not been consumed.
641  It's up to the caller to present again remaining data.
642  The function tries to flush all data decoded immediately, respecting output buffer size.
643  If `output.pos < output.size`, decoder has flushed everything it could.
644  But if `output.pos == output.size`, there might be some data left within internal buffers.,
645  In which case, call ZSTD_decompressStream() again to flush whatever remains in the buffer.
646  Note : with no additional input provided, amount of data flushed is necessarily <= ZSTD_BLOCKSIZE_MAX.
647 @return : 0 when a frame is completely decoded and fully flushed,
648        or an error code, which can be tested using ZSTD_isError(),
649        or any other value > 0, which means there is still some decoding or flushing to do to complete current frame :
650                                the return value is a suggested next input size (just a hint for better latency)
651                                that will never request more than the remaining frame size.
652
653<BR></pre>
654
655<pre><b>typedef ZSTD_DCtx ZSTD_DStream;  </b>/**< DCtx and DStream are now effectively same object (>= v1.3.0) */<b>
656</b></pre><BR>
657<h3>ZSTD_DStream management functions</h3><pre></pre><b><pre>ZSTD_DStream* ZSTD_createDStream(void);
658size_t ZSTD_freeDStream(ZSTD_DStream* zds);
659</pre></b><BR>
660<h3>Streaming decompression functions</h3><pre></pre><b><pre></pre></b><BR>
661<pre><b>size_t ZSTD_DStreamInSize(void);    </b>/*!< recommended size for input buffer */<b>
662</b></pre><BR>
663<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>
664</b></pre><BR>
665<a name="Chapter10"></a><h2>Simple dictionary API</h2><pre></pre>
666
667<pre><b>size_t ZSTD_compress_usingDict(ZSTD_CCtx* ctx,
668                               void* dst, size_t dstCapacity,
669                         const void* src, size_t srcSize,
670                         const void* dict,size_t dictSize,
671                               int compressionLevel);
672</b><p>  Compression at an explicit compression level using a Dictionary.
673  A dictionary can be any arbitrary data segment (also called a prefix),
674  or a buffer with specified information (see dictBuilder/zdict.h).
675  Note : This function loads the dictionary, resulting in significant startup delay.
676         It's intended for a dictionary used only once.
677  Note 2 : When `dict == NULL || dictSize < 8` no dictionary is used.
678</p></pre><BR>
679
680<pre><b>size_t ZSTD_decompress_usingDict(ZSTD_DCtx* dctx,
681                                 void* dst, size_t dstCapacity,
682                           const void* src, size_t srcSize,
683                           const void* dict,size_t dictSize);
684</b><p>  Decompression using a known Dictionary.
685  Dictionary must be identical to the one used during compression.
686  Note : This function loads the dictionary, resulting in significant startup delay.
687         It's intended for a dictionary used only once.
688  Note : When `dict == NULL || dictSize < 8` no dictionary is used.
689</p></pre><BR>
690
691<a name="Chapter11"></a><h2>Bulk processing dictionary API</h2><pre></pre>
692
693<pre><b>ZSTD_CDict* ZSTD_createCDict(const void* dictBuffer, size_t dictSize,
694                             int compressionLevel);
695</b><p>  When compressing multiple messages or blocks using the same dictionary,
696  it's recommended to digest the dictionary only once, since it's a costly operation.
697  ZSTD_createCDict() will create a state from digesting a dictionary.
698  The resulting state can be used for future compression operations with very limited startup cost.
699  ZSTD_CDict can be created once and shared by multiple threads concurrently, since its usage is read-only.
700 @dictBuffer can be released after ZSTD_CDict creation, because its content is copied within CDict.
701  Note 1 : Consider experimental function `ZSTD_createCDict_byReference()` if you prefer to not duplicate @dictBuffer content.
702  Note 2 : A ZSTD_CDict can be created from an empty @dictBuffer,
703      in which case the only thing that it transports is the @compressionLevel.
704      This can be useful in a pipeline featuring ZSTD_compress_usingCDict() exclusively,
705      expecting a ZSTD_CDict parameter with any data, including those without a known dictionary.
706</p></pre><BR>
707
708<pre><b>size_t      ZSTD_freeCDict(ZSTD_CDict* CDict);
709</b><p>  Function frees memory allocated by ZSTD_createCDict().
710</p></pre><BR>
711
712<pre><b>size_t ZSTD_compress_usingCDict(ZSTD_CCtx* cctx,
713                                void* dst, size_t dstCapacity,
714                          const void* src, size_t srcSize,
715                          const ZSTD_CDict* cdict);
716</b><p>  Compression using a digested Dictionary.
717  Recommended when same dictionary is used multiple times.
718  Note : compression level is _decided at dictionary creation time_,
719     and frame parameters are hardcoded (dictID=yes, contentSize=yes, checksum=no)
720</p></pre><BR>
721
722<pre><b>ZSTD_DDict* ZSTD_createDDict(const void* dictBuffer, size_t dictSize);
723</b><p>  Create a digested dictionary, ready to start decompression operation without startup delay.
724  dictBuffer can be released after DDict creation, as its content is copied inside DDict.
725</p></pre><BR>
726
727<pre><b>size_t      ZSTD_freeDDict(ZSTD_DDict* ddict);
728</b><p>  Function frees memory allocated with ZSTD_createDDict()
729</p></pre><BR>
730
731<pre><b>size_t ZSTD_decompress_usingDDict(ZSTD_DCtx* dctx,
732                                  void* dst, size_t dstCapacity,
733                            const void* src, size_t srcSize,
734                            const ZSTD_DDict* ddict);
735</b><p>  Decompression using a digested Dictionary.
736  Recommended when same dictionary is used multiple times.
737</p></pre><BR>
738
739<a name="Chapter12"></a><h2>Dictionary helper functions</h2><pre></pre>
740
741<pre><b>unsigned ZSTD_getDictID_fromDict(const void* dict, size_t dictSize);
742</b><p>  Provides the dictID stored within dictionary.
743  if @return == 0, the dictionary is not conformant with Zstandard specification.
744  It can still be loaded, but as a content-only dictionary.
745</p></pre><BR>
746
747<pre><b>unsigned ZSTD_getDictID_fromDDict(const ZSTD_DDict* ddict);
748</b><p>  Provides the dictID of the dictionary loaded into `ddict`.
749  If @return == 0, the dictionary is not conformant to Zstandard specification, or empty.
750  Non-conformant dictionaries can still be loaded, but as content-only dictionaries.
751</p></pre><BR>
752
753<pre><b>unsigned ZSTD_getDictID_fromFrame(const void* src, size_t srcSize);
754</b><p>  Provides the dictID required to decompressed the frame stored within `src`.
755  If @return == 0, the dictID could not be decoded.
756  This could for one of the following reasons :
757  - The frame does not require a dictionary to be decoded (most common case).
758  - The frame was built with dictID intentionally removed. Whatever dictionary is necessary is a hidden information.
759    Note : this use case also happens when using a non-conformant dictionary.
760  - `srcSize` is too small, and as a result, the frame header could not be decoded (only possible if `srcSize < ZSTD_FRAMEHEADERSIZE_MAX`).
761  - This is not a Zstandard frame.
762  When identifying the exact failure cause, it's possible to use ZSTD_getFrameHeader(), which will provide a more precise error code.
763</p></pre><BR>
764
765<a name="Chapter13"></a><h2>Advanced dictionary and prefix API</h2><pre>
766 This API allows dictionaries to be used with ZSTD_compress2(),
767 ZSTD_compressStream2(), and ZSTD_decompress(). Dictionaries are sticky, and
768 only reset with the context is reset with ZSTD_reset_parameters or
769 ZSTD_reset_session_and_parameters. Prefixes are single-use.
770<BR></pre>
771
772<pre><b>size_t ZSTD_CCtx_loadDictionary(ZSTD_CCtx* cctx, const void* dict, size_t dictSize);
773</b><p>  Create an internal CDict from `dict` buffer.
774  Decompression will have to use same dictionary.
775 @result : 0, or an error code (which can be tested with ZSTD_isError()).
776  Special: Loading a NULL (or 0-size) dictionary invalidates previous dictionary,
777           meaning "return to no-dictionary mode".
778  Note 1 : Dictionary is sticky, it will be used for all future compressed frames.
779           To return to "no-dictionary" situation, load a NULL dictionary (or reset parameters).
780  Note 2 : Loading a dictionary involves building tables.
781           It's also a CPU consuming operation, with non-negligible impact on latency.
782           Tables are dependent on compression parameters, and for this reason,
783           compression parameters can no longer be changed after loading a dictionary.
784  Note 3 :`dict` content will be copied internally.
785           Use experimental ZSTD_CCtx_loadDictionary_byReference() to reference content instead.
786           In such a case, dictionary buffer must outlive its users.
787  Note 4 : Use ZSTD_CCtx_loadDictionary_advanced()
788           to precisely select how dictionary content must be interpreted.
789</p></pre><BR>
790
791<pre><b>size_t ZSTD_CCtx_refCDict(ZSTD_CCtx* cctx, const ZSTD_CDict* cdict);
792</b><p>  Reference a prepared dictionary, to be used for all next compressed frames.
793  Note that compression parameters are enforced from within CDict,
794  and supersede any compression parameter previously set within CCtx.
795  The parameters ignored are labled as "superseded-by-cdict" in the ZSTD_cParameter enum docs.
796  The ignored parameters will be used again if the CCtx is returned to no-dictionary mode.
797  The dictionary will remain valid for future compressed frames using same CCtx.
798 @result : 0, or an error code (which can be tested with ZSTD_isError()).
799  Special : Referencing a NULL CDict means "return to no-dictionary mode".
800  Note 1 : Currently, only one dictionary can be managed.
801           Referencing a new dictionary effectively "discards" any previous one.
802  Note 2 : CDict is just referenced, its lifetime must outlive its usage within CCtx.
803</p></pre><BR>
804
805<pre><b>size_t ZSTD_CCtx_refPrefix(ZSTD_CCtx* cctx,
806                     const void* prefix, size_t prefixSize);
807</b><p>  Reference a prefix (single-usage dictionary) for next compressed frame.
808  A prefix is **only used once**. Tables are discarded at end of frame (ZSTD_e_end).
809  Decompression will need same prefix to properly regenerate data.
810  Compressing with a prefix is similar in outcome as performing a diff and compressing it,
811  but performs much faster, especially during decompression (compression speed is tunable with compression level).
812 @result : 0, or an error code (which can be tested with ZSTD_isError()).
813  Special: Adding any prefix (including NULL) invalidates any previous prefix or dictionary
814  Note 1 : Prefix buffer is referenced. It **must** outlive compression.
815           Its content must remain unmodified during compression.
816  Note 2 : If the intention is to diff some large src data blob with some prior version of itself,
817           ensure that the window size is large enough to contain the entire source.
818           See ZSTD_c_windowLog.
819  Note 3 : Referencing a prefix involves building tables, which are dependent on compression parameters.
820           It's a CPU consuming operation, with non-negligible impact on latency.
821           If there is a need to use the same prefix multiple times, consider loadDictionary instead.
822  Note 4 : By default, the prefix is interpreted as raw content (ZSTD_dct_rawContent).
823           Use experimental ZSTD_CCtx_refPrefix_advanced() to alter dictionary interpretation.
824</p></pre><BR>
825
826<pre><b>size_t ZSTD_DCtx_loadDictionary(ZSTD_DCtx* dctx, const void* dict, size_t dictSize);
827</b><p>  Create an internal DDict from dict buffer,
828  to be used to decompress next frames.
829  The dictionary remains valid for all future frames, until explicitly invalidated.
830 @result : 0, or an error code (which can be tested with ZSTD_isError()).
831  Special : Adding a NULL (or 0-size) dictionary invalidates any previous dictionary,
832            meaning "return to no-dictionary mode".
833  Note 1 : Loading a dictionary involves building tables,
834           which has a non-negligible impact on CPU usage and latency.
835           It's recommended to "load once, use many times", to amortize the cost
836  Note 2 :`dict` content will be copied internally, so `dict` can be released after loading.
837           Use ZSTD_DCtx_loadDictionary_byReference() to reference dictionary content instead.
838  Note 3 : Use ZSTD_DCtx_loadDictionary_advanced() to take control of
839           how dictionary content is loaded and interpreted.
840
841</p></pre><BR>
842
843<pre><b>size_t ZSTD_DCtx_refDDict(ZSTD_DCtx* dctx, const ZSTD_DDict* ddict);
844</b><p>  Reference a prepared dictionary, to be used to decompress next frames.
845  The dictionary remains active for decompression of future frames using same DCtx.
846 @result : 0, or an error code (which can be tested with ZSTD_isError()).
847  Note 1 : Currently, only one dictionary can be managed.
848           Referencing a new dictionary effectively "discards" any previous one.
849  Special: referencing a NULL DDict means "return to no-dictionary mode".
850  Note 2 : DDict is just referenced, its lifetime must outlive its usage from DCtx.
851
852</p></pre><BR>
853
854<pre><b>size_t ZSTD_DCtx_refPrefix(ZSTD_DCtx* dctx,
855                     const void* prefix, size_t prefixSize);
856</b><p>  Reference a prefix (single-usage dictionary) to decompress next frame.
857  This is the reverse operation of ZSTD_CCtx_refPrefix(),
858  and must use the same prefix as the one used during compression.
859  Prefix is **only used once**. Reference is discarded at end of frame.
860  End of frame is reached when ZSTD_decompressStream() returns 0.
861 @result : 0, or an error code (which can be tested with ZSTD_isError()).
862  Note 1 : Adding any prefix (including NULL) invalidates any previously set prefix or dictionary
863  Note 2 : Prefix buffer is referenced. It **must** outlive decompression.
864           Prefix buffer must remain unmodified up to the end of frame,
865           reached when ZSTD_decompressStream() returns 0.
866  Note 3 : By default, the prefix is treated as raw content (ZSTD_dct_rawContent).
867           Use ZSTD_CCtx_refPrefix_advanced() to alter dictMode (Experimental section)
868  Note 4 : Referencing a raw content prefix has almost no cpu nor memory cost.
869           A full dictionary is more costly, as it requires building tables.
870
871</p></pre><BR>
872
873<pre><b>size_t ZSTD_sizeof_CCtx(const ZSTD_CCtx* cctx);
874size_t ZSTD_sizeof_DCtx(const ZSTD_DCtx* dctx);
875size_t ZSTD_sizeof_CStream(const ZSTD_CStream* zcs);
876size_t ZSTD_sizeof_DStream(const ZSTD_DStream* zds);
877size_t ZSTD_sizeof_CDict(const ZSTD_CDict* cdict);
878size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict);
879</b><p>  These functions give the _current_ memory usage of selected object.
880  Note that object memory usage can evolve (increase or decrease) over time.
881</p></pre><BR>
882
883<a name="Chapter14"></a><h2>experimental API (static linking only)</h2><pre>
884 The following symbols and constants
885 are not planned to join "stable API" status in the near future.
886 They can still change in future versions.
887 Some of them are planned to remain in the static_only section indefinitely.
888 Some of them might be removed in the future (especially when redundant with existing stable functions)
889
890<BR></pre>
891
892<pre><b>typedef struct {
893    unsigned int matchPos; </b>/* Match pos in dst */<b>
894    </b>/* If seqDef.offset > 3, then this is seqDef.offset - 3<b>
895     * If seqDef.offset < 3, then this is the corresponding repeat offset
896     * But if seqDef.offset < 3 and litLength == 0, this is the
897     *   repeat offset before the corresponding repeat offset
898     * And if seqDef.offset == 3 and litLength == 0, this is the
899     *   most recent repeat offset - 1
900     */
901    unsigned int offset;
902    unsigned int litLength; </b>/* Literal length */<b>
903    unsigned int matchLength; </b>/* Match length */<b>
904    </b>/* 0 when seq not rep and seqDef.offset otherwise<b>
905     * when litLength == 0 this will be <= 4, otherwise <= 3 like normal
906     */
907    unsigned int rep;
908} ZSTD_Sequence;
909</b></pre><BR>
910<pre><b>typedef struct {
911    unsigned windowLog;       </b>/**< largest match distance : larger == more compression, more memory needed during decompression */<b>
912    unsigned chainLog;        </b>/**< fully searched segment : larger == more compression, slower, more memory (useless for fast) */<b>
913    unsigned hashLog;         </b>/**< dispatch table : larger == faster, more memory */<b>
914    unsigned searchLog;       </b>/**< nb of searches : larger == more compression, slower */<b>
915    unsigned minMatch;        </b>/**< match length searched : larger == faster decompression, sometimes less compression */<b>
916    unsigned targetLength;    </b>/**< acceptable match size for optimal parser (only) : larger == more compression, slower */<b>
917    ZSTD_strategy strategy;   </b>/**< see ZSTD_strategy definition above */<b>
918} ZSTD_compressionParameters;
919</b></pre><BR>
920<pre><b>typedef struct {
921    int contentSizeFlag; </b>/**< 1: content size will be in frame header (when known) */<b>
922    int checksumFlag;    </b>/**< 1: generate a 32-bits checksum using XXH64 algorithm at end of frame, for error detection */<b>
923    int noDictIDFlag;    </b>/**< 1: no dictID will be saved into frame header (dictID is only useful for dictionary compression) */<b>
924} ZSTD_frameParameters;
925</b></pre><BR>
926<pre><b>typedef struct {
927    ZSTD_compressionParameters cParams;
928    ZSTD_frameParameters fParams;
929} ZSTD_parameters;
930</b></pre><BR>
931<pre><b>typedef enum {
932    ZSTD_dct_auto = 0,       </b>/* dictionary is "full" when starting with ZSTD_MAGIC_DICTIONARY, otherwise it is "rawContent" */<b>
933    ZSTD_dct_rawContent = 1, </b>/* ensures dictionary is always loaded as rawContent, even if it starts with ZSTD_MAGIC_DICTIONARY */<b>
934    ZSTD_dct_fullDict = 2    </b>/* refuses to load a dictionary if it does not respect Zstandard's specification, starting with ZSTD_MAGIC_DICTIONARY */<b>
935} ZSTD_dictContentType_e;
936</b></pre><BR>
937<pre><b>typedef enum {
938    ZSTD_dlm_byCopy = 0,  </b>/**< Copy dictionary content internally */<b>
939    ZSTD_dlm_byRef = 1    </b>/**< Reference dictionary content -- the dictionary buffer must outlive its users. */<b>
940} ZSTD_dictLoadMethod_e;
941</b></pre><BR>
942<pre><b>typedef enum {
943    ZSTD_f_zstd1 = 0,           </b>/* zstd frame format, specified in zstd_compression_format.md (default) */<b>
944    ZSTD_f_zstd1_magicless = 1  </b>/* Variant of zstd frame format, without initial 4-bytes magic number.<b>
945                                 * Useful to save 4 bytes per generated frame.
946                                 * Decoder cannot recognise automatically this format, requiring this instruction. */
947} ZSTD_format_e;
948</b></pre><BR>
949<pre><b>typedef enum {
950    </b>/* Note: this enum and the behavior it controls are effectively internal<b>
951     * implementation details of the compressor. They are expected to continue
952     * to evolve and should be considered only in the context of extremely
953     * advanced performance tuning.
954     *
955     * Zstd currently supports the use of a CDict in three ways:
956     *
957     * - The contents of the CDict can be copied into the working context. This
958     *   means that the compression can search both the dictionary and input
959     *   while operating on a single set of internal tables. This makes
960     *   the compression faster per-byte of input. However, the initial copy of
961     *   the CDict's tables incurs a fixed cost at the beginning of the
962     *   compression. For small compressions (< 8 KB), that copy can dominate
963     *   the cost of the compression.
964     *
965     * - The CDict's tables can be used in-place. In this model, compression is
966     *   slower per input byte, because the compressor has to search two sets of
967     *   tables. However, this model incurs no start-up cost (as long as the
968     *   working context's tables can be reused). For small inputs, this can be
969     *   faster than copying the CDict's tables.
970     *
971     * - The CDict's tables are not used at all, and instead we use the working
972     *   context alone to reload the dictionary and use params based on the source
973     *   size. See ZSTD_compress_insertDictionary() and ZSTD_compress_usingDict().
974     *   This method is effective when the dictionary sizes are very small relative
975     *   to the input size, and the input size is fairly large to begin with.
976     *
977     * Zstd has a simple internal heuristic that selects which strategy to use
978     * at the beginning of a compression. However, if experimentation shows that
979     * Zstd is making poor choices, it is possible to override that choice with
980     * this enum.
981     */
982    ZSTD_dictDefaultAttach = 0, </b>/* Use the default heuristic. */<b>
983    ZSTD_dictForceAttach   = 1, </b>/* Never copy the dictionary. */<b>
984    ZSTD_dictForceCopy     = 2, </b>/* Always copy the dictionary. */<b>
985    ZSTD_dictForceLoad     = 3  </b>/* Always reload the dictionary */<b>
986} ZSTD_dictAttachPref_e;
987</b></pre><BR>
988<pre><b>typedef enum {
989  ZSTD_lcm_auto = 0,          </b>/**< Automatically determine the compression mode based on the compression level.<b>
990                               *   Negative compression levels will be uncompressed, and positive compression
991                               *   levels will be compressed. */
992  ZSTD_lcm_huffman = 1,       </b>/**< Always attempt Huffman compression. Uncompressed literals will still be<b>
993                               *   emitted if Huffman compression is not profitable. */
994  ZSTD_lcm_uncompressed = 2   </b>/**< Always emit uncompressed literals. */<b>
995} ZSTD_literalCompressionMode_e;
996</b></pre><BR>
997<a name="Chapter15"></a><h2>Frame size functions</h2><pre></pre>
998
999<pre><b>unsigned long long ZSTD_findDecompressedSize(const void* src, size_t srcSize);
1000</b><p>  `src` should point to the start of a series of ZSTD encoded and/or skippable frames
1001  `srcSize` must be the _exact_ size of this series
1002       (i.e. there should be a frame boundary at `src + srcSize`)
1003  @return : - decompressed size of all data in all successive frames
1004            - if the decompressed size cannot be determined: ZSTD_CONTENTSIZE_UNKNOWN
1005            - if an error occurred: ZSTD_CONTENTSIZE_ERROR
1006
1007   note 1 : decompressed size is an optional field, that may not be present, especially in streaming mode.
1008            When `return==ZSTD_CONTENTSIZE_UNKNOWN`, data to decompress could be any size.
1009            In which case, it's necessary to use streaming mode to decompress data.
1010   note 2 : decompressed size is always present when compression is done with ZSTD_compress()
1011   note 3 : decompressed size can be very large (64-bits value),
1012            potentially larger than what local system can handle as a single memory segment.
1013            In which case, it's necessary to use streaming mode to decompress data.
1014   note 4 : If source is untrusted, decompressed size could be wrong or intentionally modified.
1015            Always ensure result fits within application's authorized limits.
1016            Each application can set its own limits.
1017   note 5 : ZSTD_findDecompressedSize handles multiple frames, and so it must traverse the input to
1018            read each contained frame header.  This is fast as most of the data is skipped,
1019            however it does mean that all frame data must be present and valid.
1020</p></pre><BR>
1021
1022<pre><b>unsigned long long ZSTD_decompressBound(const void* src, size_t srcSize);
1023</b><p>  `src` should point to the start of a series of ZSTD encoded and/or skippable frames
1024  `srcSize` must be the _exact_ size of this series
1025       (i.e. there should be a frame boundary at `src + srcSize`)
1026  @return : - upper-bound for the decompressed size of all data in all successive frames
1027            - if an error occured: ZSTD_CONTENTSIZE_ERROR
1028
1029  note 1  : an error can occur if `src` contains an invalid or incorrectly formatted frame.
1030  note 2  : the upper-bound is exact when the decompressed size field is available in every ZSTD encoded frame of `src`.
1031            in this case, `ZSTD_findDecompressedSize` and `ZSTD_decompressBound` return the same value.
1032  note 3  : when the decompressed size field isn't available, the upper-bound for that frame is calculated by:
1033              upper-bound = # blocks * min(128 KB, Window_Size)
1034
1035</p></pre><BR>
1036
1037<pre><b>size_t ZSTD_frameHeaderSize(const void* src, size_t srcSize);
1038</b><p>  srcSize must be >= ZSTD_FRAMEHEADERSIZE_PREFIX.
1039 @return : size of the Frame Header,
1040           or an error code (if srcSize is too small)
1041</p></pre><BR>
1042
1043<pre><b>size_t ZSTD_getSequences(ZSTD_CCtx* zc, ZSTD_Sequence* outSeqs,
1044    size_t outSeqsSize, const void* src, size_t srcSize);
1045</b><p> Extract sequences from the sequence store
1046 zc can be used to insert custom compression params.
1047 This function invokes ZSTD_compress2
1048 @return : number of sequences extracted
1049
1050</p></pre><BR>
1051
1052<a name="Chapter16"></a><h2>Memory management</h2><pre></pre>
1053
1054<pre><b>size_t ZSTD_estimateCCtxSize(int compressionLevel);
1055size_t ZSTD_estimateCCtxSize_usingCParams(ZSTD_compressionParameters cParams);
1056size_t ZSTD_estimateCCtxSize_usingCCtxParams(const ZSTD_CCtx_params* params);
1057size_t ZSTD_estimateDCtxSize(void);
1058</b><p>  These functions make it possible to estimate memory usage of a future
1059  {D,C}Ctx, before its creation.
1060
1061  ZSTD_estimateCCtxSize() will provide a budget large enough for any
1062  compression level up to selected one. Unlike ZSTD_estimateCStreamSize*(),
1063  this estimate does not include space for a window buffer, so this estimate
1064  is guaranteed to be enough for single-shot compressions, but not streaming
1065  compressions. It will however assume the input may be arbitrarily large,
1066  which is the worst case. If srcSize is known to always be small,
1067  ZSTD_estimateCCtxSize_usingCParams() can provide a tighter estimation.
1068  ZSTD_estimateCCtxSize_usingCParams() can be used in tandem with
1069  ZSTD_getCParams() to create cParams from compressionLevel.
1070  ZSTD_estimateCCtxSize_usingCCtxParams() can be used in tandem with
1071  ZSTD_CCtxParams_setParameter().
1072
1073  Note: only single-threaded compression is supported. This function will
1074  return an error code if ZSTD_c_nbWorkers is >= 1.
1075</p></pre><BR>
1076
1077<pre><b>size_t ZSTD_estimateCStreamSize(int compressionLevel);
1078size_t ZSTD_estimateCStreamSize_usingCParams(ZSTD_compressionParameters cParams);
1079size_t ZSTD_estimateCStreamSize_usingCCtxParams(const ZSTD_CCtx_params* params);
1080size_t ZSTD_estimateDStreamSize(size_t windowSize);
1081size_t ZSTD_estimateDStreamSize_fromFrame(const void* src, size_t srcSize);
1082</b><p>  ZSTD_estimateCStreamSize() will provide a budget large enough for any compression level up to selected one.
1083  It will also consider src size to be arbitrarily "large", which is worst case.
1084  If srcSize is known to always be small, ZSTD_estimateCStreamSize_usingCParams() can provide a tighter estimation.
1085  ZSTD_estimateCStreamSize_usingCParams() can be used in tandem with ZSTD_getCParams() to create cParams from compressionLevel.
1086  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.
1087  Note : CStream size estimation is only correct for single-threaded compression.
1088  ZSTD_DStream memory budget depends on window Size.
1089  This information can be passed manually, using ZSTD_estimateDStreamSize,
1090  or deducted from a valid frame Header, using ZSTD_estimateDStreamSize_fromFrame();
1091  Note : if streaming is init with function ZSTD_init?Stream_usingDict(),
1092         an internal ?Dict will be created, which additional size is not estimated here.
1093         In this case, get total size by adding ZSTD_estimate?DictSize
1094</p></pre><BR>
1095
1096<pre><b>size_t ZSTD_estimateCDictSize(size_t dictSize, int compressionLevel);
1097size_t ZSTD_estimateCDictSize_advanced(size_t dictSize, ZSTD_compressionParameters cParams, ZSTD_dictLoadMethod_e dictLoadMethod);
1098size_t ZSTD_estimateDDictSize(size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod);
1099</b><p>  ZSTD_estimateCDictSize() will bet that src size is relatively "small", and content is copied, like ZSTD_createCDict().
1100  ZSTD_estimateCDictSize_advanced() makes it possible to control compression parameters precisely, like ZSTD_createCDict_advanced().
1101  Note : dictionaries created by reference (`ZSTD_dlm_byRef`) are logically smaller.
1102
1103</p></pre><BR>
1104
1105<pre><b>ZSTD_CCtx*    ZSTD_initStaticCCtx(void* workspace, size_t workspaceSize);
1106ZSTD_CStream* ZSTD_initStaticCStream(void* workspace, size_t workspaceSize);    </b>/**< same as ZSTD_initStaticCCtx() */<b>
1107</b><p>  Initialize an object using a pre-allocated fixed-size buffer.
1108  workspace: The memory area to emplace the object into.
1109             Provided pointer *must be 8-bytes aligned*.
1110             Buffer must outlive object.
1111  workspaceSize: Use ZSTD_estimate*Size() to determine
1112                 how large workspace must be to support target scenario.
1113 @return : pointer to object (same address as workspace, just different type),
1114           or NULL if error (size too small, incorrect alignment, etc.)
1115  Note : zstd will never resize nor malloc() when using a static buffer.
1116         If the object requires more memory than available,
1117         zstd will just error out (typically ZSTD_error_memory_allocation).
1118  Note 2 : there is no corresponding "free" function.
1119           Since workspace is allocated externally, it must be freed externally too.
1120  Note 3 : cParams : use ZSTD_getCParams() to convert a compression level
1121           into its associated cParams.
1122  Limitation 1 : currently not compatible with internal dictionary creation, triggered by
1123                 ZSTD_CCtx_loadDictionary(), ZSTD_initCStream_usingDict() or ZSTD_initDStream_usingDict().
1124  Limitation 2 : static cctx currently not compatible with multi-threading.
1125  Limitation 3 : static dctx is incompatible with legacy support.
1126
1127</p></pre><BR>
1128
1129<pre><b>ZSTD_DStream* ZSTD_initStaticDStream(void* workspace, size_t workspaceSize);    </b>/**< same as ZSTD_initStaticDCtx() */<b>
1130</b></pre><BR>
1131<pre><b>typedef void* (*ZSTD_allocFunction) (void* opaque, size_t size);
1132typedef void  (*ZSTD_freeFunction) (void* opaque, void* address);
1133typedef struct { ZSTD_allocFunction customAlloc; ZSTD_freeFunction customFree; void* opaque; } ZSTD_customMem;
1134static ZSTD_customMem const ZSTD_defaultCMem = { NULL, NULL, NULL };  </b>/**< this constant defers to stdlib's functions */<b>
1135</b><p>  These prototypes make it possible to pass your own allocation/free functions.
1136  ZSTD_customMem is provided at creation time, using ZSTD_create*_advanced() variants listed below.
1137  All allocation/free operations will be completed using these custom variants instead of regular <stdlib.h> ones.
1138
1139</p></pre><BR>
1140
1141<a name="Chapter17"></a><h2>Advanced compression functions</h2><pre></pre>
1142
1143<pre><b>ZSTD_CDict* ZSTD_createCDict_byReference(const void* dictBuffer, size_t dictSize, int compressionLevel);
1144</b><p>  Create a digested dictionary for compression
1145  Dictionary content is just referenced, not duplicated.
1146  As a consequence, `dictBuffer` **must** outlive CDict,
1147  and its content must remain unmodified throughout the lifetime of CDict.
1148  note: equivalent to ZSTD_createCDict_advanced(), with dictLoadMethod==ZSTD_dlm_byRef
1149</p></pre><BR>
1150
1151<pre><b>ZSTD_compressionParameters ZSTD_getCParams(int compressionLevel, unsigned long long estimatedSrcSize, size_t dictSize);
1152</b><p> @return ZSTD_compressionParameters structure for a selected compression level and estimated srcSize.
1153 `estimatedSrcSize` value is optional, select 0 if not known
1154</p></pre><BR>
1155
1156<pre><b>ZSTD_parameters ZSTD_getParams(int compressionLevel, unsigned long long estimatedSrcSize, size_t dictSize);
1157</b><p>  same as ZSTD_getCParams(), but @return a full `ZSTD_parameters` object instead of sub-component `ZSTD_compressionParameters`.
1158  All fields of `ZSTD_frameParameters` are set to default : contentSize=1, checksum=0, noDictID=0
1159</p></pre><BR>
1160
1161<pre><b>size_t ZSTD_checkCParams(ZSTD_compressionParameters params);
1162</b><p>  Ensure param values remain within authorized range.
1163 @return 0 on success, or an error code (can be checked with ZSTD_isError())
1164</p></pre><BR>
1165
1166<pre><b>ZSTD_compressionParameters ZSTD_adjustCParams(ZSTD_compressionParameters cPar, unsigned long long srcSize, size_t dictSize);
1167</b><p>  optimize params for a given `srcSize` and `dictSize`.
1168 `srcSize` can be unknown, in which case use ZSTD_CONTENTSIZE_UNKNOWN.
1169 `dictSize` must be `0` when there is no dictionary.
1170  cPar can be invalid : all parameters will be clamped within valid range in the @return struct.
1171  This function never fails (wide contract)
1172</p></pre><BR>
1173
1174<pre><b>size_t ZSTD_compress_advanced(ZSTD_CCtx* cctx,
1175                              void* dst, size_t dstCapacity,
1176                        const void* src, size_t srcSize,
1177                        const void* dict,size_t dictSize,
1178                              ZSTD_parameters params);
1179</b><p>  Note : this function is now DEPRECATED.
1180         It can be replaced by ZSTD_compress2(), in combination with ZSTD_CCtx_setParameter() and other parameter setters.
1181  This prototype will be marked as deprecated and generate compilation warning on reaching v1.5.x
1182</p></pre><BR>
1183
1184<pre><b>size_t ZSTD_compress_usingCDict_advanced(ZSTD_CCtx* cctx,
1185                                  void* dst, size_t dstCapacity,
1186                            const void* src, size_t srcSize,
1187                            const ZSTD_CDict* cdict,
1188                                  ZSTD_frameParameters fParams);
1189</b><p>  Note : this function is now REDUNDANT.
1190         It can be replaced by ZSTD_compress2(), in combination with ZSTD_CCtx_loadDictionary() and other parameter setters.
1191  This prototype will be marked as deprecated and generate compilation warning in some future version
1192</p></pre><BR>
1193
1194<pre><b>size_t ZSTD_CCtx_loadDictionary_byReference(ZSTD_CCtx* cctx, const void* dict, size_t dictSize);
1195</b><p>  Same as ZSTD_CCtx_loadDictionary(), but dictionary content is referenced, instead of being copied into CCtx.
1196  It saves some memory, but also requires that `dict` outlives its usage within `cctx`
1197</p></pre><BR>
1198
1199<pre><b>size_t ZSTD_CCtx_loadDictionary_advanced(ZSTD_CCtx* cctx, const void* dict, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictContentType_e dictContentType);
1200</b><p>  Same as ZSTD_CCtx_loadDictionary(), but gives finer control over
1201  how to load the dictionary (by copy ? by reference ?)
1202  and how to interpret it (automatic ? force raw mode ? full mode only ?)
1203</p></pre><BR>
1204
1205<pre><b>size_t ZSTD_CCtx_refPrefix_advanced(ZSTD_CCtx* cctx, const void* prefix, size_t prefixSize, ZSTD_dictContentType_e dictContentType);
1206</b><p>  Same as ZSTD_CCtx_refPrefix(), but gives finer control over
1207  how to interpret prefix content (automatic ? force raw mode (default) ? full mode only ?)
1208</p></pre><BR>
1209
1210<pre><b>size_t ZSTD_CCtx_getParameter(ZSTD_CCtx* cctx, ZSTD_cParameter param, int* value);
1211</b><p>  Get the requested compression parameter value, selected by enum ZSTD_cParameter,
1212  and store it into int* value.
1213 @return : 0, or an error code (which can be tested with ZSTD_isError()).
1214
1215</p></pre><BR>
1216
1217<pre><b>ZSTD_CCtx_params* ZSTD_createCCtxParams(void);
1218size_t ZSTD_freeCCtxParams(ZSTD_CCtx_params* params);
1219</b><p>  Quick howto :
1220  - ZSTD_createCCtxParams() : Create a ZSTD_CCtx_params structure
1221  - ZSTD_CCtxParams_setParameter() : Push parameters one by one into
1222                                     an existing ZSTD_CCtx_params structure.
1223                                     This is similar to
1224                                     ZSTD_CCtx_setParameter().
1225  - ZSTD_CCtx_setParametersUsingCCtxParams() : Apply parameters to
1226                                    an existing CCtx.
1227                                    These parameters will be applied to
1228                                    all subsequent frames.
1229  - ZSTD_compressStream2() : Do compression using the CCtx.
1230  - ZSTD_freeCCtxParams() : Free the memory.
1231
1232  This can be used with ZSTD_estimateCCtxSize_advanced_usingCCtxParams()
1233  for static allocation of CCtx for single-threaded compression.
1234
1235</p></pre><BR>
1236
1237<pre><b>size_t ZSTD_CCtxParams_reset(ZSTD_CCtx_params* params);
1238</b><p>  Reset params to default values.
1239
1240</p></pre><BR>
1241
1242<pre><b>size_t ZSTD_CCtxParams_init(ZSTD_CCtx_params* cctxParams, int compressionLevel);
1243</b><p>  Initializes the compression parameters of cctxParams according to
1244  compression level. All other parameters are reset to their default values.
1245
1246</p></pre><BR>
1247
1248<pre><b>size_t ZSTD_CCtxParams_init_advanced(ZSTD_CCtx_params* cctxParams, ZSTD_parameters params);
1249</b><p>  Initializes the compression and frame parameters of cctxParams according to
1250  params. All other parameters are reset to their default values.
1251
1252</p></pre><BR>
1253
1254<pre><b>size_t ZSTD_CCtxParams_setParameter(ZSTD_CCtx_params* params, ZSTD_cParameter param, int value);
1255</b><p>  Similar to ZSTD_CCtx_setParameter.
1256  Set one compression parameter, selected by enum ZSTD_cParameter.
1257  Parameters must be applied to a ZSTD_CCtx using ZSTD_CCtx_setParametersUsingCCtxParams().
1258 @result : 0, or an error code (which can be tested with ZSTD_isError()).
1259
1260</p></pre><BR>
1261
1262<pre><b>size_t ZSTD_CCtxParams_getParameter(ZSTD_CCtx_params* params, ZSTD_cParameter param, int* value);
1263</b><p> Similar to ZSTD_CCtx_getParameter.
1264 Get the requested value of one compression parameter, selected by enum ZSTD_cParameter.
1265 @result : 0, or an error code (which can be tested with ZSTD_isError()).
1266
1267</p></pre><BR>
1268
1269<pre><b>size_t ZSTD_CCtx_setParametersUsingCCtxParams(
1270        ZSTD_CCtx* cctx, const ZSTD_CCtx_params* params);
1271</b><p>  Apply a set of ZSTD_CCtx_params to the compression context.
1272  This can be done even after compression is started,
1273    if nbWorkers==0, this will have no impact until a new compression is started.
1274    if nbWorkers>=1, new parameters will be picked up at next job,
1275       with a few restrictions (windowLog, pledgedSrcSize, nbWorkers, jobSize, and overlapLog are not updated).
1276
1277</p></pre><BR>
1278
1279<pre><b>size_t ZSTD_compressStream2_simpleArgs (
1280                ZSTD_CCtx* cctx,
1281                void* dst, size_t dstCapacity, size_t* dstPos,
1282          const void* src, size_t srcSize, size_t* srcPos,
1283                ZSTD_EndDirective endOp);
1284</b><p>  Same as ZSTD_compressStream2(),
1285  but using only integral types as arguments.
1286  This variant might be helpful for binders from dynamic languages
1287  which have troubles handling structures containing memory pointers.
1288
1289</p></pre><BR>
1290
1291<a name="Chapter18"></a><h2>Advanced decompression functions</h2><pre></pre>
1292
1293<pre><b>unsigned ZSTD_isFrame(const void* buffer, size_t size);
1294</b><p>  Tells if the content of `buffer` starts with a valid Frame Identifier.
1295  Note : Frame Identifier is 4 bytes. If `size < 4`, @return will always be 0.
1296  Note 2 : Legacy Frame Identifiers are considered valid only if Legacy Support is enabled.
1297  Note 3 : Skippable Frame Identifiers are considered valid.
1298</p></pre><BR>
1299
1300<pre><b>ZSTD_DDict* ZSTD_createDDict_byReference(const void* dictBuffer, size_t dictSize);
1301</b><p>  Create a digested dictionary, ready to start decompression operation without startup delay.
1302  Dictionary content is referenced, and therefore stays in dictBuffer.
1303  It is important that dictBuffer outlives DDict,
1304  it must remain read accessible throughout the lifetime of DDict
1305</p></pre><BR>
1306
1307<pre><b>size_t ZSTD_DCtx_loadDictionary_byReference(ZSTD_DCtx* dctx, const void* dict, size_t dictSize);
1308</b><p>  Same as ZSTD_DCtx_loadDictionary(),
1309  but references `dict` content instead of copying it into `dctx`.
1310  This saves memory if `dict` remains around.,
1311  However, it's imperative that `dict` remains accessible (and unmodified) while being used, so it must outlive decompression.
1312</p></pre><BR>
1313
1314<pre><b>size_t ZSTD_DCtx_loadDictionary_advanced(ZSTD_DCtx* dctx, const void* dict, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictContentType_e dictContentType);
1315</b><p>  Same as ZSTD_DCtx_loadDictionary(),
1316  but gives direct control over
1317  how to load the dictionary (by copy ? by reference ?)
1318  and how to interpret it (automatic ? force raw mode ? full mode only ?).
1319</p></pre><BR>
1320
1321<pre><b>size_t ZSTD_DCtx_refPrefix_advanced(ZSTD_DCtx* dctx, const void* prefix, size_t prefixSize, ZSTD_dictContentType_e dictContentType);
1322</b><p>  Same as ZSTD_DCtx_refPrefix(), but gives finer control over
1323  how to interpret prefix content (automatic ? force raw mode (default) ? full mode only ?)
1324</p></pre><BR>
1325
1326<pre><b>size_t ZSTD_DCtx_setMaxWindowSize(ZSTD_DCtx* dctx, size_t maxWindowSize);
1327</b><p>  Refuses allocating internal buffers for frames requiring a window size larger than provided limit.
1328  This protects a decoder context from reserving too much memory for itself (potential attack scenario).
1329  This parameter is only useful in streaming mode, since no internal buffer is allocated in single-pass mode.
1330  By default, a decompression context accepts all window sizes <= (1 << ZSTD_WINDOWLOG_LIMIT_DEFAULT)
1331 @return : 0, or an error code (which can be tested using ZSTD_isError()).
1332
1333</p></pre><BR>
1334
1335<pre><b>size_t ZSTD_DCtx_setFormat(ZSTD_DCtx* dctx, ZSTD_format_e format);
1336</b><p>  Instruct the decoder context about what kind of data to decode next.
1337  This instruction is mandatory to decode data without a fully-formed header,
1338  such ZSTD_f_zstd1_magicless for example.
1339 @return : 0, or an error code (which can be tested using ZSTD_isError()).
1340</p></pre><BR>
1341
1342<pre><b>size_t ZSTD_decompressStream_simpleArgs (
1343                ZSTD_DCtx* dctx,
1344                void* dst, size_t dstCapacity, size_t* dstPos,
1345          const void* src, size_t srcSize, size_t* srcPos);
1346</b><p>  Same as ZSTD_decompressStream(),
1347  but using only integral types as arguments.
1348  This can be helpful for binders from dynamic languages
1349  which have troubles handling structures containing memory pointers.
1350
1351</p></pre><BR>
1352
1353<a name="Chapter19"></a><h2>Advanced streaming functions</h2><pre>  Warning : most of these functions are now redundant with the Advanced API.
1354  Once Advanced API reaches "stable" status,
1355  redundant functions will be deprecated, and then at some point removed.
1356<BR></pre>
1357
1358<h3>Advanced Streaming compression functions</h3><pre></pre><b><pre></b>/**! ZSTD_initCStream_srcSize() :<b>
1359 * This function is deprecated, and equivalent to:
1360 *     ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
1361 *     ZSTD_CCtx_refCDict(zcs, NULL); // clear the dictionary (if any)
1362 *     ZSTD_CCtx_setParameter(zcs, ZSTD_c_compressionLevel, compressionLevel);
1363 *     ZSTD_CCtx_setPledgedSrcSize(zcs, pledgedSrcSize);
1364 *
1365 * pledgedSrcSize must be correct. If it is not known at init time, use
1366 * ZSTD_CONTENTSIZE_UNKNOWN. Note that, for compatibility with older programs,
1367 * "0" also disables frame content size field. It may be enabled in the future.
1368 * Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x
1369 */
1370size_t
1371ZSTD_initCStream_srcSize(ZSTD_CStream* zcs,
1372                         int compressionLevel,
1373                         unsigned long long pledgedSrcSize);
1374</pre></b><BR>
1375<a name="Chapter20"></a><h2>! ZSTD_initCStream_usingDict() :</h2><pre> This function is deprecated, and is equivalent to:
1376     ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
1377     ZSTD_CCtx_setParameter(zcs, ZSTD_c_compressionLevel, compressionLevel);
1378     ZSTD_CCtx_loadDictionary(zcs, dict, dictSize);
1379
1380 Creates of an internal CDict (incompatible with static CCtx), except if
1381 dict == NULL or dictSize < 8, in which case no dict is used.
1382 Note: dict is loaded with ZSTD_dct_auto (treated as a full zstd dictionary if
1383 it begins with ZSTD_MAGIC_DICTIONARY, else as raw content) and ZSTD_dlm_byCopy.
1384 Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x
1385
1386<BR></pre>
1387
1388<a name="Chapter21"></a><h2>! ZSTD_initCStream_advanced() :</h2><pre> This function is deprecated, and is approximately equivalent to:
1389     ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
1390     // Pseudocode: Set each zstd parameter and leave the rest as-is.
1391     for ((param, value) : params) {
1392         ZSTD_CCtx_setParameter(zcs, param, value);
1393     }
1394     ZSTD_CCtx_setPledgedSrcSize(zcs, pledgedSrcSize);
1395     ZSTD_CCtx_loadDictionary(zcs, dict, dictSize);
1396
1397 dict is loaded with ZSTD_dct_auto and ZSTD_dlm_byCopy.
1398 pledgedSrcSize must be correct.
1399 If srcSize is not known at init time, use value ZSTD_CONTENTSIZE_UNKNOWN.
1400 Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x
1401
1402<BR></pre>
1403
1404<a name="Chapter22"></a><h2>! ZSTD_initCStream_usingCDict() :</h2><pre> This function is deprecated, and equivalent to:
1405     ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
1406     ZSTD_CCtx_refCDict(zcs, cdict);
1407
1408 note : cdict will just be referenced, and must outlive compression session
1409 Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x
1410
1411<BR></pre>
1412
1413<a name="Chapter23"></a><h2>! ZSTD_initCStream_usingCDict_advanced() :</h2><pre>   This function is DEPRECATED, and is approximately equivalent to:
1414     ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
1415     // Pseudocode: Set each zstd frame parameter and leave the rest as-is.
1416     for ((fParam, value) : fParams) {
1417         ZSTD_CCtx_setParameter(zcs, fParam, value);
1418     }
1419     ZSTD_CCtx_setPledgedSrcSize(zcs, pledgedSrcSize);
1420     ZSTD_CCtx_refCDict(zcs, cdict);
1421
1422 same as ZSTD_initCStream_usingCDict(), with control over frame parameters.
1423 pledgedSrcSize must be correct. If srcSize is not known at init time, use
1424 value ZSTD_CONTENTSIZE_UNKNOWN.
1425 Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x
1426
1427<BR></pre>
1428
1429<pre><b>size_t ZSTD_resetCStream(ZSTD_CStream* zcs, unsigned long long pledgedSrcSize);
1430</b><p> This function is deprecated, and is equivalent to:
1431     ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
1432     ZSTD_CCtx_setPledgedSrcSize(zcs, pledgedSrcSize);
1433
1434  start a new frame, using same parameters from previous frame.
1435  This is typically useful to skip dictionary loading stage, since it will re-use it in-place.
1436  Note that zcs must be init at least once before using ZSTD_resetCStream().
1437  If pledgedSrcSize is not known at reset time, use macro ZSTD_CONTENTSIZE_UNKNOWN.
1438  If pledgedSrcSize > 0, its value must be correct, as it will be written in header, and controlled at the end.
1439  For the time being, pledgedSrcSize==0 is interpreted as "srcSize unknown" for compatibility with older programs,
1440  but it will change to mean "empty" in future version, so use macro ZSTD_CONTENTSIZE_UNKNOWN instead.
1441 @return : 0, or an error code (which can be tested using ZSTD_isError())
1442  Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x
1443
1444</p></pre><BR>
1445
1446<pre><b>typedef struct {
1447    unsigned long long ingested;   </b>/* nb input bytes read and buffered */<b>
1448    unsigned long long consumed;   </b>/* nb input bytes actually compressed */<b>
1449    unsigned long long produced;   </b>/* nb of compressed bytes generated and buffered */<b>
1450    unsigned long long flushed;    </b>/* nb of compressed bytes flushed : not provided; can be tracked from caller side */<b>
1451    unsigned currentJobID;         </b>/* MT only : latest started job nb */<b>
1452    unsigned nbActiveWorkers;      </b>/* MT only : nb of workers actively compressing at probe time */<b>
1453} ZSTD_frameProgression;
1454</b></pre><BR>
1455<pre><b>size_t ZSTD_toFlushNow(ZSTD_CCtx* cctx);
1456</b><p>  Tell how many bytes are ready to be flushed immediately.
1457  Useful for multithreading scenarios (nbWorkers >= 1).
1458  Probe the oldest active job, defined as oldest job not yet entirely flushed,
1459  and check its output buffer.
1460 @return : amount of data stored in oldest job and ready to be flushed immediately.
1461  if @return == 0, it means either :
1462  + there is no active job (could be checked with ZSTD_frameProgression()), or
1463  + oldest job is still actively compressing data,
1464    but everything it has produced has also been flushed so far,
1465    therefore flush speed is limited by production speed of oldest job
1466    irrespective of the speed of concurrent (and newer) jobs.
1467
1468</p></pre><BR>
1469
1470<h3>Advanced Streaming decompression functions</h3><pre></pre><b><pre></b>/**<b>
1471 * This function is deprecated, and is equivalent to:
1472 *
1473 *     ZSTD_DCtx_reset(zds, ZSTD_reset_session_only);
1474 *     ZSTD_DCtx_loadDictionary(zds, dict, dictSize);
1475 *
1476 * note: no dictionary will be used if dict == NULL or dictSize < 8
1477 * Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x
1478 */
1479size_t ZSTD_initDStream_usingDict(ZSTD_DStream* zds, const void* dict, size_t dictSize);
1480</pre></b><BR>
1481<a name="Chapter24"></a><h2>This function is deprecated, and is equivalent to:</h2><pre>
1482     ZSTD_DCtx_reset(zds, ZSTD_reset_session_only);
1483     ZSTD_DCtx_refDDict(zds, ddict);
1484
1485 note : ddict is referenced, it must outlive decompression session
1486 Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x
1487
1488<BR></pre>
1489
1490<a name="Chapter25"></a><h2>This function is deprecated, and is equivalent to:</h2><pre>
1491     ZSTD_DCtx_reset(zds, ZSTD_reset_session_only);
1492
1493 re-use decompression parameters from previous init; saves dictionary loading
1494 Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x
1495
1496<BR></pre>
1497
1498<a name="Chapter26"></a><h2>Buffer-less and synchronous inner streaming functions</h2><pre>
1499  This is an advanced API, giving full control over buffer management, for users which need direct control over memory.
1500  But it's also a complex one, with several restrictions, documented below.
1501  Prefer normal streaming API for an easier experience.
1502
1503<BR></pre>
1504
1505<a name="Chapter27"></a><h2>Buffer-less streaming compression (synchronous mode)</h2><pre>
1506  A ZSTD_CCtx object is required to track streaming operations.
1507  Use ZSTD_createCCtx() / ZSTD_freeCCtx() to manage resource.
1508  ZSTD_CCtx object can be re-used multiple times within successive compression operations.
1509
1510  Start by initializing a context.
1511  Use ZSTD_compressBegin(), or ZSTD_compressBegin_usingDict() for dictionary compression,
1512  or ZSTD_compressBegin_advanced(), for finer parameter control.
1513  It's also possible to duplicate a reference context which has already been initialized, using ZSTD_copyCCtx()
1514
1515  Then, consume your input using ZSTD_compressContinue().
1516  There are some important considerations to keep in mind when using this advanced function :
1517  - ZSTD_compressContinue() has no internal buffer. It uses externally provided buffers only.
1518  - Interface is synchronous : input is consumed entirely and produces 1+ compressed blocks.
1519  - Caller must ensure there is enough space in `dst` to store compressed data under worst case scenario.
1520    Worst case evaluation is provided by ZSTD_compressBound().
1521    ZSTD_compressContinue() doesn't guarantee recover after a failed compression.
1522  - ZSTD_compressContinue() presumes prior input ***is still accessible and unmodified*** (up to maximum distance size, see WindowLog).
1523    It remembers all previous contiguous blocks, plus one separated memory segment (which can itself consists of multiple contiguous blocks)
1524  - ZSTD_compressContinue() detects that prior input has been overwritten when `src` buffer overlaps.
1525    In which case, it will "discard" the relevant memory section from its history.
1526
1527  Finish a frame with ZSTD_compressEnd(), which will write the last block(s) and optional checksum.
1528  It's possible to use srcSize==0, in which case, it will write a final empty block to end the frame.
1529  Without last block mark, frames are considered unfinished (hence corrupted) by compliant decoders.
1530
1531  `ZSTD_CCtx` object can be re-used (ZSTD_compressBegin()) to compress again.
1532<BR></pre>
1533
1534<h3>Buffer-less streaming compression functions</h3><pre></pre><b><pre>size_t ZSTD_compressBegin(ZSTD_CCtx* cctx, int compressionLevel);
1535size_t ZSTD_compressBegin_usingDict(ZSTD_CCtx* cctx, const void* dict, size_t dictSize, int compressionLevel);
1536size_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>
1537size_t ZSTD_compressBegin_usingCDict(ZSTD_CCtx* cctx, const ZSTD_CDict* cdict); </b>/**< note: fails if cdict==NULL */<b>
1538size_t ZSTD_compressBegin_usingCDict_advanced(ZSTD_CCtx* const cctx, const ZSTD_CDict* const cdict, ZSTD_frameParameters const fParams, unsigned long long const pledgedSrcSize);   </b>/* compression parameters are already set within cdict. pledgedSrcSize must be correct. If srcSize is not known, use macro ZSTD_CONTENTSIZE_UNKNOWN */<b>
1539size_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>
1540</pre></b><BR>
1541<a name="Chapter28"></a><h2>Buffer-less streaming decompression (synchronous mode)</h2><pre>
1542  A ZSTD_DCtx object is required to track streaming operations.
1543  Use ZSTD_createDCtx() / ZSTD_freeDCtx() to manage it.
1544  A ZSTD_DCtx object can be re-used multiple times.
1545
1546  First typical operation is to retrieve frame parameters, using ZSTD_getFrameHeader().
1547  Frame header is extracted from the beginning of compressed frame, so providing only the frame's beginning is enough.
1548  Data fragment must be large enough to ensure successful decoding.
1549 `ZSTD_frameHeaderSize_max` bytes is guaranteed to always be large enough.
1550  @result : 0 : successful decoding, the `ZSTD_frameHeader` structure is correctly filled.
1551           >0 : `srcSize` is too small, please provide at least @result bytes on next attempt.
1552           errorCode, which can be tested using ZSTD_isError().
1553
1554  It fills a ZSTD_frameHeader structure with important information to correctly decode the frame,
1555  such as the dictionary ID, content size, or maximum back-reference distance (`windowSize`).
1556  Note that these values could be wrong, either because of data corruption, or because a 3rd party deliberately spoofs false information.
1557  As a consequence, check that values remain within valid application range.
1558  For example, do not allocate memory blindly, check that `windowSize` is within expectation.
1559  Each application can set its own limits, depending on local restrictions.
1560  For extended interoperability, it is recommended to support `windowSize` of at least 8 MB.
1561
1562  ZSTD_decompressContinue() needs previous data blocks during decompression, up to `windowSize` bytes.
1563  ZSTD_decompressContinue() is very sensitive to contiguity,
1564  if 2 blocks don't follow each other, make sure that either the compressor breaks contiguity at the same place,
1565  or that previous contiguous segment is large enough to properly handle maximum back-reference distance.
1566  There are multiple ways to guarantee this condition.
1567
1568  The most memory efficient way is to use a round buffer of sufficient size.
1569  Sufficient size is determined by invoking ZSTD_decodingBufferSize_min(),
1570  which can @return an error code if required value is too large for current system (in 32-bits mode).
1571  In a round buffer methodology, ZSTD_decompressContinue() decompresses each block next to previous one,
1572  up to the moment there is not enough room left in the buffer to guarantee decoding another full block,
1573  which maximum size is provided in `ZSTD_frameHeader` structure, field `blockSizeMax`.
1574  At which point, decoding can resume from the beginning of the buffer.
1575  Note that already decoded data stored in the buffer should be flushed before being overwritten.
1576
1577  There are alternatives possible, for example using two or more buffers of size `windowSize` each, though they consume more memory.
1578
1579  Finally, if you control the compression process, you can also ignore all buffer size rules,
1580  as long as the encoder and decoder progress in "lock-step",
1581  aka use exactly the same buffer sizes, break contiguity at the same place, etc.
1582
1583  Once buffers are setup, start decompression, with ZSTD_decompressBegin().
1584  If decompression requires a dictionary, use ZSTD_decompressBegin_usingDict() or ZSTD_decompressBegin_usingDDict().
1585
1586  Then use ZSTD_nextSrcSizeToDecompress() and ZSTD_decompressContinue() alternatively.
1587  ZSTD_nextSrcSizeToDecompress() tells how many bytes to provide as 'srcSize' to ZSTD_decompressContinue().
1588  ZSTD_decompressContinue() requires this _exact_ amount of bytes, or it will fail.
1589
1590 @result of ZSTD_decompressContinue() is the number of bytes regenerated within 'dst' (necessarily <= dstCapacity).
1591  It can be zero : it just means ZSTD_decompressContinue() has decoded some metadata item.
1592  It can also be an error code, which can be tested with ZSTD_isError().
1593
1594  A frame is fully decoded when ZSTD_nextSrcSizeToDecompress() returns zero.
1595  Context can then be reset to start a new decompression.
1596
1597  Note : it's possible to know if next input to present is a header or a block, using ZSTD_nextInputType().
1598  This information is not required to properly decode a frame.
1599
1600  == Special case : skippable frames
1601
1602  Skippable frames allow integration of user-defined data into a flow of concatenated frames.
1603  Skippable frames will be ignored (skipped) by decompressor.
1604  The format of skippable frames is as follows :
1605  a) Skippable frame ID - 4 Bytes, Little endian format, any value from 0x184D2A50 to 0x184D2A5F
1606  b) Frame Size - 4 Bytes, Little endian format, unsigned 32-bits
1607  c) Frame Content - any content (User Data) of length equal to Frame Size
1608  For skippable frames ZSTD_getFrameHeader() returns zfhPtr->frameType==ZSTD_skippableFrame.
1609  For skippable frames ZSTD_decompressContinue() always returns 0 : it only skips the content.
1610<BR></pre>
1611
1612<h3>Buffer-less streaming decompression functions</h3><pre></pre><b><pre>typedef enum { ZSTD_frame, ZSTD_skippableFrame } ZSTD_frameType_e;
1613typedef struct {
1614    unsigned long long frameContentSize; </b>/* if == ZSTD_CONTENTSIZE_UNKNOWN, it means this field is not available. 0 means "empty" */<b>
1615    unsigned long long windowSize;       </b>/* can be very large, up to <= frameContentSize */<b>
1616    unsigned blockSizeMax;
1617    ZSTD_frameType_e frameType;          </b>/* if == ZSTD_skippableFrame, frameContentSize is the size of skippable content */<b>
1618    unsigned headerSize;
1619    unsigned dictID;
1620    unsigned checksumFlag;
1621} ZSTD_frameHeader;
1622</pre></b><BR>
1623<pre><b>size_t ZSTD_getFrameHeader(ZSTD_frameHeader* zfhPtr, const void* src, size_t srcSize);   </b>/**< doesn't consume input */<b>
1624</b>/*! ZSTD_getFrameHeader_advanced() :<b>
1625 *  same as ZSTD_getFrameHeader(),
1626 *  with added capability to select a format (like ZSTD_f_zstd1_magicless) */
1627size_t ZSTD_getFrameHeader_advanced(ZSTD_frameHeader* zfhPtr, const void* src, size_t srcSize, ZSTD_format_e format);
1628size_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>
1629</b><p>  decode Frame Header, or requires larger `srcSize`.
1630 @return : 0, `zfhPtr` is correctly filled,
1631          >0, `srcSize` is too small, value is wanted `srcSize` amount,
1632           or an error code, which can be tested using ZSTD_isError()
1633</p></pre><BR>
1634
1635<pre><b>typedef enum { ZSTDnit_frameHeader, ZSTDnit_blockHeader, ZSTDnit_block, ZSTDnit_lastBlock, ZSTDnit_checksum, ZSTDnit_skippableFrame } ZSTD_nextInputType_e;
1636</b></pre><BR>
1637<a name="Chapter29"></a><h2>Block level API</h2><pre></pre>
1638
1639<pre><b></b><p>    Frame metadata cost is typically ~12 bytes, which can be non-negligible for very small blocks (< 100 bytes).
1640    But users will have to take in charge needed metadata to regenerate data, such as compressed and content sizes.
1641
1642    A few rules to respect :
1643    - Compressing and decompressing require a context structure
1644      + Use ZSTD_createCCtx() and ZSTD_createDCtx()
1645    - It is necessary to init context before starting
1646      + compression : any ZSTD_compressBegin*() variant, including with dictionary
1647      + decompression : any ZSTD_decompressBegin*() variant, including with dictionary
1648      + copyCCtx() and copyDCtx() can be used too
1649    - Block size is limited, it must be <= ZSTD_getBlockSize() <= ZSTD_BLOCKSIZE_MAX == 128 KB
1650      + If input is larger than a block size, it's necessary to split input data into multiple blocks
1651      + For inputs larger than a single block, consider using regular ZSTD_compress() instead.
1652        Frame metadata is not that costly, and quickly becomes negligible as source size grows larger than a block.
1653    - When a block is considered not compressible enough, ZSTD_compressBlock() result will be 0 (zero) !
1654      ===> In which case, nothing is produced into `dst` !
1655      + User __must__ test for such outcome and deal directly with uncompressed data
1656      + A block cannot be declared incompressible if ZSTD_compressBlock() return value was != 0.
1657        Doing so would mess up with statistics history, leading to potential data corruption.
1658      + ZSTD_decompressBlock() _doesn't accept uncompressed data as input_ !!
1659      + In case of multiple successive blocks, should some of them be uncompressed,
1660        decoder must be informed of their existence in order to follow proper history.
1661        Use ZSTD_insertBlock() for such a case.
1662</p></pre><BR>
1663
1664<h3>Raw zstd block functions</h3><pre></pre><b><pre>size_t ZSTD_getBlockSize   (const ZSTD_CCtx* cctx);
1665size_t ZSTD_compressBlock  (ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize);
1666size_t ZSTD_decompressBlock(ZSTD_DCtx* dctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize);
1667size_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>
1668</pre></b><BR>
1669</html>
1670</body>
1671