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