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