]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/contrib/zstd/doc/zstd_manual.html
Upgrade Unbound to 1.6.2. More to follow.
[FreeBSD/FreeBSD.git] / sys / contrib / zstd / doc / zstd_manual.html
1 <html>
2 <head>
3 <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
4 <title>zstd 1.3.4 Manual</title>
5 </head>
6 <body>
7 <h1>zstd 1.3.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">Simple dictionary API</a></li>
16 <li><a href="#Chapter6">Bulk processing dictionary 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">START OF ADVANCED AND EXPERIMENTAL FUNCTIONS</a></li>
21 <li><a href="#Chapter11">Advanced types</a></li>
22 <li><a href="#Chapter12">Frame size functions</a></li>
23 <li><a href="#Chapter13">Memory management</a></li>
24 <li><a href="#Chapter14">Advanced compression functions</a></li>
25 <li><a href="#Chapter15">Advanced decompression functions</a></li>
26 <li><a href="#Chapter16">Advanced streaming functions</a></li>
27 <li><a href="#Chapter17">Buffer-less and synchronous inner streaming functions</a></li>
28 <li><a href="#Chapter18">Buffer-less streaming compression (synchronous mode)</a></li>
29 <li><a href="#Chapter19">Buffer-less streaming decompression (synchronous mode)</a></li>
30 <li><a href="#Chapter20">New advanced API (experimental)</a></li>
31 <li><a href="#Chapter21">Block level API</a></li>
32 </ol>
33 <hr>
34 <a name="Chapter1"></a><h2>Introduction</h2><pre>
35   zstd, short for Zstandard, is a fast lossless compression algorithm,
36   targeting real-time compression scenarios at zlib-level and better compression ratios.
37   The zstd compression library provides in-memory compression and decompression functions.
38   The library supports compression levels from 1 up to ZSTD_maxCLevel() which is currently 22.
39   Levels >= 20, labeled `--ultra`, should be used with caution, as they require more memory.
40   Compression can be done in:
41     - a single step (described as Simple API)
42     - a single step, reusing a context (described as Explicit context)
43     - unbounded multiple steps (described as Streaming compression)
44   The compression ratio achievable on small data can be highly improved using a dictionary in:
45     - a single step (described as Simple dictionary API)
46     - a single step, reusing a dictionary (described as Bulk-processing dictionary API)
47
48   Advanced experimental functions can be accessed using #define ZSTD_STATIC_LINKING_ONLY before including zstd.h.
49   Advanced experimental APIs shall never be used with a dynamic library.
50   They are not "stable", their definition may change in the future. Only static linking is allowed.
51 <BR></pre>
52
53 <a name="Chapter2"></a><h2>Version</h2><pre></pre>
54
55 <pre><b>unsigned ZSTD_versionNumber(void);   </b>/**< useful to check dll version */<b>
56 </b></pre><BR>
57 <a name="Chapter3"></a><h2>Simple API</h2><pre></pre>
58
59 <pre><b>size_t ZSTD_compress( void* dst, size_t dstCapacity,
60                 const void* src, size_t srcSize,
61                       int compressionLevel);
62 </b><p>  Compresses `src` content as a single zstd compressed frame into already allocated `dst`.
63   Hint : compression runs faster if `dstCapacity` >=  `ZSTD_compressBound(srcSize)`.
64   @return : compressed size written into `dst` (<= `dstCapacity),
65             or an error code if it fails (which can be tested using ZSTD_isError()). 
66 </p></pre><BR>
67
68 <pre><b>size_t ZSTD_decompress( void* dst, size_t dstCapacity,
69                   const void* src, size_t compressedSize);
70 </b><p>  `compressedSize` : must be the _exact_ size of some number of compressed and/or skippable frames.
71   `dstCapacity` is an upper bound of originalSize to regenerate.
72   If user cannot imply a maximum upper bound, it's better to use streaming mode to decompress data.
73   @return : the number of bytes decompressed into `dst` (<= `dstCapacity`),
74             or an errorCode if it fails (which can be tested using ZSTD_isError()). 
75 </p></pre><BR>
76
77 <pre><b>#define ZSTD_CONTENTSIZE_UNKNOWN (0ULL - 1)
78 #define ZSTD_CONTENTSIZE_ERROR   (0ULL - 2)
79 unsigned long long ZSTD_getFrameContentSize(const void *src, size_t srcSize);
80 </b><p>  `src` should point to the start of a ZSTD encoded frame.
81   `srcSize` must be at least as large as the frame header.
82             hint : any size >= `ZSTD_frameHeaderSize_max` is large enough.
83   @return : - decompressed size of the frame in `src`, if known
84             - ZSTD_CONTENTSIZE_UNKNOWN if the size cannot be determined
85             - ZSTD_CONTENTSIZE_ERROR if an error occurred (e.g. invalid magic number, srcSize too small)
86    note 1 : a 0 return value means the frame is valid but "empty".
87    note 2 : decompressed size is an optional field, it may not be present, typically in streaming mode.
88             When `return==ZSTD_CONTENTSIZE_UNKNOWN`, data to decompress could be any size.
89             In which case, it's necessary to use streaming mode to decompress data.
90             Optionally, application can rely on some implicit limit,
91             as ZSTD_decompress() only needs an upper bound of decompressed size.
92             (For example, data could be necessarily cut into blocks <= 16 KB).
93    note 3 : decompressed size is always present when compression is done with ZSTD_compress()
94    note 4 : decompressed size can be very large (64-bits value),
95             potentially larger than what local system can handle as a single memory segment.
96             In which case, it's necessary to use streaming mode to decompress data.
97    note 5 : If source is untrusted, decompressed size could be wrong or intentionally modified.
98             Always ensure return value fits within application's authorized limits.
99             Each application can set its own limits.
100    note 6 : This function replaces ZSTD_getDecompressedSize() 
101 </p></pre><BR>
102
103 <pre><b>unsigned long long ZSTD_getDecompressedSize(const void* src, size_t srcSize);
104 </b><p>  NOTE: This function is now obsolete, in favor of ZSTD_getFrameContentSize().
105   Both functions work the same way, but ZSTD_getDecompressedSize() blends
106   "empty", "unknown" and "error" results to the same return value (0),
107   while ZSTD_getFrameContentSize() gives them separate return values.
108  `src` is the start of a zstd compressed frame.
109  @return : content size to be decompressed, as a 64-bits value _if known and not empty_, 0 otherwise. 
110 </p></pre><BR>
111
112 <h3>Helper functions</h3><pre></pre><b><pre>#define ZSTD_COMPRESSBOUND(srcSize)   ((srcSize) + ((srcSize)>>8) + (((srcSize) < (128<<10)) ? (((128<<10) - (srcSize)) >> 11) </b>/* margin, from 64 to 0 */ : 0))  /* this formula ensures that bound(A) + bound(B) <= bound(A+B) as long as A and B >= 128 KB */<b>
113 size_t      ZSTD_compressBound(size_t srcSize); </b>/*!< maximum compressed size in worst case single-pass scenario */<b>
114 unsigned    ZSTD_isError(size_t code);          </b>/*!< tells if a `size_t` function result is an error code */<b>
115 const char* ZSTD_getErrorName(size_t code);     </b>/*!< provides readable string from an error code */<b>
116 int         ZSTD_maxCLevel(void);               </b>/*!< maximum compression level available */<b>
117 </pre></b><BR>
118 <a name="Chapter4"></a><h2>Explicit context</h2><pre></pre>
119
120 <h3>Compression context</h3><pre>  When compressing many times,
121   it is recommended to allocate a context just once, and re-use it for each successive compression operation.
122   This will make workload friendlier for system's memory.
123   Use one context per thread for parallel execution in multi-threaded environments. 
124 </pre><b><pre>typedef struct ZSTD_CCtx_s ZSTD_CCtx;
125 ZSTD_CCtx* ZSTD_createCCtx(void);
126 size_t     ZSTD_freeCCtx(ZSTD_CCtx* cctx);
127 </pre></b><BR>
128 <pre><b>size_t ZSTD_compressCCtx(ZSTD_CCtx* ctx,
129                          void* dst, size_t dstCapacity,
130                    const void* src, size_t srcSize,
131                          int compressionLevel);
132 </b><p>  Same as ZSTD_compress(), requires an allocated ZSTD_CCtx (see ZSTD_createCCtx()). 
133 </p></pre><BR>
134
135 <h3>Decompression context</h3><pre>  When decompressing many times,
136   it is recommended to allocate a context only once,
137   and re-use it for each successive compression operation.
138   This will make workload friendlier for system's memory.
139   Use one context per thread for parallel execution. 
140 </pre><b><pre>typedef struct ZSTD_DCtx_s ZSTD_DCtx;
141 ZSTD_DCtx* ZSTD_createDCtx(void);
142 size_t     ZSTD_freeDCtx(ZSTD_DCtx* dctx);
143 </pre></b><BR>
144 <pre><b>size_t ZSTD_decompressDCtx(ZSTD_DCtx* ctx,
145                            void* dst, size_t dstCapacity,
146                      const void* src, size_t srcSize);
147 </b><p>  Same as ZSTD_decompress(), requires an allocated ZSTD_DCtx (see ZSTD_createDCtx()) 
148 </p></pre><BR>
149
150 <a name="Chapter5"></a><h2>Simple dictionary API</h2><pre></pre>
151
152 <pre><b>size_t ZSTD_compress_usingDict(ZSTD_CCtx* ctx,
153                                void* dst, size_t dstCapacity,
154                          const void* src, size_t srcSize,
155                          const void* dict,size_t dictSize,
156                                int compressionLevel);
157 </b><p>  Compression using a predefined Dictionary (see dictBuilder/zdict.h).
158   Note : This function loads the dictionary, resulting in significant startup delay.
159   Note : When `dict == NULL || dictSize < 8` no dictionary is used. 
160 </p></pre><BR>
161
162 <pre><b>size_t ZSTD_decompress_usingDict(ZSTD_DCtx* dctx,
163                                  void* dst, size_t dstCapacity,
164                            const void* src, size_t srcSize,
165                            const void* dict,size_t dictSize);
166 </b><p>  Decompression using a predefined Dictionary (see dictBuilder/zdict.h).
167   Dictionary must be identical to the one used during compression.
168   Note : This function loads the dictionary, resulting in significant startup delay.
169   Note : When `dict == NULL || dictSize < 8` no dictionary is used. 
170 </p></pre><BR>
171
172 <a name="Chapter6"></a><h2>Bulk processing dictionary API</h2><pre></pre>
173
174 <pre><b>ZSTD_CDict* ZSTD_createCDict(const void* dictBuffer, size_t dictSize,
175                              int compressionLevel);
176 </b><p>  When compressing multiple messages / blocks with the same dictionary, it's recommended to load it just once.
177   ZSTD_createCDict() will create a digested dictionary, ready to start future compression operations without startup delay.
178   ZSTD_CDict can be created once and shared by multiple threads concurrently, since its usage is read-only.
179   `dictBuffer` can be released after ZSTD_CDict creation, since its content is copied within CDict 
180 </p></pre><BR>
181
182 <pre><b>size_t      ZSTD_freeCDict(ZSTD_CDict* CDict);
183 </b><p>  Function frees memory allocated by ZSTD_createCDict(). 
184 </p></pre><BR>
185
186 <pre><b>size_t ZSTD_compress_usingCDict(ZSTD_CCtx* cctx,
187                                 void* dst, size_t dstCapacity,
188                           const void* src, size_t srcSize,
189                           const ZSTD_CDict* cdict);
190 </b><p>  Compression using a digested Dictionary.
191   Faster startup than ZSTD_compress_usingDict(), recommended when same dictionary is used multiple times.
192   Note that compression level is decided during dictionary creation.
193   Frame parameters are hardcoded (dictID=yes, contentSize=yes, checksum=no) 
194 </p></pre><BR>
195
196 <pre><b>ZSTD_DDict* ZSTD_createDDict(const void* dictBuffer, size_t dictSize);
197 </b><p>  Create a digested dictionary, ready to start decompression operation without startup delay.
198   dictBuffer can be released after DDict creation, as its content is copied inside DDict 
199 </p></pre><BR>
200
201 <pre><b>size_t      ZSTD_freeDDict(ZSTD_DDict* ddict);
202 </b><p>  Function frees memory allocated with ZSTD_createDDict() 
203 </p></pre><BR>
204
205 <pre><b>size_t ZSTD_decompress_usingDDict(ZSTD_DCtx* dctx,
206                                   void* dst, size_t dstCapacity,
207                             const void* src, size_t srcSize,
208                             const ZSTD_DDict* ddict);
209 </b><p>  Decompression using a digested Dictionary.
210   Faster startup than ZSTD_decompress_usingDict(), recommended when same dictionary is used multiple times. 
211 </p></pre><BR>
212
213 <a name="Chapter7"></a><h2>Streaming</h2><pre></pre>
214
215 <pre><b>typedef struct ZSTD_inBuffer_s {
216   const void* src;    </b>/**< start of input buffer */<b>
217   size_t size;        </b>/**< size of input buffer */<b>
218   size_t pos;         </b>/**< position where reading stopped. Will be updated. Necessarily 0 <= pos <= size */<b>
219 } ZSTD_inBuffer;
220 </b></pre><BR>
221 <pre><b>typedef struct ZSTD_outBuffer_s {
222   void*  dst;         </b>/**< start of output buffer */<b>
223   size_t size;        </b>/**< size of output buffer */<b>
224   size_t pos;         </b>/**< position where writing stopped. Will be updated. Necessarily 0 <= pos <= size */<b>
225 } ZSTD_outBuffer;
226 </b></pre><BR>
227 <a name="Chapter8"></a><h2>Streaming compression - HowTo</h2><pre>
228   A ZSTD_CStream object is required to track streaming operation.
229   Use ZSTD_createCStream() and ZSTD_freeCStream() to create/release resources.
230   ZSTD_CStream objects can be reused multiple times on consecutive compression operations.
231   It is recommended to re-use ZSTD_CStream in situations where many streaming operations will be achieved consecutively,
232   since it will play nicer with system's memory, by re-using already allocated memory.
233   Use one separate ZSTD_CStream per thread for parallel execution.
234
235   Start a new compression by initializing ZSTD_CStream.
236   Use ZSTD_initCStream() to start a new compression operation.
237   Use ZSTD_initCStream_usingDict() or ZSTD_initCStream_usingCDict() for a compression which requires a dictionary (experimental section)
238
239   Use ZSTD_compressStream() repetitively to consume input stream.
240   The function will automatically update both `pos` fields.
241   Note that it may not consume the entire input, in which case `pos < size`,
242   and it's up to the caller to present again remaining data.
243   @return : a size hint, preferred nb of bytes to use as input for next function call
244             or an error code, which can be tested using ZSTD_isError().
245             Note 1 : it's just a hint, to help latency a little, any other value will work fine.
246             Note 2 : size hint is guaranteed to be <= ZSTD_CStreamInSize()
247
248   At any moment, it's possible to flush whatever data remains within internal buffer, using ZSTD_flushStream().
249   `output->pos` will be updated.
250   Note that some content might still be left within internal buffer if `output->size` is too small.
251   @return : nb of bytes still present within internal buffer (0 if it's empty)
252             or an error code, which can be tested using ZSTD_isError().
253
254   ZSTD_endStream() instructs to finish a frame.
255   It will perform a flush and write frame epilogue.
256   The epilogue is required for decoders to consider a frame completed.
257   ZSTD_endStream() may not be able to flush full data if `output->size` is too small.
258   In which case, call again ZSTD_endStream() to complete the flush.
259   @return : 0 if frame fully completed and fully flushed,
260              or >0 if some data is still present within internal buffer
261                   (value is minimum size estimation for remaining data to flush, but it could be more)
262             or an error code, which can be tested using ZSTD_isError().
263
264  
265 <BR></pre>
266
267 <pre><b>typedef ZSTD_CCtx ZSTD_CStream;  </b>/**< CCtx and CStream are now effectively same object (>= v1.3.0) */<b>
268 </b></pre><BR>
269 <h3>ZSTD_CStream management functions</h3><pre></pre><b><pre>ZSTD_CStream* ZSTD_createCStream(void);
270 size_t ZSTD_freeCStream(ZSTD_CStream* zcs);
271 </pre></b><BR>
272 <h3>Streaming compression functions</h3><pre></pre><b><pre>size_t ZSTD_initCStream(ZSTD_CStream* zcs, int compressionLevel);
273 size_t ZSTD_compressStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output, ZSTD_inBuffer* input);
274 size_t ZSTD_flushStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output);
275 size_t ZSTD_endStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output);
276 </pre></b><BR>
277 <pre><b>size_t ZSTD_CStreamInSize(void);    </b>/**< recommended size for input buffer */<b>
278 </b></pre><BR>
279 <pre><b>size_t ZSTD_CStreamOutSize(void);   </b>/**< recommended size for output buffer. Guarantee to successfully flush at least one complete compressed block in all circumstances. */<b>
280 </b></pre><BR>
281 <a name="Chapter9"></a><h2>Streaming decompression - HowTo</h2><pre>
282   A ZSTD_DStream object is required to track streaming operations.
283   Use ZSTD_createDStream() and ZSTD_freeDStream() to create/release resources.
284   ZSTD_DStream objects can be re-used multiple times.
285
286   Use ZSTD_initDStream() to start a new decompression operation,
287    or ZSTD_initDStream_usingDict() if decompression requires a dictionary.
288    @return : recommended first input size
289
290   Use ZSTD_decompressStream() repetitively to consume your input.
291   The function will update both `pos` fields.
292   If `input.pos < input.size`, some input has not been consumed.
293   It's up to the caller to present again remaining data.
294   If `output.pos < output.size`, decoder has flushed everything it could.
295   @return : 0 when a frame is completely decoded and fully flushed,
296             an error code, which can be tested using ZSTD_isError(),
297             any other value > 0, which means there is still some decoding to do to complete current frame.
298             The return value is a suggested next input size (a hint to improve latency) that will never load more than the current frame.
299  
300 <BR></pre>
301
302 <pre><b>typedef ZSTD_DCtx ZSTD_DStream;  </b>/**< DCtx and DStream are now effectively same object (>= v1.3.0) */<b>
303 </b></pre><BR>
304 <h3>ZSTD_DStream management functions</h3><pre></pre><b><pre>ZSTD_DStream* ZSTD_createDStream(void);
305 size_t ZSTD_freeDStream(ZSTD_DStream* zds);
306 </pre></b><BR>
307 <h3>Streaming decompression functions</h3><pre></pre><b><pre>size_t ZSTD_initDStream(ZSTD_DStream* zds);
308 size_t ZSTD_decompressStream(ZSTD_DStream* zds, ZSTD_outBuffer* output, ZSTD_inBuffer* input);
309 </pre></b><BR>
310 <pre><b>size_t ZSTD_DStreamInSize(void);    </b>/*!< recommended size for input buffer */<b>
311 </b></pre><BR>
312 <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>
313 </b></pre><BR>
314 <a name="Chapter10"></a><h2>START OF ADVANCED AND EXPERIMENTAL FUNCTIONS</h2><pre> The definitions in this section are considered experimental.
315  They should never be used with a dynamic library, as prototypes may change in the future.
316  They are provided for advanced scenarios.
317  Use them only in association with static linking.
318  
319 <BR></pre>
320
321 <a name="Chapter11"></a><h2>Advanced types</h2><pre></pre>
322
323 <pre><b>typedef enum { ZSTD_fast=1, ZSTD_dfast, ZSTD_greedy, ZSTD_lazy, ZSTD_lazy2,
324                ZSTD_btlazy2, ZSTD_btopt, ZSTD_btultra } ZSTD_strategy;   </b>/* from faster to stronger */<b>
325 </b></pre><BR>
326 <pre><b>typedef struct {
327     unsigned windowLog;      </b>/**< largest match distance : larger == more compression, more memory needed during decompression */<b>
328     unsigned chainLog;       </b>/**< fully searched segment : larger == more compression, slower, more memory (useless for fast) */<b>
329     unsigned hashLog;        </b>/**< dispatch table : larger == faster, more memory */<b>
330     unsigned searchLog;      </b>/**< nb of searches : larger == more compression, slower */<b>
331     unsigned searchLength;   </b>/**< match length searched : larger == faster decompression, sometimes less compression */<b>
332     unsigned targetLength;   </b>/**< acceptable match size for optimal parser (only) : larger == more compression, slower */<b>
333     ZSTD_strategy strategy;
334 } ZSTD_compressionParameters;
335 </b></pre><BR>
336 <pre><b>typedef struct {
337     unsigned contentSizeFlag; </b>/**< 1: content size will be in frame header (when known) */<b>
338     unsigned checksumFlag;    </b>/**< 1: generate a 32-bits checksum at end of frame, for error detection */<b>
339     unsigned noDictIDFlag;    </b>/**< 1: no dictID will be saved into frame header (if dictionary compression) */<b>
340 } ZSTD_frameParameters;
341 </b></pre><BR>
342 <pre><b>typedef struct {
343     ZSTD_compressionParameters cParams;
344     ZSTD_frameParameters fParams;
345 } ZSTD_parameters;
346 </b></pre><BR>
347 <pre><b>typedef enum {
348     ZSTD_dct_auto=0,      </b>/* dictionary is "full" when starting with ZSTD_MAGIC_DICTIONARY, otherwise it is "rawContent" */<b>
349     ZSTD_dct_rawContent,  </b>/* ensures dictionary is always loaded as rawContent, even if it starts with ZSTD_MAGIC_DICTIONARY */<b>
350     ZSTD_dct_fullDict     </b>/* refuses to load a dictionary if it does not respect Zstandard's specification */<b>
351 } ZSTD_dictContentType_e;
352 </b></pre><BR>
353 <pre><b>typedef enum {
354     ZSTD_dlm_byCopy = 0, </b>/**< Copy dictionary content internally */<b>
355     ZSTD_dlm_byRef,      </b>/**< Reference dictionary content -- the dictionary buffer must outlive its users. */<b>
356 } ZSTD_dictLoadMethod_e;
357 </b></pre><BR>
358 <a name="Chapter12"></a><h2>Frame size functions</h2><pre></pre>
359
360 <pre><b>size_t ZSTD_findFrameCompressedSize(const void* src, size_t srcSize);
361 </b><p>  `src` should point to the start of a ZSTD encoded frame or skippable frame
362   `srcSize` must be >= first frame size
363   @return : the compressed size of the first frame starting at `src`,
364             suitable to pass to `ZSTD_decompress` or similar,
365             or an error code if input is invalid 
366 </p></pre><BR>
367
368 <pre><b>unsigned long long ZSTD_findDecompressedSize(const void* src, size_t srcSize);
369 </b><p>  `src` should point the start of a series of ZSTD encoded and/or skippable frames
370   `srcSize` must be the _exact_ size of this series
371        (i.e. there should be a frame boundary exactly at `srcSize` bytes after `src`)
372   @return : - decompressed size of all data in all successive frames
373             - if the decompressed size cannot be determined: ZSTD_CONTENTSIZE_UNKNOWN
374             - if an error occurred: ZSTD_CONTENTSIZE_ERROR
375
376    note 1 : decompressed size is an optional field, that may not be present, especially in streaming mode.
377             When `return==ZSTD_CONTENTSIZE_UNKNOWN`, data to decompress could be any size.
378             In which case, it's necessary to use streaming mode to decompress data.
379    note 2 : decompressed size is always present when compression is done with ZSTD_compress()
380    note 3 : decompressed size can be very large (64-bits value),
381             potentially larger than what local system can handle as a single memory segment.
382             In which case, it's necessary to use streaming mode to decompress data.
383    note 4 : If source is untrusted, decompressed size could be wrong or intentionally modified.
384             Always ensure result fits within application's authorized limits.
385             Each application can set its own limits.
386    note 5 : ZSTD_findDecompressedSize handles multiple frames, and so it must traverse the input to
387             read each contained frame header.  This is fast as most of the data is skipped,
388             however it does mean that all frame data must be present and valid. 
389 </p></pre><BR>
390
391 <pre><b>size_t ZSTD_frameHeaderSize(const void* src, size_t srcSize);
392 </b><p>   `src` should point to the start of a ZSTD frame
393    `srcSize` must be >= ZSTD_frameHeaderSize_prefix.
394    @return : size of the Frame Header 
395 </p></pre><BR>
396
397 <a name="Chapter13"></a><h2>Memory management</h2><pre></pre>
398
399 <pre><b>size_t ZSTD_sizeof_CCtx(const ZSTD_CCtx* cctx);
400 size_t ZSTD_sizeof_DCtx(const ZSTD_DCtx* dctx);
401 size_t ZSTD_sizeof_CStream(const ZSTD_CStream* zcs);
402 size_t ZSTD_sizeof_DStream(const ZSTD_DStream* zds);
403 size_t ZSTD_sizeof_CDict(const ZSTD_CDict* cdict);
404 size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict);
405 </b><p>  These functions give the current memory usage of selected object.
406   Object memory usage can evolve when re-used. 
407 </p></pre><BR>
408
409 <pre><b>size_t ZSTD_estimateCCtxSize(int compressionLevel);
410 size_t ZSTD_estimateCCtxSize_usingCParams(ZSTD_compressionParameters cParams);
411 size_t ZSTD_estimateCCtxSize_usingCCtxParams(const ZSTD_CCtx_params* params);
412 size_t ZSTD_estimateDCtxSize(void);
413 </b><p>  These functions make it possible to estimate memory usage
414   of a future {D,C}Ctx, before its creation.
415   ZSTD_estimateCCtxSize() will provide a budget large enough for any compression level up to selected one.
416   It will also consider src size to be arbitrarily "large", which is worst case.
417   If srcSize is known to always be small, ZSTD_estimateCCtxSize_usingCParams() can provide a tighter estimation.
418   ZSTD_estimateCCtxSize_usingCParams() can be used in tandem with ZSTD_getCParams() to create cParams from compressionLevel.
419   ZSTD_estimateCCtxSize_usingCCtxParams() can be used in tandem with ZSTD_CCtxParam_setParameter(). Only single-threaded compression is supported. This function will return an error code if ZSTD_p_nbWorkers is >= 1.
420   Note : CCtx size estimation is only correct for single-threaded compression. 
421 </p></pre><BR>
422
423 <pre><b>size_t ZSTD_estimateCStreamSize(int compressionLevel);
424 size_t ZSTD_estimateCStreamSize_usingCParams(ZSTD_compressionParameters cParams);
425 size_t ZSTD_estimateCStreamSize_usingCCtxParams(const ZSTD_CCtx_params* params);
426 size_t ZSTD_estimateDStreamSize(size_t windowSize);
427 size_t ZSTD_estimateDStreamSize_fromFrame(const void* src, size_t srcSize);
428 </b><p>  ZSTD_estimateCStreamSize() will provide a budget large enough for any compression level up to selected one.
429   It will also consider src size to be arbitrarily "large", which is worst case.
430   If srcSize is known to always be small, ZSTD_estimateCStreamSize_usingCParams() can provide a tighter estimation.
431   ZSTD_estimateCStreamSize_usingCParams() can be used in tandem with ZSTD_getCParams() to create cParams from compressionLevel.
432   ZSTD_estimateCStreamSize_usingCCtxParams() can be used in tandem with ZSTD_CCtxParam_setParameter(). Only single-threaded compression is supported. This function will return an error code if ZSTD_p_nbWorkers is >= 1.
433   Note : CStream size estimation is only correct for single-threaded compression.
434   ZSTD_DStream memory budget depends on window Size.
435   This information can be passed manually, using ZSTD_estimateDStreamSize,
436   or deducted from a valid frame Header, using ZSTD_estimateDStreamSize_fromFrame();
437   Note : if streaming is init with function ZSTD_init?Stream_usingDict(),
438          an internal ?Dict will be created, which additional size is not estimated here.
439          In this case, get total size by adding ZSTD_estimate?DictSize 
440 </p></pre><BR>
441
442 <pre><b>size_t ZSTD_estimateCDictSize(size_t dictSize, int compressionLevel);
443 size_t ZSTD_estimateCDictSize_advanced(size_t dictSize, ZSTD_compressionParameters cParams, ZSTD_dictLoadMethod_e dictLoadMethod);
444 size_t ZSTD_estimateDDictSize(size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod);
445 </b><p>  ZSTD_estimateCDictSize() will bet that src size is relatively "small", and content is copied, like ZSTD_createCDict().
446   ZSTD_estimateCDictSize_advanced() makes it possible to control compression parameters precisely, like ZSTD_createCDict_advanced().
447   Note : dictionaries created by reference (`ZSTD_dlm_byRef`) are logically smaller.
448  
449 </p></pre><BR>
450
451 <pre><b>ZSTD_CCtx*    ZSTD_initStaticCCtx(void* workspace, size_t workspaceSize);
452 ZSTD_CStream* ZSTD_initStaticCStream(void* workspace, size_t workspaceSize);    </b>/**< same as ZSTD_initStaticCCtx() */<b>
453 </b><p>  Initialize an object using a pre-allocated fixed-size buffer.
454   workspace: The memory area to emplace the object into.
455              Provided pointer *must be 8-bytes aligned*.
456              Buffer must outlive object.
457   workspaceSize: Use ZSTD_estimate*Size() to determine
458                  how large workspace must be to support target scenario.
459  @return : pointer to object (same address as workspace, just different type),
460            or NULL if error (size too small, incorrect alignment, etc.)
461   Note : zstd will never resize nor malloc() when using a static buffer.
462          If the object requires more memory than available,
463          zstd will just error out (typically ZSTD_error_memory_allocation).
464   Note 2 : there is no corresponding "free" function.
465            Since workspace is allocated externally, it must be freed externally too.
466   Note 3 : cParams : use ZSTD_getCParams() to convert a compression level
467            into its associated cParams.
468   Limitation 1 : currently not compatible with internal dictionary creation, triggered by
469                  ZSTD_CCtx_loadDictionary(), ZSTD_initCStream_usingDict() or ZSTD_initDStream_usingDict().
470   Limitation 2 : static cctx currently not compatible with multi-threading.
471   Limitation 3 : static dctx is incompatible with legacy support.
472  
473 </p></pre><BR>
474
475 <pre><b>ZSTD_DStream* ZSTD_initStaticDStream(void* workspace, size_t workspaceSize);    </b>/**< same as ZSTD_initStaticDCtx() */<b>
476 </b></pre><BR>
477 <pre><b>typedef void* (*ZSTD_allocFunction) (void* opaque, size_t size);
478 typedef void  (*ZSTD_freeFunction) (void* opaque, void* address);
479 typedef struct { ZSTD_allocFunction customAlloc; ZSTD_freeFunction customFree; void* opaque; } ZSTD_customMem;
480 static ZSTD_customMem const ZSTD_defaultCMem = { NULL, NULL, NULL };  </b>/**< this constant defers to stdlib's functions */<b>
481 </b><p>  These prototypes make it possible to pass your own allocation/free functions.
482   ZSTD_customMem is provided at creation time, using ZSTD_create*_advanced() variants listed below.
483   All allocation/free operations will be completed using these custom variants instead of regular <stdlib.h> ones.
484  
485 </p></pre><BR>
486
487 <a name="Chapter14"></a><h2>Advanced compression functions</h2><pre></pre>
488
489 <pre><b>ZSTD_CDict* ZSTD_createCDict_byReference(const void* dictBuffer, size_t dictSize, int compressionLevel);
490 </b><p>  Create a digested dictionary for compression
491   Dictionary content is simply referenced, and therefore stays in dictBuffer.
492   It is important that dictBuffer outlives CDict, it must remain read accessible throughout the lifetime of CDict 
493 </p></pre><BR>
494
495 <pre><b>ZSTD_compressionParameters ZSTD_getCParams(int compressionLevel, unsigned long long estimatedSrcSize, size_t dictSize);
496 </b><p>   @return ZSTD_compressionParameters structure for a selected compression level and estimated srcSize.
497    `estimatedSrcSize` value is optional, select 0 if not known 
498 </p></pre><BR>
499
500 <pre><b>ZSTD_parameters ZSTD_getParams(int compressionLevel, unsigned long long estimatedSrcSize, size_t dictSize);
501 </b><p>   same as ZSTD_getCParams(), but @return a full `ZSTD_parameters` object instead of sub-component `ZSTD_compressionParameters`.
502    All fields of `ZSTD_frameParameters` are set to default : contentSize=1, checksum=0, noDictID=0 
503 </p></pre><BR>
504
505 <pre><b>size_t ZSTD_checkCParams(ZSTD_compressionParameters params);
506 </b><p>   Ensure param values remain within authorized range 
507 </p></pre><BR>
508
509 <pre><b>ZSTD_compressionParameters ZSTD_adjustCParams(ZSTD_compressionParameters cPar, unsigned long long srcSize, size_t dictSize);
510 </b><p>  optimize params for a given `srcSize` and `dictSize`.
511   both values are optional, select `0` if unknown. 
512 </p></pre><BR>
513
514 <pre><b>size_t ZSTD_compress_advanced (ZSTD_CCtx* cctx,
515                       void* dst, size_t dstCapacity,
516                 const void* src, size_t srcSize,
517                 const void* dict,size_t dictSize,
518                       ZSTD_parameters params);
519 </b><p>   Same as ZSTD_compress_usingDict(), with fine-tune control over each compression parameter 
520 </p></pre><BR>
521
522 <pre><b>size_t ZSTD_compress_usingCDict_advanced(ZSTD_CCtx* cctx,
523                       void* dst, size_t dstCapacity,
524                 const void* src, size_t srcSize,
525                 const ZSTD_CDict* cdict, ZSTD_frameParameters fParams);
526 </b><p>   Same as ZSTD_compress_usingCDict(), with fine-tune control over frame parameters 
527 </p></pre><BR>
528
529 <a name="Chapter15"></a><h2>Advanced decompression functions</h2><pre></pre>
530
531 <pre><b>unsigned ZSTD_isFrame(const void* buffer, size_t size);
532 </b><p>  Tells if the content of `buffer` starts with a valid Frame Identifier.
533   Note : Frame Identifier is 4 bytes. If `size < 4`, @return will always be 0.
534   Note 2 : Legacy Frame Identifiers are considered valid only if Legacy Support is enabled.
535   Note 3 : Skippable Frame Identifiers are considered valid. 
536 </p></pre><BR>
537
538 <pre><b>ZSTD_DDict* ZSTD_createDDict_byReference(const void* dictBuffer, size_t dictSize);
539 </b><p>  Create a digested dictionary, ready to start decompression operation without startup delay.
540   Dictionary content is referenced, and therefore stays in dictBuffer.
541   It is important that dictBuffer outlives DDict,
542   it must remain read accessible throughout the lifetime of DDict 
543 </p></pre><BR>
544
545 <pre><b>unsigned ZSTD_getDictID_fromDict(const void* dict, size_t dictSize);
546 </b><p>  Provides the dictID stored within dictionary.
547   if @return == 0, the dictionary is not conformant with Zstandard specification.
548   It can still be loaded, but as a content-only dictionary. 
549 </p></pre><BR>
550
551 <pre><b>unsigned ZSTD_getDictID_fromDDict(const ZSTD_DDict* ddict);
552 </b><p>  Provides the dictID of the dictionary loaded into `ddict`.
553   If @return == 0, the dictionary is not conformant to Zstandard specification, or empty.
554   Non-conformant dictionaries can still be loaded, but as content-only dictionaries. 
555 </p></pre><BR>
556
557 <pre><b>unsigned ZSTD_getDictID_fromFrame(const void* src, size_t srcSize);
558 </b><p>  Provides the dictID required to decompressed the frame stored within `src`.
559   If @return == 0, the dictID could not be decoded.
560   This could for one of the following reasons :
561   - The frame does not require a dictionary to be decoded (most common case).
562   - The frame was built with dictID intentionally removed. Whatever dictionary is necessary is a hidden information.
563     Note : this use case also happens when using a non-conformant dictionary.
564   - `srcSize` is too small, and as a result, the frame header could not be decoded (only possible if `srcSize < ZSTD_FRAMEHEADERSIZE_MAX`).
565   - This is not a Zstandard frame.
566   When identifying the exact failure cause, it's possible to use ZSTD_getFrameHeader(), which will provide a more precise error code. 
567 </p></pre><BR>
568
569 <a name="Chapter16"></a><h2>Advanced streaming functions</h2><pre></pre>
570
571 <h3>Advanced Streaming compression functions</h3><pre></pre><b><pre>size_t ZSTD_initCStream_srcSize(ZSTD_CStream* zcs, int compressionLevel, unsigned long long pledgedSrcSize);   </b>/**< pledgedSrcSize must be correct. If it is not known at init time, use ZSTD_CONTENTSIZE_UNKNOWN. Note that, for compatibility with older programs, "0" also disables frame content size field. It may be enabled in the future. */<b>
572 size_t ZSTD_initCStream_usingDict(ZSTD_CStream* zcs, const void* dict, size_t dictSize, int compressionLevel); </b>/**< creates of an internal CDict (incompatible with static CCtx), except if dict == NULL or dictSize < 8, in which case no dict is used. Note: dict is loaded with ZSTD_dm_auto (treated as a full zstd dictionary if it begins with ZSTD_MAGIC_DICTIONARY, else as raw content) and ZSTD_dlm_byCopy.*/<b>
573 size_t ZSTD_initCStream_advanced(ZSTD_CStream* zcs, const void* dict, size_t dictSize,
574                                              ZSTD_parameters params, unsigned long long pledgedSrcSize);  </b>/**< pledgedSrcSize must be correct. If srcSize is not known at init time, use value ZSTD_CONTENTSIZE_UNKNOWN. dict is loaded with ZSTD_dm_auto and ZSTD_dlm_byCopy. */<b>
575 size_t ZSTD_initCStream_usingCDict(ZSTD_CStream* zcs, const ZSTD_CDict* cdict);  </b>/**< note : cdict will just be referenced, and must outlive compression session */<b>
576 size_t ZSTD_initCStream_usingCDict_advanced(ZSTD_CStream* zcs, const ZSTD_CDict* cdict, ZSTD_frameParameters fParams, unsigned long long pledgedSrcSize);  </b>/**< same as ZSTD_initCStream_usingCDict(), with control over frame parameters. pledgedSrcSize must be correct. If srcSize is not known at init time, use value ZSTD_CONTENTSIZE_UNKNOWN. */<b>
577 </pre></b><BR>
578 <pre><b>size_t ZSTD_resetCStream(ZSTD_CStream* zcs, unsigned long long pledgedSrcSize);
579 </b><p>  start a new compression job, using same parameters from previous job.
580   This is typically useful to skip dictionary loading stage, since it will re-use it in-place..
581   Note that zcs must be init at least once before using ZSTD_resetCStream().
582   If pledgedSrcSize is not known at reset time, use macro ZSTD_CONTENTSIZE_UNKNOWN.
583   If pledgedSrcSize > 0, its value must be correct, as it will be written in header, and controlled at the end.
584   For the time being, pledgedSrcSize==0 is interpreted as "srcSize unknown" for compatibility with older programs,
585   but it will change to mean "empty" in future version, so use macro ZSTD_CONTENTSIZE_UNKNOWN instead.
586  @return : 0, or an error code (which can be tested using ZSTD_isError()) 
587 </p></pre><BR>
588
589 <pre><b>typedef struct {
590     unsigned long long ingested;
591     unsigned long long consumed;
592     unsigned long long produced;
593 } ZSTD_frameProgression;
594 </b></pre><BR>
595 <h3>Advanced Streaming decompression functions</h3><pre></pre><b><pre>typedef enum { DStream_p_maxWindowSize } ZSTD_DStreamParameter_e;
596 size_t ZSTD_setDStreamParameter(ZSTD_DStream* zds, ZSTD_DStreamParameter_e paramType, unsigned paramValue);   </b>/* obsolete : this API will be removed in a future version */<b>
597 size_t ZSTD_initDStream_usingDict(ZSTD_DStream* zds, const void* dict, size_t dictSize); </b>/**< note: no dictionary will be used if dict == NULL or dictSize < 8 */<b>
598 size_t ZSTD_initDStream_usingDDict(ZSTD_DStream* zds, const ZSTD_DDict* ddict);  </b>/**< note : ddict is referenced, it must outlive decompression session */<b>
599 size_t ZSTD_resetDStream(ZSTD_DStream* zds);  </b>/**< re-use decompression parameters from previous init; saves dictionary loading */<b>
600 </pre></b><BR>
601 <a name="Chapter17"></a><h2>Buffer-less and synchronous inner streaming functions</h2><pre>
602   This is an advanced API, giving full control over buffer management, for users which need direct control over memory.
603   But it's also a complex one, with several restrictions, documented below.
604   Prefer normal streaming API for an easier experience.
605  
606 <BR></pre>
607
608 <a name="Chapter18"></a><h2>Buffer-less streaming compression (synchronous mode)</h2><pre>
609   A ZSTD_CCtx object is required to track streaming operations.
610   Use ZSTD_createCCtx() / ZSTD_freeCCtx() to manage resource.
611   ZSTD_CCtx object can be re-used multiple times within successive compression operations.
612
613   Start by initializing a context.
614   Use ZSTD_compressBegin(), or ZSTD_compressBegin_usingDict() for dictionary compression,
615   or ZSTD_compressBegin_advanced(), for finer parameter control.
616   It's also possible to duplicate a reference context which has already been initialized, using ZSTD_copyCCtx()
617
618   Then, consume your input using ZSTD_compressContinue().
619   There are some important considerations to keep in mind when using this advanced function :
620   - ZSTD_compressContinue() has no internal buffer. It uses externally provided buffers only.
621   - Interface is synchronous : input is consumed entirely and produces 1+ compressed blocks.
622   - Caller must ensure there is enough space in `dst` to store compressed data under worst case scenario.
623     Worst case evaluation is provided by ZSTD_compressBound().
624     ZSTD_compressContinue() doesn't guarantee recover after a failed compression.
625   - ZSTD_compressContinue() presumes prior input ***is still accessible and unmodified*** (up to maximum distance size, see WindowLog).
626     It remembers all previous contiguous blocks, plus one separated memory segment (which can itself consists of multiple contiguous blocks)
627   - ZSTD_compressContinue() detects that prior input has been overwritten when `src` buffer overlaps.
628     In which case, it will "discard" the relevant memory section from its history.
629
630   Finish a frame with ZSTD_compressEnd(), which will write the last block(s) and optional checksum.
631   It's possible to use srcSize==0, in which case, it will write a final empty block to end the frame.
632   Without last block mark, frames are considered unfinished (hence corrupted) by compliant decoders.
633
634   `ZSTD_CCtx` object can be re-used (ZSTD_compressBegin()) to compress again.
635 <BR></pre>
636
637 <h3>Buffer-less streaming compression functions</h3><pre></pre><b><pre>size_t ZSTD_compressBegin(ZSTD_CCtx* cctx, int compressionLevel);
638 size_t ZSTD_compressBegin_usingDict(ZSTD_CCtx* cctx, const void* dict, size_t dictSize, int compressionLevel);
639 size_t ZSTD_compressBegin_advanced(ZSTD_CCtx* cctx, const void* dict, size_t dictSize, ZSTD_parameters params, unsigned long long pledgedSrcSize); </b>/**< pledgedSrcSize : If srcSize is not known at init time, use ZSTD_CONTENTSIZE_UNKNOWN */<b>
640 size_t ZSTD_compressBegin_usingCDict(ZSTD_CCtx* cctx, const ZSTD_CDict* cdict); </b>/**< note: fails if cdict==NULL */<b>
641 size_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>
642 size_t ZSTD_copyCCtx(ZSTD_CCtx* cctx, const ZSTD_CCtx* preparedCCtx, unsigned long long pledgedSrcSize); </b>/**<  note: if pledgedSrcSize is not known, use ZSTD_CONTENTSIZE_UNKNOWN */<b>
643 </pre></b><BR>
644 <a name="Chapter19"></a><h2>Buffer-less streaming decompression (synchronous mode)</h2><pre>
645   A ZSTD_DCtx object is required to track streaming operations.
646   Use ZSTD_createDCtx() / ZSTD_freeDCtx() to manage it.
647   A ZSTD_DCtx object can be re-used multiple times.
648
649   First typical operation is to retrieve frame parameters, using ZSTD_getFrameHeader().
650   Frame header is extracted from the beginning of compressed frame, so providing only the frame's beginning is enough.
651   Data fragment must be large enough to ensure successful decoding.
652  `ZSTD_frameHeaderSize_max` bytes is guaranteed to always be large enough.
653   @result : 0 : successful decoding, the `ZSTD_frameHeader` structure is correctly filled.
654            >0 : `srcSize` is too small, please provide at least @result bytes on next attempt.
655            errorCode, which can be tested using ZSTD_isError().
656
657   It fills a ZSTD_frameHeader structure with important information to correctly decode the frame,
658   such as the dictionary ID, content size, or maximum back-reference distance (`windowSize`).
659   Note that these values could be wrong, either because of data corruption, or because a 3rd party deliberately spoofs false information.
660   As a consequence, check that values remain within valid application range.
661   For example, do not allocate memory blindly, check that `windowSize` is within expectation.
662   Each application can set its own limits, depending on local restrictions.
663   For extended interoperability, it is recommended to support `windowSize` of at least 8 MB.
664
665   ZSTD_decompressContinue() needs previous data blocks during decompression, up to `windowSize` bytes.
666   ZSTD_decompressContinue() is very sensitive to contiguity,
667   if 2 blocks don't follow each other, make sure that either the compressor breaks contiguity at the same place,
668   or that previous contiguous segment is large enough to properly handle maximum back-reference distance.
669   There are multiple ways to guarantee this condition.
670
671   The most memory efficient way is to use a round buffer of sufficient size.
672   Sufficient size is determined by invoking ZSTD_decodingBufferSize_min(),
673   which can @return an error code if required value is too large for current system (in 32-bits mode).
674   In a round buffer methodology, ZSTD_decompressContinue() decompresses each block next to previous one,
675   up to the moment there is not enough room left in the buffer to guarantee decoding another full block,
676   which maximum size is provided in `ZSTD_frameHeader` structure, field `blockSizeMax`.
677   At which point, decoding can resume from the beginning of the buffer.
678   Note that already decoded data stored in the buffer should be flushed before being overwritten.
679
680   There are alternatives possible, for example using two or more buffers of size `windowSize` each, though they consume more memory.
681
682   Finally, if you control the compression process, you can also ignore all buffer size rules,
683   as long as the encoder and decoder progress in "lock-step",
684   aka use exactly the same buffer sizes, break contiguity at the same place, etc.
685
686   Once buffers are setup, start decompression, with ZSTD_decompressBegin().
687   If decompression requires a dictionary, use ZSTD_decompressBegin_usingDict() or ZSTD_decompressBegin_usingDDict().
688
689   Then use ZSTD_nextSrcSizeToDecompress() and ZSTD_decompressContinue() alternatively.
690   ZSTD_nextSrcSizeToDecompress() tells how many bytes to provide as 'srcSize' to ZSTD_decompressContinue().
691   ZSTD_decompressContinue() requires this _exact_ amount of bytes, or it will fail.
692
693  @result of ZSTD_decompressContinue() is the number of bytes regenerated within 'dst' (necessarily <= dstCapacity).
694   It can be zero : it just means ZSTD_decompressContinue() has decoded some metadata item.
695   It can also be an error code, which can be tested with ZSTD_isError().
696
697   A frame is fully decoded when ZSTD_nextSrcSizeToDecompress() returns zero.
698   Context can then be reset to start a new decompression.
699
700   Note : it's possible to know if next input to present is a header or a block, using ZSTD_nextInputType().
701   This information is not required to properly decode a frame.
702
703   == Special case : skippable frames 
704
705   Skippable frames allow integration of user-defined data into a flow of concatenated frames.
706   Skippable frames will be ignored (skipped) by decompressor.
707   The format of skippable frames is as follows :
708   a) Skippable frame ID - 4 Bytes, Little endian format, any value from 0x184D2A50 to 0x184D2A5F
709   b) Frame Size - 4 Bytes, Little endian format, unsigned 32-bits
710   c) Frame Content - any content (User Data) of length equal to Frame Size
711   For skippable frames ZSTD_getFrameHeader() returns zfhPtr->frameType==ZSTD_skippableFrame.
712   For skippable frames ZSTD_decompressContinue() always returns 0 : it only skips the content.
713 <BR></pre>
714
715 <h3>Buffer-less streaming decompression functions</h3><pre></pre><b><pre>typedef enum { ZSTD_frame, ZSTD_skippableFrame } ZSTD_frameType_e;
716 typedef struct {
717     unsigned long long frameContentSize; </b>/* if == ZSTD_CONTENTSIZE_UNKNOWN, it means this field is not available. 0 means "empty" */<b>
718     unsigned long long windowSize;       </b>/* can be very large, up to <= frameContentSize */<b>
719     unsigned blockSizeMax;
720     ZSTD_frameType_e frameType;          </b>/* if == ZSTD_skippableFrame, frameContentSize is the size of skippable content */<b>
721     unsigned headerSize;
722     unsigned dictID;
723     unsigned checksumFlag;
724 } ZSTD_frameHeader;
725 size_t ZSTD_getFrameHeader(ZSTD_frameHeader* zfhPtr, const void* src, size_t srcSize);   </b>/**< doesn't consume input */<b>
726 size_t ZSTD_decodingBufferSize_min(unsigned long long windowSize, unsigned long long frameContentSize);  </b>/**< when frame content size is not known, pass in frameContentSize == ZSTD_CONTENTSIZE_UNKNOWN */<b>
727 </pre></b><BR>
728 <pre><b>typedef enum { ZSTDnit_frameHeader, ZSTDnit_blockHeader, ZSTDnit_block, ZSTDnit_lastBlock, ZSTDnit_checksum, ZSTDnit_skippableFrame } ZSTD_nextInputType_e;
729 </b></pre><BR>
730 <a name="Chapter20"></a><h2>New advanced API (experimental)</h2><pre></pre>
731
732 <pre><b>typedef enum {
733     </b>/* Opened question : should we have a format ZSTD_f_auto ?<b>
734      * Today, it would mean exactly the same as ZSTD_f_zstd1.
735      * But, in the future, should several formats become supported,
736      * on the compression side, it would mean "default format".
737      * On the decompression side, it would mean "automatic format detection",
738      * so that ZSTD_f_zstd1 would mean "accept *only* zstd frames".
739      * Since meaning is a little different, another option could be to define different enums for compression and decompression.
740      * This question could be kept for later, when there are actually multiple formats to support,
741      * but there is also the question of pinning enum values, and pinning value `0` is especially important */
742     ZSTD_f_zstd1 = 0,        </b>/* zstd frame format, specified in zstd_compression_format.md (default) */<b>
743     ZSTD_f_zstd1_magicless,  </b>/* Variant of zstd frame format, without initial 4-bytes magic number.<b>
744                               * Useful to save 4 bytes per generated frame.
745                               * Decoder cannot recognise automatically this format, requiring instructions. */
746 } ZSTD_format_e;
747 </b></pre><BR>
748 <pre><b>typedef enum {
749     </b>/* compression format */<b>
750     ZSTD_p_format = 10,      </b>/* See ZSTD_format_e enum definition.<b>
751                               * Cast selected format as unsigned for ZSTD_CCtx_setParameter() compatibility. */
752
753     </b>/* compression parameters */<b>
754     ZSTD_p_compressionLevel=100, </b>/* Update all compression parameters according to pre-defined cLevel table<b>
755                               * Default level is ZSTD_CLEVEL_DEFAULT==3.
756                               * Special: value 0 means "do not change cLevel".
757                               * Note 1 : it's possible to pass a negative compression level by casting it to unsigned type.
758                               * Note 2 : setting a level sets all default values of other compression parameters.
759                               * Note 3 : setting compressionLevel automatically updates ZSTD_p_compressLiterals. */
760     ZSTD_p_windowLog,        </b>/* Maximum allowed back-reference distance, expressed as power of 2.<b>
761                               * Must be clamped between ZSTD_WINDOWLOG_MIN and ZSTD_WINDOWLOG_MAX.
762                               * Special: value 0 means "use default windowLog".
763                               * Note: Using a window size greater than ZSTD_MAXWINDOWSIZE_DEFAULT (default: 2^27)
764                               *       requires explicitly allowing such window size during decompression stage. */
765     ZSTD_p_hashLog,          </b>/* Size of the probe table, as a power of 2.<b>
766                               * Resulting table size is (1 << (hashLog+2)).
767                               * Must be clamped between ZSTD_HASHLOG_MIN and ZSTD_HASHLOG_MAX.
768                               * Larger tables improve compression ratio of strategies <= dFast,
769                               * and improve speed of strategies > dFast.
770                               * Special: value 0 means "use default hashLog". */
771     ZSTD_p_chainLog,         </b>/* Size of the full-search table, as a power of 2.<b>
772                               * Resulting table size is (1 << (chainLog+2)).
773                               * Larger tables result in better and slower compression.
774                               * This parameter is useless when using "fast" strategy.
775                               * Special: value 0 means "use default chainLog". */
776     ZSTD_p_searchLog,        </b>/* Number of search attempts, as a power of 2.<b>
777                               * More attempts result in better and slower compression.
778                               * This parameter is useless when using "fast" and "dFast" strategies.
779                               * Special: value 0 means "use default searchLog". */
780     ZSTD_p_minMatch,         </b>/* Minimum size of searched matches (note : repCode matches can be smaller).<b>
781                               * Larger values make faster compression and decompression, but decrease ratio.
782                               * Must be clamped between ZSTD_SEARCHLENGTH_MIN and ZSTD_SEARCHLENGTH_MAX.
783                               * Note that currently, for all strategies < btopt, effective minimum is 4.
784                               *                    , for all strategies > fast, effective maximum is 6.
785                               * Special: value 0 means "use default minMatchLength". */
786     ZSTD_p_targetLength,     </b>/* Impact of this field depends on strategy.<b>
787                               * For strategies btopt & btultra:
788                               *     Length of Match considered "good enough" to stop search.
789                               *     Larger values make compression stronger, and slower.
790                               * For strategy fast:
791                               *     Distance between match sampling.
792                               *     Larger values make compression faster, and weaker.
793                               * Special: value 0 means "use default targetLength". */
794     ZSTD_p_compressionStrategy, </b>/* See ZSTD_strategy enum definition.<b>
795                               * Cast selected strategy as unsigned for ZSTD_CCtx_setParameter() compatibility.
796                               * The higher the value of selected strategy, the more complex it is,
797                               * resulting in stronger and slower compression.
798                               * Special: value 0 means "use default strategy". */
799
800     ZSTD_p_enableLongDistanceMatching=160, </b>/* Enable long distance matching.<b>
801                                          * This parameter is designed to improve compression ratio
802                                          * for large inputs, by finding large matches at long distance.
803                                          * It increases memory usage and window size.
804                                          * Note: enabling this parameter increases ZSTD_p_windowLog to 128 MB
805                                          * except when expressly set to a different value. */
806     ZSTD_p_ldmHashLog,       </b>/* Size of the table for long distance matching, as a power of 2.<b>
807                               * Larger values increase memory usage and compression ratio,
808                               * but decrease compression speed.
809                               * Must be clamped between ZSTD_HASHLOG_MIN and ZSTD_HASHLOG_MAX
810                               * default: windowlog - 7.
811                               * Special: value 0 means "automatically determine hashlog". */
812     ZSTD_p_ldmMinMatch,      </b>/* Minimum match size for long distance matcher.<b>
813                               * Larger/too small values usually decrease compression ratio.
814                               * Must be clamped between ZSTD_LDM_MINMATCH_MIN and ZSTD_LDM_MINMATCH_MAX.
815                               * Special: value 0 means "use default value" (default: 64). */
816     ZSTD_p_ldmBucketSizeLog, </b>/* Log size of each bucket in the LDM hash table for collision resolution.<b>
817                               * Larger values improve collision resolution but decrease compression speed.
818                               * The maximum value is ZSTD_LDM_BUCKETSIZELOG_MAX .
819                               * Special: value 0 means "use default value" (default: 3). */
820     ZSTD_p_ldmHashEveryLog,  </b>/* Frequency of inserting/looking up entries in the LDM hash table.<b>
821                               * Must be clamped between 0 and (ZSTD_WINDOWLOG_MAX - ZSTD_HASHLOG_MIN).
822                               * Default is MAX(0, (windowLog - ldmHashLog)), optimizing hash table usage.
823                               * Larger values improve compression speed.
824                               * Deviating far from default value will likely result in a compression ratio decrease.
825                               * Special: value 0 means "automatically determine hashEveryLog". */
826
827     </b>/* frame parameters */<b>
828     ZSTD_p_contentSizeFlag=200, </b>/* Content size will be written into frame header _whenever known_ (default:1)<b>
829                               * Content size must be known at the beginning of compression,
830                               * it is provided using ZSTD_CCtx_setPledgedSrcSize() */
831     ZSTD_p_checksumFlag,     </b>/* A 32-bits checksum of content is written at end of frame (default:0) */<b>
832     ZSTD_p_dictIDFlag,       </b>/* When applicable, dictionary's ID is written into frame header (default:1) */<b>
833
834     </b>/* multi-threading parameters */<b>
835     </b>/* These parameters are only useful if multi-threading is enabled (ZSTD_MULTITHREAD).<b>
836      * They return an error otherwise. */
837     ZSTD_p_nbWorkers=400,    </b>/* Select how many threads will be spawned to compress in parallel.<b>
838                               * When nbWorkers >= 1, triggers asynchronous mode :
839                               * ZSTD_compress_generic() consumes some input, flush some output if possible, and immediately gives back control to caller,
840                               * while compression work is performed in parallel, within worker threads.
841                               * (note : a strong exception to this rule is when first invocation sets ZSTD_e_end : it becomes a blocking call).
842                               * More workers improve speed, but also increase memory usage.
843                               * Default value is `0`, aka "single-threaded mode" : no worker is spawned, compression is performed inside Caller's thread, all invocations are blocking */
844     ZSTD_p_jobSize,          </b>/* Size of a compression job. This value is enforced only in non-blocking mode.<b>
845                               * Each compression job is completed in parallel, so this value indirectly controls the nb of active threads.
846                               * 0 means default, which is dynamically determined based on compression parameters.
847                               * Job size must be a minimum of overlapSize, or 1 MB, whichever is largest.
848                               * The minimum size is automatically and transparently enforced */
849     ZSTD_p_overlapSizeLog,   </b>/* Size of previous input reloaded at the beginning of each job.<b>
850                               * 0 => no overlap, 6(default) => use 1/8th of windowSize, >=9 => use full windowSize */
851
852     </b>/* =================================================================== */<b>
853     </b>/* experimental parameters - no stability guaranteed                   */<b>
854     </b>/* =================================================================== */<b>
855
856     ZSTD_p_compressLiterals=1000, </b>/* control huffman compression of literals (enabled) by default.<b>
857                               * disabling it improves speed and decreases compression ratio by a large amount.
858                               * note : this setting is automatically updated when changing compression level.
859                               *        positive compression levels set ZSTD_p_compressLiterals to 1.
860                               *        negative compression levels set ZSTD_p_compressLiterals to 0. */
861
862     ZSTD_p_forceMaxWindow=1100, </b>/* Force back-reference distances to remain < windowSize,<b>
863                               * even when referencing into Dictionary content (default:0) */
864
865 } ZSTD_cParameter;
866 </b></pre><BR>
867 <pre><b>size_t ZSTD_CCtx_setParameter(ZSTD_CCtx* cctx, ZSTD_cParameter param, unsigned value);
868 </b><p>  Set one compression parameter, selected by enum ZSTD_cParameter.
869   Setting a parameter is generally only possible during frame initialization (before starting compression),
870   except for a few exceptions which can be updated during compression: compressionLevel, hashLog, chainLog, searchLog, minMatch, targetLength and strategy.
871   Note : when `value` is an enum, cast it to unsigned for proper type checking.
872   @result : informational value (typically, value being set clamped correctly),
873             or an error code (which can be tested with ZSTD_isError()). 
874 </p></pre><BR>
875
876 <pre><b>size_t ZSTD_CCtx_setPledgedSrcSize(ZSTD_CCtx* cctx, unsigned long long pledgedSrcSize);
877 </b><p>  Total input data size to be compressed as a single frame.
878   This value will be controlled at the end, and result in error if not respected.
879  @result : 0, or an error code (which can be tested with ZSTD_isError()).
880   Note 1 : 0 means zero, empty.
881            In order to mean "unknown content size", pass constant ZSTD_CONTENTSIZE_UNKNOWN.
882            ZSTD_CONTENTSIZE_UNKNOWN is default value for any new compression job.
883   Note 2 : If all data is provided and consumed in a single round,
884            this value is overriden by srcSize instead. 
885 </p></pre><BR>
886
887 <pre><b>size_t ZSTD_CCtx_loadDictionary(ZSTD_CCtx* cctx, const void* dict, size_t dictSize);
888 size_t ZSTD_CCtx_loadDictionary_byReference(ZSTD_CCtx* cctx, const void* dict, size_t dictSize);
889 size_t ZSTD_CCtx_loadDictionary_advanced(ZSTD_CCtx* cctx, const void* dict, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictContentType_e dictContentType);
890 </b><p>  Create an internal CDict from `dict` buffer.
891   Decompression will have to use same dictionary.
892  @result : 0, or an error code (which can be tested with ZSTD_isError()).
893   Special: Adding a NULL (or 0-size) dictionary invalidates previous dictionary,
894            meaning "return to no-dictionary mode".
895   Note 1 : Dictionary will be used for all future compression jobs.
896            To return to "no-dictionary" situation, load a NULL dictionary
897   Note 2 : Loading a dictionary involves building tables, which are dependent on compression parameters.
898            For this reason, compression parameters cannot be changed anymore after loading a dictionary.
899            It's also a CPU consuming operation, with non-negligible impact on latency.
900   Note 3 :`dict` content will be copied internally.
901            Use ZSTD_CCtx_loadDictionary_byReference() to reference dictionary content instead.
902            In such a case, dictionary buffer must outlive its users.
903   Note 4 : Use ZSTD_CCtx_loadDictionary_advanced()
904            to precisely select how dictionary content must be interpreted. 
905 </p></pre><BR>
906
907 <pre><b>size_t ZSTD_CCtx_refCDict(ZSTD_CCtx* cctx, const ZSTD_CDict* cdict);
908 </b><p>  Reference a prepared dictionary, to be used for all next compression jobs.
909   Note that compression parameters are enforced from within CDict,
910   and supercede any compression parameter previously set within CCtx.
911   The dictionary will remain valid for future compression jobs using same CCtx.
912  @result : 0, or an error code (which can be tested with ZSTD_isError()).
913   Special : adding a NULL CDict means "return to no-dictionary mode".
914   Note 1 : Currently, only one dictionary can be managed.
915            Adding a new dictionary effectively "discards" any previous one.
916   Note 2 : CDict is just referenced, its lifetime must outlive CCtx. 
917 </p></pre><BR>
918
919 <pre><b>size_t ZSTD_CCtx_refPrefix(ZSTD_CCtx* cctx, const void* prefix, size_t prefixSize);
920 size_t ZSTD_CCtx_refPrefix_advanced(ZSTD_CCtx* cctx, const void* prefix, size_t prefixSize, ZSTD_dictContentType_e dictContentType);
921 </b><p>  Reference a prefix (single-usage dictionary) for next compression job.
922   Decompression need same prefix to properly regenerate data.
923   Prefix is **only used once**. Tables are discarded at end of compression job.
924   Subsequent compression jobs will be done without prefix (if none is explicitly referenced).
925   If there is a need to use same prefix multiple times, consider embedding it into a ZSTD_CDict instead.
926  @result : 0, or an error code (which can be tested with ZSTD_isError()).
927   Special: Adding any prefix (including NULL) invalidates any previous prefix or dictionary
928   Note 1 : Prefix buffer is referenced. It must outlive compression job.
929   Note 2 : Referencing a prefix involves building tables, which are dependent on compression parameters.
930            It's a CPU consuming operation, with non-negligible impact on latency.
931   Note 3 : By default, the prefix is treated as raw content (ZSTD_dm_rawContent).
932            Use ZSTD_CCtx_refPrefix_advanced() to alter dictMode. 
933 </p></pre><BR>
934
935 <pre><b>void ZSTD_CCtx_reset(ZSTD_CCtx* cctx);
936 </b><p>  Return a CCtx to clean state.
937   Useful after an error, or to interrupt an ongoing compression job and start a new one.
938   Any internal data not yet flushed is cancelled.
939   Dictionary (if any) is dropped.
940   All parameters are back to default values.
941   It's possible to modify compression parameters after a reset.
942  
943 </p></pre><BR>
944
945 <pre><b>typedef enum {
946     ZSTD_e_continue=0, </b>/* collect more data, encoder decides when to output compressed result, for optimal conditions */<b>
947     ZSTD_e_flush,      </b>/* flush any data provided so far - frame will continue, future data can still reference previous data for better compression */<b>
948     ZSTD_e_end         </b>/* flush any remaining data and close current frame. Any additional data starts a new frame. */<b>
949 } ZSTD_EndDirective;
950 </b></pre><BR>
951 <pre><b>size_t ZSTD_compress_generic (ZSTD_CCtx* cctx,
952                               ZSTD_outBuffer* output,
953                               ZSTD_inBuffer* input,
954                               ZSTD_EndDirective endOp);
955 </b><p>  Behave about the same as ZSTD_compressStream. To note :
956   - Compression parameters are pushed into CCtx before starting compression, using ZSTD_CCtx_setParameter()
957   - Compression parameters cannot be changed once compression is started.
958   - outpot->pos must be <= dstCapacity, input->pos must be <= srcSize
959   - outpot->pos and input->pos will be updated. They are guaranteed to remain below their respective limit.
960   - In single-thread mode (default), function is blocking : it completed its job before returning to caller.
961   - In multi-thread mode, function is non-blocking : it just acquires a copy of input, and distribute job to internal worker threads,
962                                                      and then immediately returns, just indicating that there is some data remaining to be flushed.
963                                                      The function nonetheless guarantees forward progress : it will return only after it reads or write at least 1+ byte.
964   - Exception : in multi-threading mode, if the first call requests a ZSTD_e_end directive, it is blocking : it will complete compression before giving back control to caller.
965   - @return provides a minimum amount of data remaining to be flushed from internal buffers
966             or an error code, which can be tested using ZSTD_isError().
967             if @return != 0, flush is not fully completed, there is still some data left within internal buffers.
968             This is useful for ZSTD_e_flush, since in this case more flushes are necessary to empty all buffers.
969             For ZSTD_e_end, @return == 0 when internal buffers are fully flushed and frame is completed.
970   - after a ZSTD_e_end directive, if internal buffer is not fully flushed (@return != 0),
971             only ZSTD_e_end or ZSTD_e_flush operations are allowed.
972             Before starting a new compression job, or changing compression parameters,
973             it is required to fully flush internal buffers.
974  
975 </p></pre><BR>
976
977 <pre><b>size_t ZSTD_compress_generic_simpleArgs (
978                 ZSTD_CCtx* cctx,
979                 void* dst, size_t dstCapacity, size_t* dstPos,
980           const void* src, size_t srcSize, size_t* srcPos,
981                 ZSTD_EndDirective endOp);
982 </b><p>  Same as ZSTD_compress_generic(),
983   but using only integral types as arguments.
984   Argument list is larger than ZSTD_{in,out}Buffer,
985   but can be helpful for binders from dynamic languages
986   which have troubles handling structures containing memory pointers.
987  
988 </p></pre><BR>
989
990 <pre><b>ZSTD_CCtx_params* ZSTD_createCCtxParams(void);
991 size_t ZSTD_freeCCtxParams(ZSTD_CCtx_params* params);
992 </b><p>  Quick howto :
993   - ZSTD_createCCtxParams() : Create a ZSTD_CCtx_params structure
994   - ZSTD_CCtxParam_setParameter() : Push parameters one by one into
995                                     an existing ZSTD_CCtx_params structure.
996                                     This is similar to
997                                     ZSTD_CCtx_setParameter().
998   - ZSTD_CCtx_setParametersUsingCCtxParams() : Apply parameters to
999                                     an existing CCtx.
1000                                     These parameters will be applied to
1001                                     all subsequent compression jobs.
1002   - ZSTD_compress_generic() : Do compression using the CCtx.
1003   - ZSTD_freeCCtxParams() : Free the memory.
1004
1005   This can be used with ZSTD_estimateCCtxSize_advanced_usingCCtxParams()
1006   for static allocation for single-threaded compression.
1007  
1008 </p></pre><BR>
1009
1010 <pre><b>size_t ZSTD_CCtxParams_reset(ZSTD_CCtx_params* params);
1011 </b><p>  Reset params to default values.
1012  
1013 </p></pre><BR>
1014
1015 <pre><b>size_t ZSTD_CCtxParams_init(ZSTD_CCtx_params* cctxParams, int compressionLevel);
1016 </b><p>  Initializes the compression parameters of cctxParams according to
1017   compression level. All other parameters are reset to their default values.
1018  
1019 </p></pre><BR>
1020
1021 <pre><b>size_t ZSTD_CCtxParams_init_advanced(ZSTD_CCtx_params* cctxParams, ZSTD_parameters params);
1022 </b><p>  Initializes the compression and frame parameters of cctxParams according to
1023   params. All other parameters are reset to their default values.
1024  
1025 </p></pre><BR>
1026
1027 <pre><b>size_t ZSTD_CCtxParam_setParameter(ZSTD_CCtx_params* params, ZSTD_cParameter param, unsigned value);
1028 </b><p>  Similar to ZSTD_CCtx_setParameter.
1029   Set one compression parameter, selected by enum ZSTD_cParameter.
1030   Parameters must be applied to a ZSTD_CCtx using ZSTD_CCtx_setParametersUsingCCtxParams().
1031   Note : when `value` is an enum, cast it to unsigned for proper type checking.
1032  @result : 0, or an error code (which can be tested with ZSTD_isError()).
1033  
1034 </p></pre><BR>
1035
1036 <pre><b>size_t ZSTD_CCtx_setParametersUsingCCtxParams(
1037         ZSTD_CCtx* cctx, const ZSTD_CCtx_params* params);
1038 </b><p>  Apply a set of ZSTD_CCtx_params to the compression context.
1039   This can be done even after compression is started,
1040     if nbWorkers==0, this will have no impact until a new compression is started.
1041     if nbWorkers>=1, new parameters will be picked up at next job,
1042        with a few restrictions (windowLog, pledgedSrcSize, nbWorkers, jobSize, and overlapLog are not updated).
1043  
1044 </p></pre><BR>
1045
1046 <h3>Advanced parameters for decompression API</h3><pre></pre><b><pre></pre></b><BR>
1047 <pre><b>size_t ZSTD_DCtx_loadDictionary(ZSTD_DCtx* dctx, const void* dict, size_t dictSize);
1048 size_t ZSTD_DCtx_loadDictionary_byReference(ZSTD_DCtx* dctx, const void* dict, size_t dictSize);
1049 size_t ZSTD_DCtx_loadDictionary_advanced(ZSTD_DCtx* dctx, const void* dict, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictContentType_e dictContentType);
1050 </b><p>  Create an internal DDict from dict buffer,
1051   to be used to decompress next frames.
1052  @result : 0, or an error code (which can be tested with ZSTD_isError()).
1053   Special : Adding a NULL (or 0-size) dictionary invalidates any previous dictionary,
1054             meaning "return to no-dictionary mode".
1055   Note 1 : `dict` content will be copied internally.
1056             Use ZSTD_DCtx_loadDictionary_byReference()
1057             to reference dictionary content instead.
1058             In which case, the dictionary buffer must outlive its users.
1059   Note 2 : Loading a dictionary involves building tables,
1060            which has a non-negligible impact on CPU usage and latency.
1061   Note 3 : Use ZSTD_DCtx_loadDictionary_advanced() to select
1062            how dictionary content will be interpreted and loaded.
1063  
1064 </p></pre><BR>
1065
1066 <pre><b>size_t ZSTD_DCtx_refDDict(ZSTD_DCtx* dctx, const ZSTD_DDict* ddict);
1067 </b><p>  Reference a prepared dictionary, to be used to decompress next frames.
1068   The dictionary remains active for decompression of future frames using same DCtx.
1069  @result : 0, or an error code (which can be tested with ZSTD_isError()).
1070   Note 1 : Currently, only one dictionary can be managed.
1071            Referencing a new dictionary effectively "discards" any previous one.
1072   Special : adding a NULL DDict means "return to no-dictionary mode".
1073   Note 2 : DDict is just referenced, its lifetime must outlive its usage from DCtx.
1074  
1075 </p></pre><BR>
1076
1077 <pre><b>size_t ZSTD_DCtx_refPrefix(ZSTD_DCtx* dctx, const void* prefix, size_t prefixSize);
1078 size_t ZSTD_DCtx_refPrefix_advanced(ZSTD_DCtx* dctx, const void* prefix, size_t prefixSize, ZSTD_dictContentType_e dictContentType);
1079 </b><p>  Reference a prefix (single-usage dictionary) for next compression job.
1080   Prefix is **only used once**. It must be explicitly referenced before each frame.
1081   If there is a need to use same prefix multiple times, consider embedding it into a ZSTD_DDict instead.
1082  @result : 0, or an error code (which can be tested with ZSTD_isError()).
1083   Note 1 : Adding any prefix (including NULL) invalidates any previously set prefix or dictionary
1084   Note 2 : Prefix buffer is referenced. It must outlive compression job.
1085   Note 3 : By default, the prefix is treated as raw content (ZSTD_dm_rawContent).
1086            Use ZSTD_CCtx_refPrefix_advanced() to alter dictMode.
1087   Note 4 : Referencing a raw content prefix has almost no cpu nor memory cost.
1088  
1089 </p></pre><BR>
1090
1091 <pre><b>size_t ZSTD_DCtx_setMaxWindowSize(ZSTD_DCtx* dctx, size_t maxWindowSize);
1092 </b><p>  Refuses allocating internal buffers for frames requiring a window size larger than provided limit.
1093   This is useful to prevent a decoder context from reserving too much memory for itself (potential attack scenario).
1094   This parameter is only useful in streaming mode, since no internal buffer is allocated in direct mode.
1095   By default, a decompression context accepts all window sizes <= (1 << ZSTD_WINDOWLOG_MAX)
1096  @return : 0, or an error code (which can be tested using ZSTD_isError()).
1097  
1098 </p></pre><BR>
1099
1100 <pre><b>size_t ZSTD_DCtx_setFormat(ZSTD_DCtx* dctx, ZSTD_format_e format);
1101 </b><p>  Instruct the decoder context about what kind of data to decode next.
1102   This instruction is mandatory to decode data without a fully-formed header,
1103   such ZSTD_f_zstd1_magicless for example.
1104  @return : 0, or an error code (which can be tested using ZSTD_isError()).
1105  
1106 </p></pre><BR>
1107
1108 <pre><b>size_t ZSTD_decompress_generic(ZSTD_DCtx* dctx,
1109                                ZSTD_outBuffer* output,
1110                                ZSTD_inBuffer* input);
1111 </b><p>  Behave the same as ZSTD_decompressStream.
1112   Decompression parameters cannot be changed once decompression is started.
1113  @return : an error code, which can be tested using ZSTD_isError()
1114            if >0, a hint, nb of expected input bytes for next invocation.
1115            `0` means : a frame has just been fully decoded and flushed.
1116  
1117 </p></pre><BR>
1118
1119 <pre><b>size_t ZSTD_decompress_generic_simpleArgs (
1120                 ZSTD_DCtx* dctx,
1121                 void* dst, size_t dstCapacity, size_t* dstPos,
1122           const void* src, size_t srcSize, size_t* srcPos);
1123 </b><p>  Same as ZSTD_decompress_generic(),
1124   but using only integral types as arguments.
1125   Argument list is larger than ZSTD_{in,out}Buffer,
1126   but can be helpful for binders from dynamic languages
1127   which have troubles handling structures containing memory pointers.
1128  
1129 </p></pre><BR>
1130
1131 <pre><b>void ZSTD_DCtx_reset(ZSTD_DCtx* dctx);
1132 </b><p>  Return a DCtx to clean state.
1133   If a decompression was ongoing, any internal data not yet flushed is cancelled.
1134   All parameters are back to default values, including sticky ones.
1135   Dictionary (if any) is dropped.
1136   Parameters can be modified again after a reset.
1137  
1138 </p></pre><BR>
1139
1140 <a name="Chapter21"></a><h2>Block level API</h2><pre></pre>
1141
1142 <pre><b></b><p>    Frame metadata cost is typically ~18 bytes, which can be non-negligible for very small blocks (< 100 bytes).
1143     User will have to take in charge required information to regenerate data, such as compressed and content sizes.
1144
1145     A few rules to respect :
1146     - Compressing and decompressing require a context structure
1147       + Use ZSTD_createCCtx() and ZSTD_createDCtx()
1148     - It is necessary to init context before starting
1149       + compression : any ZSTD_compressBegin*() variant, including with dictionary
1150       + decompression : any ZSTD_decompressBegin*() variant, including with dictionary
1151       + copyCCtx() and copyDCtx() can be used too
1152     - Block size is limited, it must be <= ZSTD_getBlockSize() <= ZSTD_BLOCKSIZE_MAX == 128 KB
1153       + If input is larger than a block size, it's necessary to split input data into multiple blocks
1154       + For inputs larger than a single block size, consider using the regular ZSTD_compress() instead.
1155         Frame metadata is not that costly, and quickly becomes negligible as source size grows larger.
1156     - When a block is considered not compressible enough, ZSTD_compressBlock() result will be zero.
1157       In which case, nothing is produced into `dst`.
1158       + User must test for such outcome and deal directly with uncompressed data
1159       + ZSTD_decompressBlock() doesn't accept uncompressed data as input !!!
1160       + In case of multiple successive blocks, should some of them be uncompressed,
1161         decoder must be informed of their existence in order to follow proper history.
1162         Use ZSTD_insertBlock() for such a case.
1163 </p></pre><BR>
1164
1165 <h3>Raw zstd block functions</h3><pre></pre><b><pre>size_t ZSTD_getBlockSize   (const ZSTD_CCtx* cctx);
1166 size_t ZSTD_compressBlock  (ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize);
1167 size_t ZSTD_decompressBlock(ZSTD_DCtx* dctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize);
1168 size_t ZSTD_insertBlock    (ZSTD_DCtx* dctx, const void* blockStart, size_t blockSize);  </b>/**< insert uncompressed block into `dctx` history. Useful for multi-blocks decompression. */<b>
1169 </pre></b><BR>
1170 </html>
1171 </body>