blob: 2470a4555b0fff27800aed6b1bf2e55791f1d4e8 [file] [log] [blame]
Przemyslaw Skibinski86d94242016-10-24 16:07:53 +02001<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
4<title>zstd 1.1.1 Manual</title>
5</head>
6<body>
7<h1>zstd 1.1.1 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">Fast 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">Advanced compression functions</a></li>
23<li><a href="#Chapter13">Advanced decompression functions</a></li>
24<li><a href="#Chapter14">Advanced streaming functions</a></li>
25<li><a href="#Chapter15">Buffer-less and synchronous inner streaming functions</a></li>
26<li><a href="#Chapter16">Buffer-less streaming compression (synchronous mode)</a></li>
27<li><a href="#Chapter17">Buffer-less streaming decompression (synchronous mode)</a></li>
28<li><a href="#Chapter18">Block functions</a></li>
29</ol>
30<hr>
31<a name="Chapter1"></a><h2>Introduction</h2><pre>
Przemyslaw Skibinski1fd5b452016-10-31 10:44:44 +010032 zstd, short for Zstandard, is a fast lossless compression algorithm, targeting real-time compression scenarios
Przemyslaw Skibinski86d94242016-10-24 16:07:53 +020033 at zlib-level and better compression ratios. The zstd compression library provides in-memory compression and
34 decompression functions. The library supports compression levels from 1 up to ZSTD_maxCLevel() which is 22.
Przemyslaw Skibinski1fd5b452016-10-31 10:44:44 +010035 Levels >= 20, labelled `--ultra`, should be used with caution, as they require more memory.
Przemyslaw Skibinski86d94242016-10-24 16:07:53 +020036 Compression can be done in:
37 - a single step (described as Simple API)
38 - a single step, reusing a context (described as Explicit memory management)
Przemyslaw Skibinski1fd5b452016-10-31 10:44:44 +010039 - unbounded multiple steps (described as Streaming compression)
Przemyslaw Skibinski86d94242016-10-24 16:07:53 +020040 The compression ratio achievable on small data can be highly improved using compression with a dictionary in:
41 - a single step (described as Simple dictionary API)
42 - a single step, reusing a dictionary (described as Fast dictionary API)
43
Przemyslaw Skibinski1fd5b452016-10-31 10:44:44 +010044 Advanced experimental functions can be accessed using #define ZSTD_STATIC_LINKING_ONLY before including zstd.h.
45 These APIs shall never be used with a dynamic library.
Przemyslaw Skibinski86d94242016-10-24 16:07:53 +020046 They are not "stable", their definition may change in the future. Only static linking is allowed.
47<BR></pre>
48
49<a name="Chapter2"></a><h2>Version</h2><pre></pre>
50
51<pre><b>unsigned ZSTD_versionNumber (void); </b>/**< returns version number of ZSTD */<b>
52</b></pre><BR>
53<a name="Chapter3"></a><h2>Simple API</h2><pre></pre>
54
55<pre><b>size_t ZSTD_compress( void* dst, size_t dstCapacity,
56 const void* src, size_t srcSize,
57 int compressionLevel);
58</b><p> Compresses `src` content as a single zstd compressed frame into already allocated `dst`.
59 Hint : compression runs faster if `dstCapacity` >= `ZSTD_compressBound(srcSize)`.
60 @return : compressed size written into `dst` (<= `dstCapacity),
61 or an error code if it fails (which can be tested using ZSTD_isError())
62</p></pre><BR>
63
64<pre><b>size_t ZSTD_decompress( void* dst, size_t dstCapacity,
65 const void* src, size_t compressedSize);
66</b><p> `compressedSize` : must be the _exact_ size of a single compressed frame.
67 `dstCapacity` is an upper bound of originalSize.
68 If user cannot imply a maximum upper bound, it's better to use streaming mode to decompress data.
69 @return : the number of bytes decompressed into `dst` (<= `dstCapacity`),
70 or an errorCode if it fails (which can be tested using ZSTD_isError())
71</p></pre><BR>
72
73<pre><b>unsigned long long ZSTD_getDecompressedSize(const void* src, size_t srcSize);
74</b><p> 'src' is the start of a zstd compressed frame.
75 @return : content size to be decompressed, as a 64-bits value _if known_, 0 otherwise.
76 note 1 : decompressed size is an optional field, that may not be present, especially in streaming mode.
77 When `return==0`, data to decompress could be any size.
78 In which case, it's necessary to use streaming mode to decompress data.
79 Optionally, application can still use ZSTD_decompress() while relying on implied limits.
80 (For example, data may be necessarily cut into blocks <= 16 KB).
81 note 2 : decompressed size is always present when compression is done with ZSTD_compress()
82 note 3 : decompressed size can be very large (64-bits value),
83 potentially larger than what local system can handle as a single memory segment.
84 In which case, it's necessary to use streaming mode to decompress data.
85 note 4 : If source is untrusted, decompressed size could be wrong or intentionally modified.
86 Always ensure result fits within application's authorized limits.
87 Each application can set its own limits.
88 note 5 : when `return==0`, if precise failure cause is needed, use ZSTD_getFrameParams() to know more.
89</p></pre><BR>
90
91<h3>Helper functions</h3><pre><b>int ZSTD_maxCLevel(void); </b>/*!< maximum compression level available */<b>
92size_t ZSTD_compressBound(size_t srcSize); </b>/*!< maximum compressed size in worst case scenario */<b>
93unsigned ZSTD_isError(size_t code); </b>/*!< tells if a `size_t` function result is an error code */<b>
94const char* ZSTD_getErrorName(size_t code); </b>/*!< provides readable string from an error code */<b>
95</b></pre><BR>
96<a name="Chapter4"></a><h2>Explicit memory management</h2><pre></pre>
97
Przemyslaw Skibinski86d94242016-10-24 16:07:53 +020098<pre><b>size_t ZSTD_compressCCtx(ZSTD_CCtx* ctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize, int compressionLevel);
99</b><p> Same as ZSTD_compress(), requires an allocated ZSTD_CCtx (see ZSTD_createCCtx())
100</p></pre><BR>
101
102<h3>Decompression context</h3><pre><b>typedef struct ZSTD_DCtx_s ZSTD_DCtx;
103ZSTD_DCtx* ZSTD_createDCtx(void);
104size_t ZSTD_freeDCtx(ZSTD_DCtx* dctx);
105</b></pre><BR>
106<pre><b>size_t ZSTD_decompressDCtx(ZSTD_DCtx* ctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize);
107</b><p> Same as ZSTD_decompress(), requires an allocated ZSTD_DCtx (see ZSTD_createDCtx())
108</p></pre><BR>
109
110<a name="Chapter5"></a><h2>Simple dictionary API</h2><pre></pre>
111
112<pre><b>size_t ZSTD_compress_usingDict(ZSTD_CCtx* ctx,
113 void* dst, size_t dstCapacity,
114 const void* src, size_t srcSize,
115 const void* dict,size_t dictSize,
116 int compressionLevel);
117</b><p> Compression using a predefined Dictionary (see dictBuilder/zdict.h).
118 Note : This function load the dictionary, resulting in significant startup delay.
119</p></pre><BR>
120
121<pre><b>size_t ZSTD_decompress_usingDict(ZSTD_DCtx* dctx,
122 void* dst, size_t dstCapacity,
123 const void* src, size_t srcSize,
124 const void* dict,size_t dictSize);
125</b><p> Decompression using a predefined Dictionary (see dictBuilder/zdict.h).
126 Dictionary must be identical to the one used during compression.
127 Note : This function load the dictionary, resulting in significant startup delay
128</p></pre><BR>
129
130<a name="Chapter6"></a><h2>Fast dictionary API</h2><pre></pre>
131
132<pre><b>ZSTD_CDict* ZSTD_createCDict(const void* dict, size_t dictSize, int compressionLevel);
Przemyslaw Skibinski1fd5b452016-10-31 10:44:44 +0100133</b><p> When compressing multiple messages / blocks with the same dictionary, it's recommended to load it just once.
134 ZSTD_createCDict() will create a digested dictionary, ready to start future compression operations without startup delay.
135 ZSTD_CDict can be created once and used by multiple threads concurrently, as its usage is read-only.
Przemyslaw Skibinski86d94242016-10-24 16:07:53 +0200136 `dict` can be released after ZSTD_CDict creation
137</p></pre><BR>
138
139<pre><b>size_t ZSTD_freeCDict(ZSTD_CDict* CDict);
Przemyslaw Skibinski1fd5b452016-10-31 10:44:44 +0100140</b><p> Function frees memory allocated by ZSTD_createCDict()
Przemyslaw Skibinski86d94242016-10-24 16:07:53 +0200141</p></pre><BR>
142
143<pre><b>size_t ZSTD_compress_usingCDict(ZSTD_CCtx* cctx,
144 void* dst, size_t dstCapacity,
145 const void* src, size_t srcSize,
146 const ZSTD_CDict* cdict);
147</b><p> Compression using a digested Dictionary.
148 Faster startup than ZSTD_compress_usingDict(), recommended when same dictionary is used multiple times.
149 Note that compression level is decided during dictionary creation
150</p></pre><BR>
151
152<pre><b>ZSTD_DDict* ZSTD_createDDict(const void* dict, size_t dictSize);
153</b><p> Create a digested dictionary, ready to start decompression operation without startup delay.
154 `dict` can be released after creation
155</p></pre><BR>
156
157<pre><b>size_t ZSTD_freeDDict(ZSTD_DDict* ddict);
158</b><p> Function frees memory allocated with ZSTD_createDDict()
159</p></pre><BR>
160
161<pre><b>size_t ZSTD_decompress_usingDDict(ZSTD_DCtx* dctx,
162 void* dst, size_t dstCapacity,
163 const void* src, size_t srcSize,
164 const ZSTD_DDict* ddict);
165</b><p> Decompression using a digested Dictionary
166 Faster startup than ZSTD_decompress_usingDict(), recommended when same dictionary is used multiple times.
167</p></pre><BR>
168
169<a name="Chapter7"></a><h2>Streaming</h2><pre></pre>
170
171<pre><b>typedef struct ZSTD_inBuffer_s {
172 const void* src; </b>/**< start of input buffer */<b>
173 size_t size; </b>/**< size of input buffer */<b>
174 size_t pos; </b>/**< position where reading stopped. Will be updated. Necessarily 0 <= pos <= size */<b>
175} ZSTD_inBuffer;
176</b></pre><BR>
177<pre><b>typedef struct ZSTD_outBuffer_s {
178 void* dst; </b>/**< start of output buffer */<b>
179 size_t size; </b>/**< size of output buffer */<b>
180 size_t pos; </b>/**< position where writing stopped. Will be updated. Necessarily 0 <= pos <= size */<b>
181} ZSTD_outBuffer;
182</b></pre><BR>
183<a name="Chapter8"></a><h2>Streaming compression - HowTo</h2><pre>
184 A ZSTD_CStream object is required to track streaming operation.
185 Use ZSTD_createCStream() and ZSTD_freeCStream() to create/release resources.
186 ZSTD_CStream objects can be reused multiple times on consecutive compression operations.
Przemyslaw Skibinski1fd5b452016-10-31 10:44:44 +0100187 It is recommended to re-use ZSTD_CStream in situations where many streaming operations will be achieved consecutively,
188 since it will play nicer with system's memory, by re-using already allocated memory.
189 Use one separate ZSTD_CStream per thread for parallel execution.
Przemyslaw Skibinski86d94242016-10-24 16:07:53 +0200190
Przemyslaw Skibinski1fd5b452016-10-31 10:44:44 +0100191 Start a new compression by initializing ZSTD_CStream.
Przemyslaw Skibinski86d94242016-10-24 16:07:53 +0200192 Use ZSTD_initCStream() to start a new compression operation.
193 Use ZSTD_initCStream_usingDict() for a compression which requires a dictionary.
194
195 Use ZSTD_compressStream() repetitively to consume input stream.
196 The function will automatically update both `pos` fields.
197 Note that it may not consume the entire input, in which case `pos < size`,
198 and it's up to the caller to present again remaining data.
199 @return : a size hint, preferred nb of bytes to use as input for next function call
200 (it's just a hint, to help latency a little, any other value will work fine)
201 (note : the size hint is guaranteed to be <= ZSTD_CStreamInSize() )
202 or an error code, which can be tested using ZSTD_isError().
203
204 At any moment, it's possible to flush whatever data remains within buffer, using ZSTD_flushStream().
205 `output->pos` will be updated.
206 Note some content might still be left within internal buffer if `output->size` is too small.
207 @return : nb of bytes still present within internal buffer (0 if it's empty)
208 or an error code, which can be tested using ZSTD_isError().
209
210 ZSTD_endStream() instructs to finish a frame.
211 It will perform a flush and write frame epilogue.
212 The epilogue is required for decoders to consider a frame completed.
213 Similar to ZSTD_flushStream(), it may not be able to flush the full content if `output->size` is too small.
214 In which case, call again ZSTD_endStream() to complete the flush.
215 @return : nb of bytes still present within internal buffer (0 if it's empty)
216 or an error code, which can be tested using ZSTD_isError().
217
218
219<BR></pre>
220
221<h3>Streaming compression functions</h3><pre><b>typedef struct ZSTD_CStream_s ZSTD_CStream;
222ZSTD_CStream* ZSTD_createCStream(void);
223size_t ZSTD_freeCStream(ZSTD_CStream* zcs);
224size_t ZSTD_initCStream(ZSTD_CStream* zcs, int compressionLevel);
225size_t ZSTD_compressStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output, ZSTD_inBuffer* input);
226size_t ZSTD_flushStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output);
227size_t ZSTD_endStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output);
228</b></pre><BR>
229<pre><b>size_t ZSTD_CStreamInSize(void); </b>/**< recommended size for input buffer */<b>
230</b></pre><BR>
231<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>
232</b></pre><BR>
233<a name="Chapter9"></a><h2>Streaming decompression - HowTo</h2><pre>
234 A ZSTD_DStream object is required to track streaming operations.
235 Use ZSTD_createDStream() and ZSTD_freeDStream() to create/release resources.
236 ZSTD_DStream objects can be re-used multiple times.
237
238 Use ZSTD_initDStream() to start a new decompression operation,
239 or ZSTD_initDStream_usingDict() if decompression requires a dictionary.
240 @return : recommended first input size
241
242 Use ZSTD_decompressStream() repetitively to consume your input.
243 The function will update both `pos` fields.
244 If `input.pos < input.size`, some input has not been consumed.
245 It's up to the caller to present again remaining data.
246 If `output.pos < output.size`, decoder has flushed everything it could.
247 @return : 0 when a frame is completely decoded and fully flushed,
248 an error code, which can be tested using ZSTD_isError(),
249 any other value > 0, which means there is still some work to do to complete the frame.
250 The return value is a suggested next input size (just an hint, to help latency).
251
252<BR></pre>
253
254<h3>Streaming decompression functions</h3><pre><b>typedef struct ZSTD_DStream_s ZSTD_DStream;
255ZSTD_DStream* ZSTD_createDStream(void);
256size_t ZSTD_freeDStream(ZSTD_DStream* zds);
257size_t ZSTD_initDStream(ZSTD_DStream* zds);
258size_t ZSTD_decompressStream(ZSTD_DStream* zds, ZSTD_outBuffer* output, ZSTD_inBuffer* input);
259</b></pre><BR>
260<pre><b>size_t ZSTD_DStreamInSize(void); </b>/*!< recommended size for input buffer */<b>
261</b></pre><BR>
262<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>
263</b></pre><BR>
264<a name="Chapter10"></a><h2>START OF ADVANCED AND EXPERIMENTAL FUNCTIONS</h2><pre> The definitions in this section are considered experimental.
265 They should never be used with a dynamic library, as they may change in the future.
266 They are provided for advanced usages.
267 Use them only in association with static linking.
268
269<BR></pre>
270
271<a name="Chapter11"></a><h2>Advanced types</h2><pre></pre>
272
Przemyslaw Skibinski1fd5b452016-10-31 10:44:44 +0100273<pre><b>typedef enum { ZSTD_fast, ZSTD_dfast, ZSTD_greedy, ZSTD_lazy, ZSTD_lazy2, ZSTD_btlazy2, ZSTD_btopt, ZSTD_btopt2 } ZSTD_strategy; </b>/* from faster to stronger */<b>
Przemyslaw Skibinski86d94242016-10-24 16:07:53 +0200274</b></pre><BR>
275<pre><b>typedef struct {
276 unsigned windowLog; </b>/**< largest match distance : larger == more compression, more memory needed during decompression */<b>
277 unsigned chainLog; </b>/**< fully searched segment : larger == more compression, slower, more memory (useless for fast) */<b>
278 unsigned hashLog; </b>/**< dispatch table : larger == faster, more memory */<b>
279 unsigned searchLog; </b>/**< nb of searches : larger == more compression, slower */<b>
280 unsigned searchLength; </b>/**< match length searched : larger == faster decompression, sometimes less compression */<b>
281 unsigned targetLength; </b>/**< acceptable match size for optimal parser (only) : larger == more compression, slower */<b>
282 ZSTD_strategy strategy;
283} ZSTD_compressionParameters;
284</b></pre><BR>
285<pre><b>typedef struct {
286 unsigned contentSizeFlag; </b>/**< 1: content size will be in frame header (if known). */<b>
287 unsigned checksumFlag; </b>/**< 1: will generate a 22-bits checksum at end of frame, to be used for error detection by decompressor */<b>
288 unsigned noDictIDFlag; </b>/**< 1: no dict ID will be saved into frame header (if dictionary compression) */<b>
289} ZSTD_frameParameters;
290</b></pre><BR>
291<pre><b>typedef struct {
292 ZSTD_compressionParameters cParams;
293 ZSTD_frameParameters fParams;
294} ZSTD_parameters;
295</b></pre><BR>
296<h3>Custom memory allocation functions</h3><pre><b>typedef void* (*ZSTD_allocFunction) (void* opaque, size_t size);
297typedef void (*ZSTD_freeFunction) (void* opaque, void* address);
298typedef struct { ZSTD_allocFunction customAlloc; ZSTD_freeFunction customFree; void* opaque; } ZSTD_customMem;
299</b></pre><BR>
300<a name="Chapter12"></a><h2>Advanced compression functions</h2><pre></pre>
301
302<pre><b>size_t ZSTD_estimateCCtxSize(ZSTD_compressionParameters cParams);
303</b><p> Gives the amount of memory allocated for a ZSTD_CCtx given a set of compression parameters.
304 `frameContentSize` is an optional parameter, provide `0` if unknown
305</p></pre><BR>
306
307<pre><b>ZSTD_CCtx* ZSTD_createCCtx_advanced(ZSTD_customMem customMem);
308</b><p> Create a ZSTD compression context using external alloc and free functions
309</p></pre><BR>
310
311<pre><b>size_t ZSTD_sizeof_CCtx(const ZSTD_CCtx* cctx);
312</b><p> Gives the amount of memory used by a given ZSTD_CCtx
313</p></pre><BR>
314
315<pre><b>ZSTD_CDict* ZSTD_createCDict_advanced(const void* dict, size_t dictSize,
316 ZSTD_parameters params, ZSTD_customMem customMem);
317</b><p> Create a ZSTD_CDict using external alloc and free, and customized compression parameters
318</p></pre><BR>
319
320<pre><b>size_t ZSTD_sizeof_CDict(const ZSTD_CDict* cdict);
321</b><p> Gives the amount of memory used by a given ZSTD_sizeof_CDict
322</p></pre><BR>
323
324<pre><b>ZSTD_parameters ZSTD_getParams(int compressionLevel, unsigned long long srcSize, size_t dictSize);
325</b><p> same as ZSTD_getCParams(), but @return a full `ZSTD_parameters` object instead of a `ZSTD_compressionParameters`.
326 All fields of `ZSTD_frameParameters` are set to default (0)
327</p></pre><BR>
328
329<pre><b>ZSTD_compressionParameters ZSTD_getCParams(int compressionLevel, unsigned long long srcSize, size_t dictSize);
330</b><p> @return ZSTD_compressionParameters structure for a selected compression level and srcSize.
331 `srcSize` value is optional, select 0 if not known
332</p></pre><BR>
333
334<pre><b>size_t ZSTD_checkCParams(ZSTD_compressionParameters params);
335</b><p> Ensure param values remain within authorized range
336</p></pre><BR>
337
338<pre><b>ZSTD_compressionParameters ZSTD_adjustCParams(ZSTD_compressionParameters cPar, unsigned long long srcSize, size_t dictSize);
339</b><p> optimize params for a given `srcSize` and `dictSize`.
340 both values are optional, select `0` if unknown.
341</p></pre><BR>
342
343<pre><b>size_t ZSTD_compress_advanced (ZSTD_CCtx* ctx,
344 void* dst, size_t dstCapacity,
345 const void* src, size_t srcSize,
346 const void* dict,size_t dictSize,
347 ZSTD_parameters params);
348</b><p> Same as ZSTD_compress_usingDict(), with fine-tune control of each compression parameter
349</p></pre><BR>
350
351<a name="Chapter13"></a><h2>Advanced decompression functions</h2><pre></pre>
352
353<pre><b>size_t ZSTD_estimateDCtxSize(void);
354</b><p> Gives the potential amount of memory allocated to create a ZSTD_DCtx
355</p></pre><BR>
356
357<pre><b>ZSTD_DCtx* ZSTD_createDCtx_advanced(ZSTD_customMem customMem);
358</b><p> Create a ZSTD decompression context using external alloc and free functions
359</p></pre><BR>
360
361<pre><b>size_t ZSTD_sizeof_DCtx(const ZSTD_DCtx* dctx);
362</b><p> Gives the amount of memory used by a given ZSTD_DCtx
363</p></pre><BR>
364
365<pre><b>size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict);
366</b><p> Gives the amount of memory used by a given ZSTD_DDict
367</p></pre><BR>
368
369<a name="Chapter14"></a><h2>Advanced streaming functions</h2><pre></pre>
370
371<h3>Advanced Streaming compression functions</h3><pre><b>ZSTD_CStream* ZSTD_createCStream_advanced(ZSTD_customMem customMem);
372size_t ZSTD_initCStream_usingDict(ZSTD_CStream* zcs, const void* dict, size_t dictSize, int compressionLevel);
373size_t ZSTD_initCStream_advanced(ZSTD_CStream* zcs, const void* dict, size_t dictSize,
374 ZSTD_parameters params, unsigned long long pledgedSrcSize); </b>/**< pledgedSrcSize is optional and can be zero == unknown */<b>
Przemyslaw Skibinski1fd5b452016-10-31 10:44:44 +0100375size_t ZSTD_initCStream_usingCDict(ZSTD_CStream* zcs, const ZSTD_CDict* cdict); </b>/**< note : cdict will just be referenced, and must outlive compression session */<b>
376size_t ZSTD_resetCStream(ZSTD_CStream* zcs, unsigned long long pledgedSrcSize); </b>/**< re-use compression parameters from previous init; skip dictionary loading stage; zcs must be init at least once before */<b>
Przemyslaw Skibinski86d94242016-10-24 16:07:53 +0200377size_t ZSTD_sizeof_CStream(const ZSTD_CStream* zcs);
378</b></pre><BR>
379<h3>Advanced Streaming decompression functions</h3><pre><b>typedef enum { ZSTDdsp_maxWindowSize } ZSTD_DStreamParameter_e;
380ZSTD_DStream* ZSTD_createDStream_advanced(ZSTD_customMem customMem);
381size_t ZSTD_initDStream_usingDict(ZSTD_DStream* zds, const void* dict, size_t dictSize);
382size_t ZSTD_setDStreamParameter(ZSTD_DStream* zds, ZSTD_DStreamParameter_e paramType, unsigned paramValue);
Przemyslaw Skibinski1fd5b452016-10-31 10:44:44 +0100383size_t ZSTD_initDStream_usingDDict(ZSTD_DStream* zds, const ZSTD_DDict* ddict); </b>/**< note : ddict will just be referenced, and must outlive decompression session */<b>
Przemyslaw Skibinski86d94242016-10-24 16:07:53 +0200384size_t ZSTD_resetDStream(ZSTD_DStream* zds); </b>/**< re-use decompression parameters from previous init; saves dictionary loading */<b>
385size_t ZSTD_sizeof_DStream(const ZSTD_DStream* zds);
386</b></pre><BR>
387<a name="Chapter15"></a><h2>Buffer-less and synchronous inner streaming functions</h2><pre>
388 This is an advanced API, giving full control over buffer management, for users which need direct control over memory.
389 But it's also a complex one, with many restrictions (documented below).
Przemyslaw Skibinski1fd5b452016-10-31 10:44:44 +0100390 Prefer using normal streaming API for an easier experience
Przemyslaw Skibinski86d94242016-10-24 16:07:53 +0200391
392<BR></pre>
393
394<a name="Chapter16"></a><h2>Buffer-less streaming compression (synchronous mode)</h2><pre>
395 A ZSTD_CCtx object is required to track streaming operations.
396 Use ZSTD_createCCtx() / ZSTD_freeCCtx() to manage resource.
397 ZSTD_CCtx object can be re-used multiple times within successive compression operations.
398
399 Start by initializing a context.
400 Use ZSTD_compressBegin(), or ZSTD_compressBegin_usingDict() for dictionary compression,
401 or ZSTD_compressBegin_advanced(), for finer parameter control.
402 It's also possible to duplicate a reference context which has already been initialized, using ZSTD_copyCCtx()
403
404 Then, consume your input using ZSTD_compressContinue().
405 There are some important considerations to keep in mind when using this advanced function :
406 - ZSTD_compressContinue() has no internal buffer. It uses externally provided buffer only.
407 - Interface is synchronous : input is consumed entirely and produce 1+ (or more) compressed blocks.
408 - Caller must ensure there is enough space in `dst` to store compressed data under worst case scenario.
409 Worst case evaluation is provided by ZSTD_compressBound().
410 ZSTD_compressContinue() doesn't guarantee recover after a failed compression.
411 - ZSTD_compressContinue() presumes prior input ***is still accessible and unmodified*** (up to maximum distance size, see WindowLog).
412 It remembers all previous contiguous blocks, plus one separated memory segment (which can itself consists of multiple contiguous blocks)
413 - ZSTD_compressContinue() detects that prior input has been overwritten when `src` buffer overlaps.
414 In which case, it will "discard" the relevant memory section from its history.
415
416 Finish a frame with ZSTD_compressEnd(), which will write the last block(s) and optional checksum.
417 It's possible to use a NULL,0 src content, in which case, it will write a final empty block to end the frame,
418 Without last block mark, frames will be considered unfinished (broken) by decoders.
419
420 You can then reuse `ZSTD_CCtx` (ZSTD_compressBegin()) to compress some new frame.
421<BR></pre>
422
423<h3>Buffer-less streaming compression functions</h3><pre><b>size_t ZSTD_compressBegin(ZSTD_CCtx* cctx, int compressionLevel);
424size_t ZSTD_compressBegin_usingDict(ZSTD_CCtx* cctx, const void* dict, size_t dictSize, int compressionLevel);
425size_t ZSTD_compressBegin_advanced(ZSTD_CCtx* cctx, const void* dict, size_t dictSize, ZSTD_parameters params, unsigned long long pledgedSrcSize);
426size_t ZSTD_copyCCtx(ZSTD_CCtx* cctx, const ZSTD_CCtx* preparedCCtx, unsigned long long pledgedSrcSize);
427size_t ZSTD_compressContinue(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize);
428size_t ZSTD_compressEnd(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize);
429</b></pre><BR>
430<a name="Chapter17"></a><h2>Buffer-less streaming decompression (synchronous mode)</h2><pre>
431 A ZSTD_DCtx object is required to track streaming operations.
432 Use ZSTD_createDCtx() / ZSTD_freeDCtx() to manage it.
433 A ZSTD_DCtx object can be re-used multiple times.
434
435 First typical operation is to retrieve frame parameters, using ZSTD_getFrameParams().
436 It fills a ZSTD_frameParams structure which provide important information to correctly decode the frame,
437 such as the minimum rolling buffer size to allocate to decompress data (`windowSize`),
438 and the dictionary ID used.
439 (Note : content size is optional, it may not be present. 0 means : content size unknown).
440 Note that these values could be wrong, either because of data malformation, or because an attacker is spoofing deliberate false information.
441 As a consequence, check that values remain within valid application range, especially `windowSize`, before allocation.
442 Each application can set its own limit, depending on local restrictions. For extended interoperability, it is recommended to support at least 8 MB.
443 Frame parameters are extracted from the beginning of the compressed frame.
444 Data fragment must be large enough to ensure successful decoding, typically `ZSTD_frameHeaderSize_max` bytes.
445 @result : 0 : successful decoding, the `ZSTD_frameParams` structure is correctly filled.
446 >0 : `srcSize` is too small, please provide at least @result bytes on next attempt.
447 errorCode, which can be tested using ZSTD_isError().
448
449 Start decompression, with ZSTD_decompressBegin() or ZSTD_decompressBegin_usingDict().
450 Alternatively, you can copy a prepared context, using ZSTD_copyDCtx().
451
452 Then use ZSTD_nextSrcSizeToDecompress() and ZSTD_decompressContinue() alternatively.
453 ZSTD_nextSrcSizeToDecompress() tells how many bytes to provide as 'srcSize' to ZSTD_decompressContinue().
454 ZSTD_decompressContinue() requires this _exact_ amount of bytes, or it will fail.
455
456 @result of ZSTD_decompressContinue() is the number of bytes regenerated within 'dst' (necessarily <= dstCapacity).
457 It can be zero, which is not an error; it just means ZSTD_decompressContinue() has decoded some metadata item.
458 It can also be an error code, which can be tested with ZSTD_isError().
459
460 ZSTD_decompressContinue() needs previous data blocks during decompression, up to `windowSize`.
461 They should preferably be located contiguously, prior to current block.
462 Alternatively, a round buffer of sufficient size is also possible. Sufficient size is determined by frame parameters.
463 ZSTD_decompressContinue() is very sensitive to contiguity,
464 if 2 blocks don't follow each other, make sure that either the compressor breaks contiguity at the same place,
465 or that previous contiguous segment is large enough to properly handle maximum back-reference.
466
467 A frame is fully decoded when ZSTD_nextSrcSizeToDecompress() returns zero.
468 Context can then be reset to start a new decompression.
469
470 Note : it's possible to know if next input to present is a header or a block, using ZSTD_nextInputType().
471 This information is not required to properly decode a frame.
472
473 == Special case : skippable frames ==
474
475 Skippable frames allow integration of user-defined data into a flow of concatenated frames.
476 Skippable frames will be ignored (skipped) by a decompressor. The format of skippable frames is as follows :
477 a) Skippable frame ID - 4 Bytes, Little endian format, any value from 0x184D2A50 to 0x184D2A5F
478 b) Frame Size - 4 Bytes, Little endian format, unsigned 32-bits
479 c) Frame Content - any content (User Data) of length equal to Frame Size
480 For skippable frames ZSTD_decompressContinue() always returns 0.
481 For skippable frames ZSTD_getFrameParams() returns fparamsPtr->windowLog==0 what means that a frame is skippable.
482 It also returns Frame Size as fparamsPtr->frameContentSize.
483<BR></pre>
484
485<pre><b>typedef struct {
486 unsigned long long frameContentSize;
487 unsigned windowSize;
488 unsigned dictID;
489 unsigned checksumFlag;
490} ZSTD_frameParams;
491</b></pre><BR>
492<h3>Buffer-less streaming decompression functions</h3><pre><b>size_t ZSTD_getFrameParams(ZSTD_frameParams* fparamsPtr, const void* src, size_t srcSize); </b>/**< doesn't consume input, see details below */<b>
493size_t ZSTD_decompressBegin(ZSTD_DCtx* dctx);
494size_t ZSTD_decompressBegin_usingDict(ZSTD_DCtx* dctx, const void* dict, size_t dictSize);
495void ZSTD_copyDCtx(ZSTD_DCtx* dctx, const ZSTD_DCtx* preparedDCtx);
496size_t ZSTD_nextSrcSizeToDecompress(ZSTD_DCtx* dctx);
497size_t ZSTD_decompressContinue(ZSTD_DCtx* dctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize);
498typedef enum { ZSTDnit_frameHeader, ZSTDnit_blockHeader, ZSTDnit_block, ZSTDnit_lastBlock, ZSTDnit_checksum, ZSTDnit_skippableFrame } ZSTD_nextInputType_e;
499ZSTD_nextInputType_e ZSTD_nextInputType(ZSTD_DCtx* dctx);
500</b></pre><BR>
501<a name="Chapter18"></a><h2>Block functions</h2><pre>
502 Block functions produce and decode raw zstd blocks, without frame metadata.
503 Frame metadata cost is typically ~18 bytes, which can be non-negligible for very small blocks (< 100 bytes).
504 User will have to take in charge required information to regenerate data, such as compressed and content sizes.
505
506 A few rules to respect :
507 - Compressing and decompressing require a context structure
508 + Use ZSTD_createCCtx() and ZSTD_createDCtx()
509 - It is necessary to init context before starting
510 + compression : ZSTD_compressBegin()
511 + decompression : ZSTD_decompressBegin()
512 + variants _usingDict() are also allowed
513 + copyCCtx() and copyDCtx() work too
514 - Block size is limited, it must be <= ZSTD_getBlockSizeMax()
515 + If you need to compress more, cut data into multiple blocks
516 + Consider using the regular ZSTD_compress() instead, as frame metadata costs become negligible when source size is large.
517 - When a block is considered not compressible enough, ZSTD_compressBlock() result will be zero.
518 In which case, nothing is produced into `dst`.
519 + User must test for such outcome and deal directly with uncompressed data
520 + ZSTD_decompressBlock() doesn't accept uncompressed data as input !!!
521 + In case of multiple successive blocks, decoder must be informed of uncompressed block existence to follow proper history.
522 Use ZSTD_insertBlock() in such a case.
523<BR></pre>
524
525<h3>Raw zstd block functions</h3><pre><b>size_t ZSTD_getBlockSizeMax(ZSTD_CCtx* cctx);
526size_t ZSTD_compressBlock (ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize);
527size_t ZSTD_decompressBlock(ZSTD_DCtx* dctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize);
528size_t ZSTD_insertBlock(ZSTD_DCtx* dctx, const void* blockStart, size_t blockSize); </b>/**< insert block into `dctx` history. Useful for uncompressed blocks */<b>
529</b></pre><BR>
530</html>
531</body>