|
@@ -1,16 +1,17 @@
|
|
|
<html>
|
|
|
<head>
|
|
|
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
|
|
-<title>zstd 1.5.5 Manual</title>
|
|
|
+<title>zstd 1.5.7 Manual</title>
|
|
|
</head>
|
|
|
<body>
|
|
|
-<h1>zstd 1.5.5 Manual</h1>
|
|
|
+<h1>zstd 1.5.7 Manual</h1>
|
|
|
+Note: the content of this file has been automatically generated by parsing "zstd.h"
|
|
|
<hr>
|
|
|
<a name="Contents"></a><h2>Contents</h2>
|
|
|
<ol>
|
|
|
<li><a href="#Chapter1">Introduction</a></li>
|
|
|
<li><a href="#Chapter2">Version</a></li>
|
|
|
-<li><a href="#Chapter3">Simple API</a></li>
|
|
|
+<li><a href="#Chapter3">Simple Core API</a></li>
|
|
|
<li><a href="#Chapter4">Explicit context</a></li>
|
|
|
<li><a href="#Chapter5">Advanced compression API (Requires v1.4.0+)</a></li>
|
|
|
<li><a href="#Chapter6">Advanced decompression API (Requires v1.4.0+)</a></li>
|
|
@@ -74,7 +75,7 @@
|
|
|
</b><p> Return runtime library version, like "1.4.5". Requires v1.3.0+.
|
|
|
</p></pre><BR>
|
|
|
|
|
|
-<a name="Chapter3"></a><h2>Simple API</h2><pre></pre>
|
|
|
+<a name="Chapter3"></a><h2>Simple Core API</h2><pre></pre>
|
|
|
|
|
|
<pre><b>size_t ZSTD_compress( void* dst, size_t dstCapacity,
|
|
|
const void* src, size_t srcSize,
|
|
@@ -88,38 +89,42 @@
|
|
|
|
|
|
<pre><b>size_t ZSTD_decompress( void* dst, size_t dstCapacity,
|
|
|
const void* src, size_t compressedSize);
|
|
|
-</b><p> `compressedSize` : must be the _exact_ size of some number of compressed and/or skippable frames.
|
|
|
- `dstCapacity` is an upper bound of originalSize to regenerate.
|
|
|
- If user cannot imply a maximum upper bound, it's better to use streaming mode to decompress data.
|
|
|
- @return : the number of bytes decompressed into `dst` (<= `dstCapacity`),
|
|
|
- or an errorCode if it fails (which can be tested using ZSTD_isError()).
|
|
|
+</b><p> `compressedSize` : must be the _exact_ size of some number of compressed and/or skippable frames.
|
|
|
+ Multiple compressed frames can be decompressed at once with this method.
|
|
|
+ The result will be the concatenation of all decompressed frames, back to back.
|
|
|
+ `dstCapacity` is an upper bound of originalSize to regenerate.
|
|
|
+ First frame's decompressed size can be extracted using ZSTD_getFrameContentSize().
|
|
|
+ If maximum upper bound isn't known, prefer using streaming mode to decompress data.
|
|
|
+ @return : the number of bytes decompressed into `dst` (<= `dstCapacity`),
|
|
|
+ or an errorCode if it fails (which can be tested using ZSTD_isError()).
|
|
|
</p></pre><BR>
|
|
|
|
|
|
+<h3>Decompression helper functions</h3><pre></pre><b><pre></pre></b><BR>
|
|
|
<pre><b>#define ZSTD_CONTENTSIZE_UNKNOWN (0ULL - 1)
|
|
|
#define ZSTD_CONTENTSIZE_ERROR (0ULL - 2)
|
|
|
unsigned long long ZSTD_getFrameContentSize(const void *src, size_t srcSize);
|
|
|
-</b><p> `src` should point to the start of a ZSTD encoded frame.
|
|
|
- `srcSize` must be at least as large as the frame header.
|
|
|
- hint : any size >= `ZSTD_frameHeaderSize_max` is large enough.
|
|
|
- @return : - decompressed size of `src` frame content, if known
|
|
|
- - ZSTD_CONTENTSIZE_UNKNOWN if the size cannot be determined
|
|
|
- - ZSTD_CONTENTSIZE_ERROR if an error occurred (e.g. invalid magic number, srcSize too small)
|
|
|
- note 1 : a 0 return value means the frame is valid but "empty".
|
|
|
- note 2 : decompressed size is an optional field, it may not be present, typically in streaming mode.
|
|
|
- When `return==ZSTD_CONTENTSIZE_UNKNOWN`, data to decompress could be any size.
|
|
|
- In which case, it's necessary to use streaming mode to decompress data.
|
|
|
- Optionally, application can rely on some implicit limit,
|
|
|
- as ZSTD_decompress() only needs an upper bound of decompressed size.
|
|
|
- (For example, data could be necessarily cut into blocks <= 16 KB).
|
|
|
- note 3 : decompressed size is always present when compression is completed using single-pass functions,
|
|
|
- such as ZSTD_compress(), ZSTD_compressCCtx() ZSTD_compress_usingDict() or ZSTD_compress_usingCDict().
|
|
|
- note 4 : decompressed size can be very large (64-bits value),
|
|
|
- potentially larger than what local system can handle as a single memory segment.
|
|
|
- In which case, it's necessary to use streaming mode to decompress data.
|
|
|
- note 5 : If source is untrusted, decompressed size could be wrong or intentionally modified.
|
|
|
- Always ensure return value fits within application's authorized limits.
|
|
|
- Each application can set its own limits.
|
|
|
- note 6 : This function replaces ZSTD_getDecompressedSize()
|
|
|
+</b><p> `src` should point to the start of a ZSTD encoded frame.
|
|
|
+ `srcSize` must be at least as large as the frame header.
|
|
|
+ hint : any size >= `ZSTD_frameHeaderSize_max` is large enough.
|
|
|
+ @return : - decompressed size of `src` frame content, if known
|
|
|
+ - ZSTD_CONTENTSIZE_UNKNOWN if the size cannot be determined
|
|
|
+ - ZSTD_CONTENTSIZE_ERROR if an error occurred (e.g. invalid magic number, srcSize too small)
|
|
|
+ note 1 : a 0 return value means the frame is valid but "empty".
|
|
|
+ note 2 : decompressed size is an optional field, it may not be present (typically in streaming mode).
|
|
|
+ When `return==ZSTD_CONTENTSIZE_UNKNOWN`, data to decompress could be any size.
|
|
|
+ In which case, it's necessary to use streaming mode to decompress data.
|
|
|
+ Optionally, application can rely on some implicit limit,
|
|
|
+ as ZSTD_decompress() only needs an upper bound of decompressed size.
|
|
|
+ (For example, data could be necessarily cut into blocks <= 16 KB).
|
|
|
+ note 3 : decompressed size is always present when compression is completed using single-pass functions,
|
|
|
+ such as ZSTD_compress(), ZSTD_compressCCtx() ZSTD_compress_usingDict() or ZSTD_compress_usingCDict().
|
|
|
+ note 4 : decompressed size can be very large (64-bits value),
|
|
|
+ potentially larger than what local system can handle as a single memory segment.
|
|
|
+ In which case, it's necessary to use streaming mode to decompress data.
|
|
|
+ note 5 : If source is untrusted, decompressed size could be wrong or intentionally modified.
|
|
|
+ Always ensure return value fits within application's authorized limits.
|
|
|
+ Each application can set its own limits.
|
|
|
+ note 6 : This function replaces ZSTD_getDecompressedSize()
|
|
|
</p></pre><BR>
|
|
|
|
|
|
<pre><b>ZSTD_DEPRECATED("Replaced by ZSTD_getFrameContentSize")
|
|
@@ -140,67 +145,71 @@ unsigned long long ZSTD_getDecompressedSize(const void* src, size_t srcSize);
|
|
|
or an error code if input is invalid
|
|
|
</p></pre><BR>
|
|
|
|
|
|
-<h3>Helper functions</h3><pre></pre><b><pre></b>/* ZSTD_compressBound() :<b>
|
|
|
- * maximum compressed size in worst case single-pass scenario.
|
|
|
- * When invoking `ZSTD_compress()` or any other one-pass compression function,
|
|
|
- * it's recommended to provide @dstCapacity >= ZSTD_compressBound(srcSize)
|
|
|
- * as it eliminates one potential failure scenario,
|
|
|
- * aka not enough room in dst buffer to write the compressed frame.
|
|
|
- * Note : ZSTD_compressBound() itself can fail, if @srcSize > ZSTD_MAX_INPUT_SIZE .
|
|
|
- * In which case, ZSTD_compressBound() will return an error code
|
|
|
- * which can be tested using ZSTD_isError().
|
|
|
- *
|
|
|
- * ZSTD_COMPRESSBOUND() :
|
|
|
- * same as ZSTD_compressBound(), but as a macro.
|
|
|
- * It can be used to produce constants, which can be useful for static allocation,
|
|
|
- * for example to size a static array on stack.
|
|
|
- * Will produce constant value 0 if srcSize too large.
|
|
|
- */
|
|
|
-#define ZSTD_MAX_INPUT_SIZE ((sizeof(size_t)==8) ? 0xFF00FF00FF00FF00LLU : 0xFF00FF00U)
|
|
|
+<h3>Compression helper functions</h3><pre></pre><b><pre></pre></b><BR>
|
|
|
+<pre><b>#define ZSTD_MAX_INPUT_SIZE ((sizeof(size_t)==8) ? 0xFF00FF00FF00FF00ULL : 0xFF00FF00U)
|
|
|
#define ZSTD_COMPRESSBOUND(srcSize) (((size_t)(srcSize) >= ZSTD_MAX_INPUT_SIZE) ? 0 : (srcSize) + ((srcSize)>>8) + (((srcSize) < (128<<10)) ? (((128<<10) - (srcSize)) >> 11) </b>/* margin, from 64 to 0 */ : 0)) /* this formula ensures that bound(A) + bound(B) <= bound(A+B) as long as A and B >= 128 KB */<b>
|
|
|
size_t ZSTD_compressBound(size_t srcSize); </b>/*!< maximum compressed size in worst case single-pass scenario */<b>
|
|
|
+</b><p> maximum compressed size in worst case single-pass scenario.
|
|
|
+ When invoking `ZSTD_compress()`, or any other one-pass compression function,
|
|
|
+ it's recommended to provide @dstCapacity >= ZSTD_compressBound(srcSize)
|
|
|
+ as it eliminates one potential failure scenario,
|
|
|
+ aka not enough room in dst buffer to write the compressed frame.
|
|
|
+ Note : ZSTD_compressBound() itself can fail, if @srcSize >= ZSTD_MAX_INPUT_SIZE .
|
|
|
+ In which case, ZSTD_compressBound() will return an error code
|
|
|
+ which can be tested using ZSTD_isError().
|
|
|
+
|
|
|
+ ZSTD_COMPRESSBOUND() :
|
|
|
+ same as ZSTD_compressBound(), but as a macro.
|
|
|
+ It can be used to produce constants, which can be useful for static allocation,
|
|
|
+ for example to size a static array on stack.
|
|
|
+ Will produce constant value 0 if srcSize is too large.
|
|
|
+
|
|
|
+</p></pre><BR>
|
|
|
+
|
|
|
+<h3>Error helper functions</h3><pre></pre><b><pre>#include "zstd_errors.h" </b>/* list of errors */<b>
|
|
|
</b>/* ZSTD_isError() :<b>
|
|
|
* Most ZSTD_* functions returning a size_t value can be tested for error,
|
|
|
* using ZSTD_isError().
|
|
|
* @return 1 if error, 0 otherwise
|
|
|
*/
|
|
|
-unsigned ZSTD_isError(size_t code); </b>/*!< tells if a `size_t` function result is an error code */<b>
|
|
|
-const char* ZSTD_getErrorName(size_t code); </b>/*!< provides readable string from an error code */<b>
|
|
|
-int ZSTD_minCLevel(void); </b>/*!< minimum negative compression level allowed, requires v1.4.0+ */<b>
|
|
|
-int ZSTD_maxCLevel(void); </b>/*!< maximum compression level available */<b>
|
|
|
-int ZSTD_defaultCLevel(void); </b>/*!< default compression level, specified by ZSTD_CLEVEL_DEFAULT, requires v1.5.0+ */<b>
|
|
|
+unsigned ZSTD_isError(size_t result); </b>/*!< tells if a `size_t` function result is an error code */<b>
|
|
|
+ZSTD_ErrorCode ZSTD_getErrorCode(size_t functionResult); </b>/* convert a result into an error code, which can be compared to error enum list */<b>
|
|
|
+const char* ZSTD_getErrorName(size_t result); </b>/*!< provides readable string from a function result */<b>
|
|
|
+int ZSTD_minCLevel(void); </b>/*!< minimum negative compression level allowed, requires v1.4.0+ */<b>
|
|
|
+int ZSTD_maxCLevel(void); </b>/*!< maximum compression level available */<b>
|
|
|
+int ZSTD_defaultCLevel(void); </b>/*!< default compression level, specified by ZSTD_CLEVEL_DEFAULT, requires v1.5.0+ */<b>
|
|
|
</pre></b><BR>
|
|
|
<a name="Chapter4"></a><h2>Explicit context</h2><pre></pre>
|
|
|
|
|
|
<h3>Compression context</h3><pre> When compressing many times,
|
|
|
- it is recommended to allocate a context just once,
|
|
|
- and re-use it for each successive compression operation.
|
|
|
- This will make workload friendlier for system's memory.
|
|
|
+ it is recommended to allocate a compression context just once,
|
|
|
+ and reuse it for each successive compression operation.
|
|
|
+ This will make the workload easier for system's memory.
|
|
|
Note : re-using context is just a speed / resource optimization.
|
|
|
It doesn't change the compression ratio, which remains identical.
|
|
|
- Note 2 : In multi-threaded environments,
|
|
|
- use one different context per thread for parallel execution.
|
|
|
+ Note 2: For parallel execution in multi-threaded environments,
|
|
|
+ use one different context per thread .
|
|
|
|
|
|
</pre><b><pre>typedef struct ZSTD_CCtx_s ZSTD_CCtx;
|
|
|
ZSTD_CCtx* ZSTD_createCCtx(void);
|
|
|
-size_t ZSTD_freeCCtx(ZSTD_CCtx* cctx); </b>/* accept NULL pointer */<b>
|
|
|
+size_t ZSTD_freeCCtx(ZSTD_CCtx* cctx); </b>/* compatible with NULL pointer */<b>
|
|
|
</pre></b><BR>
|
|
|
<pre><b>size_t ZSTD_compressCCtx(ZSTD_CCtx* cctx,
|
|
|
void* dst, size_t dstCapacity,
|
|
|
const void* src, size_t srcSize,
|
|
|
int compressionLevel);
|
|
|
</b><p> Same as ZSTD_compress(), using an explicit ZSTD_CCtx.
|
|
|
- Important : in order to behave similarly to `ZSTD_compress()`,
|
|
|
- this function compresses at requested compression level,
|
|
|
- __ignoring any other parameter__ .
|
|
|
+ Important : in order to mirror `ZSTD_compress()` behavior,
|
|
|
+ this function compresses at the requested compression level,
|
|
|
+ __ignoring any other advanced parameter__ .
|
|
|
If any advanced parameter was set using the advanced API,
|
|
|
- they will all be reset. Only `compressionLevel` remains.
|
|
|
+ they will all be reset. Only @compressionLevel remains.
|
|
|
|
|
|
</p></pre><BR>
|
|
|
|
|
|
<h3>Decompression context</h3><pre> When decompressing many times,
|
|
|
it is recommended to allocate a context only once,
|
|
|
- and re-use it for each successive compression operation.
|
|
|
+ and reuse it for each successive compression operation.
|
|
|
This will make workload friendlier for system's memory.
|
|
|
Use one context per thread for parallel execution.
|
|
|
</pre><b><pre>typedef struct ZSTD_DCtx_s ZSTD_DCtx;
|
|
@@ -212,7 +221,7 @@ size_t ZSTD_freeDCtx(ZSTD_DCtx* dctx); </b>/* accept NULL pointer */<b>
|
|
|
const void* src, size_t srcSize);
|
|
|
</b><p> Same as ZSTD_decompress(),
|
|
|
requires an allocated ZSTD_DCtx.
|
|
|
- Compatible with sticky parameters.
|
|
|
+ Compatible with sticky parameters (see below).
|
|
|
|
|
|
</p></pre><BR>
|
|
|
|
|
@@ -296,6 +305,19 @@ size_t ZSTD_freeDCtx(ZSTD_DCtx* dctx); </b>/* accept NULL pointer */<b>
|
|
|
* The higher the value of selected strategy, the more complex it is,
|
|
|
* resulting in stronger and slower compression.
|
|
|
* Special: value 0 means "use default strategy". */
|
|
|
+
|
|
|
+ ZSTD_c_targetCBlockSize=130, </b>/* v1.5.6+<b>
|
|
|
+ * Attempts to fit compressed block size into approximately targetCBlockSize.
|
|
|
+ * Bound by ZSTD_TARGETCBLOCKSIZE_MIN and ZSTD_TARGETCBLOCKSIZE_MAX.
|
|
|
+ * Note that it's not a guarantee, just a convergence target (default:0).
|
|
|
+ * No target when targetCBlockSize == 0.
|
|
|
+ * This is helpful in low bandwidth streaming environments to improve end-to-end latency,
|
|
|
+ * when a client can make use of partial documents (a prominent example being Chrome).
|
|
|
+ * Note: this parameter is stable since v1.5.6.
|
|
|
+ * It was present as an experimental parameter in earlier versions,
|
|
|
+ * but it's not recommended using it with earlier library versions
|
|
|
+ * due to massive performance regressions.
|
|
|
+ */
|
|
|
</b>/* LDM mode parameters */<b>
|
|
|
ZSTD_c_enableLongDistanceMatching=160, </b>/* Enable long distance matching.<b>
|
|
|
* This parameter is designed to improve compression ratio
|
|
@@ -375,14 +397,14 @@ size_t ZSTD_freeDCtx(ZSTD_DCtx* dctx); </b>/* accept NULL pointer */<b>
|
|
|
* ZSTD_c_forceMaxWindow
|
|
|
* ZSTD_c_forceAttachDict
|
|
|
* ZSTD_c_literalCompressionMode
|
|
|
- * ZSTD_c_targetCBlockSize
|
|
|
* ZSTD_c_srcSizeHint
|
|
|
* ZSTD_c_enableDedicatedDictSearch
|
|
|
* ZSTD_c_stableInBuffer
|
|
|
* ZSTD_c_stableOutBuffer
|
|
|
* ZSTD_c_blockDelimiters
|
|
|
* ZSTD_c_validateSequences
|
|
|
- * ZSTD_c_useBlockSplitter
|
|
|
+ * ZSTD_c_blockSplitterLevel
|
|
|
+ * ZSTD_c_splitAfterSequences
|
|
|
* ZSTD_c_useRowMatchFinder
|
|
|
* ZSTD_c_prefetchCDictTables
|
|
|
* ZSTD_c_enableSeqProducerFallback
|
|
@@ -396,7 +418,7 @@ size_t ZSTD_freeDCtx(ZSTD_DCtx* dctx); </b>/* accept NULL pointer */<b>
|
|
|
ZSTD_c_experimentalParam3=1000,
|
|
|
ZSTD_c_experimentalParam4=1001,
|
|
|
ZSTD_c_experimentalParam5=1002,
|
|
|
- ZSTD_c_experimentalParam6=1003,
|
|
|
+ </b>/* was ZSTD_c_experimentalParam6=1003; is now ZSTD_c_targetCBlockSize */<b>
|
|
|
ZSTD_c_experimentalParam7=1004,
|
|
|
ZSTD_c_experimentalParam8=1005,
|
|
|
ZSTD_c_experimentalParam9=1006,
|
|
@@ -409,7 +431,8 @@ size_t ZSTD_freeDCtx(ZSTD_DCtx* dctx); </b>/* accept NULL pointer */<b>
|
|
|
ZSTD_c_experimentalParam16=1013,
|
|
|
ZSTD_c_experimentalParam17=1014,
|
|
|
ZSTD_c_experimentalParam18=1015,
|
|
|
- ZSTD_c_experimentalParam19=1016
|
|
|
+ ZSTD_c_experimentalParam19=1016,
|
|
|
+ ZSTD_c_experimentalParam20=1017
|
|
|
} ZSTD_cParameter;
|
|
|
</b></pre><BR>
|
|
|
<pre><b>typedef struct {
|
|
@@ -483,6 +506,7 @@ size_t ZSTD_freeDCtx(ZSTD_DCtx* dctx); </b>/* accept NULL pointer */<b>
|
|
|
void* dst, size_t dstCapacity,
|
|
|
const void* src, size_t srcSize);
|
|
|
</b><p> Behave the same as ZSTD_compressCCtx(), but compression parameters are set using the advanced API.
|
|
|
+ (note that this entry point doesn't even expose a compression level parameter).
|
|
|
ZSTD_compress2() always starts a new frame.
|
|
|
Should cctx hold data from a previously unfinished frame, everything about it is forgotten.
|
|
|
- Compression parameters are pushed into CCtx before starting compression, using ZSTD_CCtx_set*()
|
|
@@ -513,6 +537,7 @@ size_t ZSTD_freeDCtx(ZSTD_DCtx* dctx); </b>/* accept NULL pointer */<b>
|
|
|
* ZSTD_d_forceIgnoreChecksum
|
|
|
* ZSTD_d_refMultipleDDicts
|
|
|
* ZSTD_d_disableHuffmanAssembly
|
|
|
+ * ZSTD_d_maxBlockSize
|
|
|
* Because they are not stable, it's necessary to define ZSTD_STATIC_LINKING_ONLY to access them.
|
|
|
* note : never ever use experimentalParam? names directly
|
|
|
*/
|
|
@@ -520,7 +545,8 @@ size_t ZSTD_freeDCtx(ZSTD_DCtx* dctx); </b>/* accept NULL pointer */<b>
|
|
|
ZSTD_d_experimentalParam2=1001,
|
|
|
ZSTD_d_experimentalParam3=1002,
|
|
|
ZSTD_d_experimentalParam4=1003,
|
|
|
- ZSTD_d_experimentalParam5=1004
|
|
|
+ ZSTD_d_experimentalParam5=1004,
|
|
|
+ ZSTD_d_experimentalParam6=1005
|
|
|
|
|
|
} ZSTD_dParameter;
|
|
|
</b></pre><BR>
|
|
@@ -568,14 +594,14 @@ size_t ZSTD_freeDCtx(ZSTD_DCtx* dctx); </b>/* accept NULL pointer */<b>
|
|
|
A ZSTD_CStream object is required to track streaming operation.
|
|
|
Use ZSTD_createCStream() and ZSTD_freeCStream() to create/release resources.
|
|
|
ZSTD_CStream objects can be reused multiple times on consecutive compression operations.
|
|
|
- It is recommended to re-use ZSTD_CStream since it will play nicer with system's memory, by re-using already allocated memory.
|
|
|
+ It is recommended to reuse ZSTD_CStream since it will play nicer with system's memory, by re-using already allocated memory.
|
|
|
|
|
|
For parallel execution, use one separate ZSTD_CStream per thread.
|
|
|
|
|
|
note : since v1.3.0, ZSTD_CStream and ZSTD_CCtx are the same thing.
|
|
|
|
|
|
Parameters are sticky : when starting a new compression on the same context,
|
|
|
- it will re-use the same sticky parameters as previous compression session.
|
|
|
+ it will reuse the same sticky parameters as previous compression session.
|
|
|
When in doubt, it's recommended to fully initialize the context before usage.
|
|
|
Use ZSTD_CCtx_reset() to reset the context and ZSTD_CCtx_setParameter(),
|
|
|
ZSTD_CCtx_setPledgedSrcSize(), or ZSTD_CCtx_loadDictionary() and friends to
|
|
@@ -666,6 +692,11 @@ size_t ZSTD_freeCStream(ZSTD_CStream* zcs); </b>/* accept NULL pointer */<b>
|
|
|
only ZSTD_e_end or ZSTD_e_flush operations are allowed.
|
|
|
Before starting a new compression job, or changing compression parameters,
|
|
|
it is required to fully flush internal buffers.
|
|
|
+ - note: if an operation ends with an error, it may leave @cctx in an undefined state.
|
|
|
+ Therefore, it's UB to invoke ZSTD_compressStream2() of ZSTD_compressStream() on such a state.
|
|
|
+ In order to be re-employed after an error, a state must be reset,
|
|
|
+ which can be done explicitly (ZSTD_CCtx_reset()),
|
|
|
+ or is sometimes implied by methods starting a new compression job (ZSTD_initCStream(), ZSTD_compressCCtx())
|
|
|
|
|
|
</p></pre><BR>
|
|
|
|
|
@@ -698,7 +729,7 @@ size_t ZSTD_endStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output);
|
|
|
<a name="Chapter9"></a><h2>Streaming decompression - HowTo</h2><pre>
|
|
|
A ZSTD_DStream object is required to track streaming operations.
|
|
|
Use ZSTD_createDStream() and ZSTD_freeDStream() to create/release resources.
|
|
|
- ZSTD_DStream objects can be re-used multiple times.
|
|
|
+ ZSTD_DStream objects can be re-employed multiple times.
|
|
|
|
|
|
Use ZSTD_initDStream() to start a new decompression operation.
|
|
|
@return : recommended first input size
|
|
@@ -708,16 +739,21 @@ size_t ZSTD_endStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output);
|
|
|
The function will update both `pos` fields.
|
|
|
If `input.pos < input.size`, some input has not been consumed.
|
|
|
It's up to the caller to present again remaining data.
|
|
|
+
|
|
|
The function tries to flush all data decoded immediately, respecting output buffer size.
|
|
|
If `output.pos < output.size`, decoder has flushed everything it could.
|
|
|
- But if `output.pos == output.size`, there might be some data left within internal buffers.,
|
|
|
+
|
|
|
+ However, when `output.pos == output.size`, it's more difficult to know.
|
|
|
+ If @return > 0, the frame is not complete, meaning
|
|
|
+ either there is still some data left to flush within internal buffers,
|
|
|
+ or there is more input to read to complete the frame (or both).
|
|
|
In which case, call ZSTD_decompressStream() again to flush whatever remains in the buffer.
|
|
|
Note : with no additional input provided, amount of data flushed is necessarily <= ZSTD_BLOCKSIZE_MAX.
|
|
|
@return : 0 when a frame is completely decoded and fully flushed,
|
|
|
or an error code, which can be tested using ZSTD_isError(),
|
|
|
or any other value > 0, which means there is still some decoding or flushing to do to complete current frame :
|
|
|
the return value is a suggested next input size (just a hint for better latency)
|
|
|
- that will never request more than the remaining frame size.
|
|
|
+ that will never request more than the remaining content of the compressed frame.
|
|
|
|
|
|
<BR></pre>
|
|
|
|
|
@@ -743,14 +779,21 @@ size_t ZSTD_freeDStream(ZSTD_DStream* zds); </b>/* accept NULL pointer */<b>
|
|
|
Function will update both input and output `pos` fields exposing current state via these fields:
|
|
|
- `input.pos < input.size`, some input remaining and caller should provide remaining input
|
|
|
on the next call.
|
|
|
- - `output.pos < output.size`, decoder finished and flushed all remaining buffers.
|
|
|
- - `output.pos == output.size`, potentially uncflushed data present in the internal buffers,
|
|
|
- call ZSTD_decompressStream() again to flush remaining data to output.
|
|
|
+ - `output.pos < output.size`, decoder flushed internal output buffer.
|
|
|
+ - `output.pos == output.size`, unflushed data potentially present in the internal buffers,
|
|
|
+ check ZSTD_decompressStream() @return value,
|
|
|
+ if > 0, invoke it again to flush remaining data to output.
|
|
|
Note : with no additional input, amount of data flushed <= ZSTD_BLOCKSIZE_MAX.
|
|
|
|
|
|
@return : 0 when a frame is completely decoded and fully flushed,
|
|
|
or an error code, which can be tested using ZSTD_isError(),
|
|
|
or any other value > 0, which means there is some decoding or flushing to do to complete current frame.
|
|
|
+
|
|
|
+ Note: when an operation returns with an error code, the @zds state may be left in undefined state.
|
|
|
+ It's UB to invoke `ZSTD_decompressStream()` on such a state.
|
|
|
+ In order to re-use such a state, it must be first reset,
|
|
|
+ which can be done explicitly (`ZSTD_DCtx_reset()`),
|
|
|
+ or is implied for operations starting some new decompression job (`ZSTD_initDStream`, `ZSTD_decompressDCtx()`, `ZSTD_decompress_usingDict()`)
|
|
|
|
|
|
</p></pre><BR>
|
|
|
|
|
@@ -869,7 +912,7 @@ size_t ZSTD_freeDStream(ZSTD_DStream* zds); </b>/* accept NULL pointer */<b>
|
|
|
<a name="Chapter13"></a><h2>Advanced dictionary and prefix API (Requires v1.4.0+)</h2><pre>
|
|
|
This API allows dictionaries to be used with ZSTD_compress2(),
|
|
|
ZSTD_compressStream2(), and ZSTD_decompressDCtx().
|
|
|
- Dictionaries are sticky, they remain valid when same context is re-used,
|
|
|
+ Dictionaries are sticky, they remain valid when same context is reused,
|
|
|
they only reset when the context is reset
|
|
|
with ZSTD_reset_parameters or ZSTD_reset_session_and_parameters.
|
|
|
In contrast, Prefixes are single-use.
|
|
@@ -1041,7 +1084,7 @@ size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict);
|
|
|
*
|
|
|
* Note: This field is optional. ZSTD_generateSequences() will calculate the value of
|
|
|
* 'rep', but repeat offsets do not necessarily need to be calculated from an external
|
|
|
- * sequence provider's perspective. For example, ZSTD_compressSequences() does not
|
|
|
+ * sequence provider perspective. For example, ZSTD_compressSequences() does not
|
|
|
* use this 'rep' field at all (as of now).
|
|
|
*/
|
|
|
} ZSTD_Sequence;
|
|
@@ -1146,14 +1189,14 @@ size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict);
|
|
|
} ZSTD_literalCompressionMode_e;
|
|
|
</b></pre><BR>
|
|
|
<pre><b>typedef enum {
|
|
|
- </b>/* Note: This enum controls features which are conditionally beneficial. Zstd typically will make a final<b>
|
|
|
- * decision on whether or not to enable the feature (ZSTD_ps_auto), but setting the switch to ZSTD_ps_enable
|
|
|
- * or ZSTD_ps_disable allow for a force enable/disable the feature.
|
|
|
+ </b>/* Note: This enum controls features which are conditionally beneficial.<b>
|
|
|
+ * Zstd can take a decision on whether or not to enable the feature (ZSTD_ps_auto),
|
|
|
+ * but setting the switch to ZSTD_ps_enable or ZSTD_ps_disable force enable/disable the feature.
|
|
|
*/
|
|
|
ZSTD_ps_auto = 0, </b>/* Let the library automatically determine whether the feature shall be enabled */<b>
|
|
|
ZSTD_ps_enable = 1, </b>/* Force-enable the feature */<b>
|
|
|
ZSTD_ps_disable = 2 </b>/* Do not use the feature */<b>
|
|
|
-} ZSTD_paramSwitch_e;
|
|
|
+} ZSTD_ParamSwitch_e;
|
|
|
</b></pre><BR>
|
|
|
<a name="Chapter15"></a><h2>Frame header and size functions</h2><pre></pre>
|
|
|
|
|
@@ -1201,13 +1244,13 @@ size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict);
|
|
|
or an error code (if srcSize is too small)
|
|
|
</p></pre><BR>
|
|
|
|
|
|
-<pre><b>typedef enum { ZSTD_frame, ZSTD_skippableFrame } ZSTD_frameType_e;
|
|
|
+<pre><b>typedef enum { ZSTD_frame, ZSTD_skippableFrame } ZSTD_FrameType_e;
|
|
|
</b></pre><BR>
|
|
|
<pre><b>typedef struct {
|
|
|
unsigned long long frameContentSize; </b>/* if == ZSTD_CONTENTSIZE_UNKNOWN, it means this field is not available. 0 means "empty" */<b>
|
|
|
unsigned long long windowSize; </b>/* can be very large, up to <= frameContentSize */<b>
|
|
|
unsigned blockSizeMax;
|
|
|
- ZSTD_frameType_e frameType; </b>/* if == ZSTD_skippableFrame, frameContentSize is the size of skippable content */<b>
|
|
|
+ ZSTD_FrameType_e frameType; </b>/* if == ZSTD_skippableFrame, frameContentSize is the size of skippable content */<b>
|
|
|
unsigned headerSize;
|
|
|
unsigned dictID;
|
|
|
unsigned checksumFlag;
|
|
@@ -1215,11 +1258,11 @@ size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict);
|
|
|
unsigned _reserved2;
|
|
|
} ZSTD_frameHeader;
|
|
|
</b></pre><BR>
|
|
|
-<pre><b>ZSTDLIB_STATIC_API size_t ZSTD_getFrameHeader(ZSTD_frameHeader* zfhPtr, const void* src, size_t srcSize); </b>/**< doesn't consume input */<b>
|
|
|
+<pre><b>ZSTDLIB_STATIC_API size_t ZSTD_getFrameHeader(ZSTD_FrameHeader* zfhPtr, const void* src, size_t srcSize); </b>/**< doesn't consume input */<b>
|
|
|
</b>/*! ZSTD_getFrameHeader_advanced() :<b>
|
|
|
* same as ZSTD_getFrameHeader(),
|
|
|
* with added capability to select a format (like ZSTD_f_zstd1_magicless) */
|
|
|
-ZSTDLIB_STATIC_API size_t ZSTD_getFrameHeader_advanced(ZSTD_frameHeader* zfhPtr, const void* src, size_t srcSize, ZSTD_format_e format);
|
|
|
+ZSTDLIB_STATIC_API size_t ZSTD_getFrameHeader_advanced(ZSTD_FrameHeader* zfhPtr, const void* src, size_t srcSize, ZSTD_format_e format);
|
|
|
</b><p> decode Frame Header, or requires larger `srcSize`.
|
|
|
@return : 0, `zfhPtr` is correctly filled,
|
|
|
>0, `srcSize` is too small, value is wanted `srcSize` amount,
|
|
@@ -1272,9 +1315,9 @@ ZSTDLIB_STATIC_API size_t ZSTD_getFrameHeader_advanced(ZSTD_frameHeader* zfhPtr,
|
|
|
</p></pre><BR>
|
|
|
|
|
|
<pre><b>typedef enum {
|
|
|
- ZSTD_sf_noBlockDelimiters = 0, </b>/* Representation of ZSTD_Sequence has no block delimiters, sequences only */<b>
|
|
|
- ZSTD_sf_explicitBlockDelimiters = 1 </b>/* Representation of ZSTD_Sequence contains explicit block delimiters */<b>
|
|
|
-} ZSTD_sequenceFormat_e;
|
|
|
+ ZSTD_sf_noBlockDelimiters = 0, </b>/* ZSTD_Sequence[] has no block delimiters, just sequences */<b>
|
|
|
+ ZSTD_sf_explicitBlockDelimiters = 1 </b>/* ZSTD_Sequence[] contains explicit block delimiters */<b>
|
|
|
+} ZSTD_SequenceFormat_e;
|
|
|
</b></pre><BR>
|
|
|
<pre><b>ZSTDLIB_STATIC_API size_t ZSTD_sequenceBound(size_t srcSize);
|
|
|
</b><p> `srcSize` : size of the input buffer
|
|
@@ -1285,19 +1328,37 @@ ZSTDLIB_STATIC_API size_t ZSTD_getFrameHeader_advanced(ZSTD_frameHeader* zfhPtr,
|
|
|
|
|
|
</p></pre><BR>
|
|
|
|
|
|
-<pre><b></b><p> Generate sequences using ZSTD_compress2(), given a source buffer.
|
|
|
+<pre><b>ZSTD_DEPRECATED("For debugging only, will be replaced by ZSTD_extractSequences()")
|
|
|
+ZSTDLIB_STATIC_API size_t
|
|
|
+ZSTD_generateSequences(ZSTD_CCtx* zc,
|
|
|
+ ZSTD_Sequence* outSeqs, size_t outSeqsCapacity,
|
|
|
+ const void* src, size_t srcSize);
|
|
|
+</b><p> WARNING: This function is meant for debugging and informational purposes ONLY!
|
|
|
+ Its implementation is flawed, and it will be deleted in a future version.
|
|
|
+ It is not guaranteed to succeed, as there are several cases where it will give
|
|
|
+ up and fail. You should NOT use this function in production code.
|
|
|
+
|
|
|
+ This function is deprecated, and will be removed in a future version.
|
|
|
+
|
|
|
+ Generate sequences using ZSTD_compress2(), given a source buffer.
|
|
|
+
|
|
|
+ @param zc The compression context to be used for ZSTD_compress2(). Set any
|
|
|
+ compression parameters you need on this context.
|
|
|
+ @param outSeqs The output sequences buffer of size @p outSeqsSize
|
|
|
+ @param outSeqsCapacity The size of the output sequences buffer.
|
|
|
+ ZSTD_sequenceBound(srcSize) is an upper bound on the number
|
|
|
+ of sequences that can be generated.
|
|
|
+ @param src The source buffer to generate sequences from of size @p srcSize.
|
|
|
+ @param srcSize The size of the source buffer.
|
|
|
|
|
|
Each block will end with a dummy sequence
|
|
|
with offset == 0, matchLength == 0, and litLength == length of last literals.
|
|
|
litLength may be == 0, and if so, then the sequence of (of: 0 ml: 0 ll: 0)
|
|
|
simply acts as a block delimiter.
|
|
|
|
|
|
- @zc can be used to insert custom compression params.
|
|
|
- This function invokes ZSTD_compress2().
|
|
|
-
|
|
|
- The output of this function can be fed into ZSTD_compressSequences() with CCtx
|
|
|
- setting of ZSTD_c_blockDelimiters as ZSTD_sf_explicitBlockDelimiters
|
|
|
- @return : number of sequences generated
|
|
|
+ @returns The number of sequences generated, necessarily less than
|
|
|
+ ZSTD_sequenceBound(srcSize), or an error code that can be checked
|
|
|
+ with ZSTD_isError().
|
|
|
|
|
|
</p></pre><BR>
|
|
|
|
|
@@ -1315,13 +1376,14 @@ ZSTDLIB_STATIC_API size_t ZSTD_getFrameHeader_advanced(ZSTD_frameHeader* zfhPtr,
|
|
|
</p></pre><BR>
|
|
|
|
|
|
<pre><b>ZSTDLIB_STATIC_API size_t
|
|
|
-ZSTD_compressSequences( ZSTD_CCtx* cctx, void* dst, size_t dstSize,
|
|
|
- const ZSTD_Sequence* inSeqs, size_t inSeqsSize,
|
|
|
- const void* src, size_t srcSize);
|
|
|
+ZSTD_compressSequences(ZSTD_CCtx* cctx,
|
|
|
+ void* dst, size_t dstCapacity,
|
|
|
+ const ZSTD_Sequence* inSeqs, size_t inSeqsSize,
|
|
|
+ const void* src, size_t srcSize);
|
|
|
</b><p> Compress an array of ZSTD_Sequence, associated with @src buffer, into dst.
|
|
|
@src contains the entire input (not just the literals).
|
|
|
If @srcSize > sum(sequence.length), the remaining bytes are considered all literals
|
|
|
- If a dictionary is included, then the cctx should reference the dict. (see: ZSTD_CCtx_refCDict(), ZSTD_CCtx_loadDictionary(), etc.)
|
|
|
+ If a dictionary is included, then the cctx should reference the dict (see: ZSTD_CCtx_refCDict(), ZSTD_CCtx_loadDictionary(), etc.).
|
|
|
The entire source is compressed into a single frame.
|
|
|
|
|
|
The compression behavior changes based on cctx params. In particular:
|
|
@@ -1330,11 +1392,17 @@ ZSTD_compressSequences( ZSTD_CCtx* cctx, void* dst, size_t dstSize,
|
|
|
the block size derived from the cctx, and sequences may be split. This is the default setting.
|
|
|
|
|
|
If ZSTD_c_blockDelimiters == ZSTD_sf_explicitBlockDelimiters, the array of ZSTD_Sequence is expected to contain
|
|
|
- block delimiters (defined in ZSTD_Sequence). Behavior is undefined if no block delimiters are provided.
|
|
|
+ valid block delimiters (defined in ZSTD_Sequence). Behavior is undefined if no block delimiters are provided.
|
|
|
+
|
|
|
+ When ZSTD_c_blockDelimiters == ZSTD_sf_explicitBlockDelimiters, it's possible to decide generating repcodes
|
|
|
+ using the advanced parameter ZSTD_c_repcodeResolution. Repcodes will improve compression ratio, though the benefit
|
|
|
+ can vary greatly depending on Sequences. On the other hand, repcode resolution is an expensive operation.
|
|
|
+ By default, it's disabled at low (<10) compression levels, and enabled above the threshold (>=10).
|
|
|
+ ZSTD_c_repcodeResolution makes it possible to directly manage this processing in either direction.
|
|
|
|
|
|
- If ZSTD_c_validateSequences == 0, this function will blindly accept the sequences provided. Invalid sequences cause undefined
|
|
|
- behavior. If ZSTD_c_validateSequences == 1, then if sequence is invalid (see doc/zstd_compression_format.md for
|
|
|
- specifics regarding offset/matchlength requirements) then the function will bail out and return an error.
|
|
|
+ If ZSTD_c_validateSequences == 0, this function blindly accepts the Sequences provided. Invalid Sequences cause undefined
|
|
|
+ behavior. If ZSTD_c_validateSequences == 1, then the function will detect invalid Sequences (see doc/zstd_compression_format.md for
|
|
|
+ specifics regarding offset/matchlength requirements) and then bail out and return an error.
|
|
|
|
|
|
In addition to the two adjustable experimental params, there are other important cctx params.
|
|
|
- ZSTD_c_minMatch MUST be set as less than or equal to the smallest match generated by the match finder. It has a minimum value of ZSTD_MINMATCH_MIN.
|
|
@@ -1342,9 +1410,33 @@ ZSTD_compressSequences( ZSTD_CCtx* cctx, void* dst, size_t dstSize,
|
|
|
- ZSTD_c_windowLog affects offset validation: this function will return an error at higher debug levels if a provided offset
|
|
|
is larger than what the spec allows for a given window log and dictionary (if present). See: doc/zstd_compression_format.md
|
|
|
|
|
|
- Note: Repcodes are, as of now, always re-calculated within this function, so ZSTD_Sequence::rep is unused.
|
|
|
- Note 2: Once we integrate ability to ingest repcodes, the explicit block delims mode must respect those repcodes exactly,
|
|
|
- and cannot emit an RLE block that disagrees with the repcode history
|
|
|
+ Note: Repcodes are, as of now, always re-calculated within this function, ZSTD_Sequence.rep is effectively unused.
|
|
|
+ Dev Note: Once ability to ingest repcodes become available, the explicit block delims mode must respect those repcodes exactly,
|
|
|
+ and cannot emit an RLE block that disagrees with the repcode history.
|
|
|
+ @return : final compressed size, or a ZSTD error code.
|
|
|
+
|
|
|
+</p></pre><BR>
|
|
|
+
|
|
|
+<pre><b>ZSTDLIB_STATIC_API size_t
|
|
|
+ZSTD_compressSequencesAndLiterals(ZSTD_CCtx* cctx,
|
|
|
+ void* dst, size_t dstCapacity,
|
|
|
+ const ZSTD_Sequence* inSeqs, size_t nbSequences,
|
|
|
+ const void* literals, size_t litSize, size_t litCapacity,
|
|
|
+ size_t decompressedSize);
|
|
|
+</b><p> This is a variant of ZSTD_compressSequences() which,
|
|
|
+ instead of receiving (src,srcSize) as input parameter, receives (literals,litSize),
|
|
|
+ aka all the literals, already extracted and laid out into a single continuous buffer.
|
|
|
+ This can be useful if the process generating the sequences also happens to generate the buffer of literals,
|
|
|
+ thus skipping an extraction + caching stage.
|
|
|
+ It's a speed optimization, useful when the right conditions are met,
|
|
|
+ but it also features the following limitations:
|
|
|
+ - Only supports explicit delimiter mode
|
|
|
+ - Currently does not support Sequences validation (so input Sequences are trusted)
|
|
|
+ - Not compatible with frame checksum, which must be disabled
|
|
|
+ - If any block is incompressible, will fail and return an error
|
|
|
+ - @litSize must be == sum of all @.litLength fields in @inSeqs. Any discrepancy will generate an error.
|
|
|
+ - the buffer @literals must have a size @litCapacity which is larger than @litSize by at least 8 bytes.
|
|
|
+ - @decompressedSize must be correct, and correspond to the sum of all Sequences. Any discrepancy will generate an error.
|
|
|
@return : final compressed size, or a ZSTD error code.
|
|
|
|
|
|
</p></pre><BR>
|
|
@@ -1386,58 +1478,61 @@ ZSTD_compressSequences( ZSTD_CCtx* cctx, void* dst, size_t dstSize,
|
|
|
|
|
|
<a name="Chapter16"></a><h2>Memory management</h2><pre></pre>
|
|
|
|
|
|
-<pre><b>ZSTDLIB_STATIC_API size_t ZSTD_estimateCCtxSize(int compressionLevel);
|
|
|
+<pre><b>ZSTDLIB_STATIC_API size_t ZSTD_estimateCCtxSize(int maxCompressionLevel);
|
|
|
ZSTDLIB_STATIC_API size_t ZSTD_estimateCCtxSize_usingCParams(ZSTD_compressionParameters cParams);
|
|
|
ZSTDLIB_STATIC_API size_t ZSTD_estimateCCtxSize_usingCCtxParams(const ZSTD_CCtx_params* params);
|
|
|
ZSTDLIB_STATIC_API size_t ZSTD_estimateDCtxSize(void);
|
|
|
</b><p> These functions make it possible to estimate memory usage
|
|
|
of a future {D,C}Ctx, before its creation.
|
|
|
+ This is useful in combination with ZSTD_initStatic(),
|
|
|
+ which makes it possible to employ a static buffer for ZSTD_CCtx* state.
|
|
|
|
|
|
ZSTD_estimateCCtxSize() will provide a memory budget large enough
|
|
|
- for any compression level up to selected one.
|
|
|
- Note : Unlike ZSTD_estimateCStreamSize*(), this estimate
|
|
|
- does not include space for a window buffer.
|
|
|
- Therefore, the estimation is only guaranteed for single-shot compressions, not streaming.
|
|
|
+ to compress data of any size using one-shot compression ZSTD_compressCCtx() or ZSTD_compress2()
|
|
|
+ associated with any compression level up to max specified one.
|
|
|
The estimate will assume the input may be arbitrarily large,
|
|
|
which is the worst case.
|
|
|
|
|
|
+ Note that the size estimation is specific for one-shot compression,
|
|
|
+ it is not valid for streaming (see ZSTD_estimateCStreamSize*())
|
|
|
+ nor other potential ways of using a ZSTD_CCtx* state.
|
|
|
+
|
|
|
When srcSize can be bound by a known and rather "small" value,
|
|
|
- this fact can be used to provide a tighter estimation
|
|
|
- because the CCtx compression context will need less memory.
|
|
|
- This tighter estimation can be provided by more advanced functions
|
|
|
+ this knowledge can be used to provide a tighter budget estimation
|
|
|
+ because the ZSTD_CCtx* state will need less memory for small inputs.
|
|
|
+ This tighter estimation can be provided by employing more advanced functions
|
|
|
ZSTD_estimateCCtxSize_usingCParams(), which can be used in tandem with ZSTD_getCParams(),
|
|
|
and ZSTD_estimateCCtxSize_usingCCtxParams(), which can be used in tandem with ZSTD_CCtxParams_setParameter().
|
|
|
Both can be used to estimate memory using custom compression parameters and arbitrary srcSize limits.
|
|
|
|
|
|
Note : only single-threaded compression is supported.
|
|
|
ZSTD_estimateCCtxSize_usingCCtxParams() will return an error code if ZSTD_c_nbWorkers is >= 1.
|
|
|
-
|
|
|
- Note 2 : ZSTD_estimateCCtxSize* functions are not compatible with the Block-Level Sequence Producer API at this time.
|
|
|
- Size estimates assume that no external sequence producer is registered.
|
|
|
|
|
|
</p></pre><BR>
|
|
|
|
|
|
-<pre><b>ZSTDLIB_STATIC_API size_t ZSTD_estimateCStreamSize(int compressionLevel);
|
|
|
+<pre><b>ZSTDLIB_STATIC_API size_t ZSTD_estimateCStreamSize(int maxCompressionLevel);
|
|
|
ZSTDLIB_STATIC_API size_t ZSTD_estimateCStreamSize_usingCParams(ZSTD_compressionParameters cParams);
|
|
|
ZSTDLIB_STATIC_API size_t ZSTD_estimateCStreamSize_usingCCtxParams(const ZSTD_CCtx_params* params);
|
|
|
-ZSTDLIB_STATIC_API size_t ZSTD_estimateDStreamSize(size_t windowSize);
|
|
|
+ZSTDLIB_STATIC_API size_t ZSTD_estimateDStreamSize(size_t maxWindowSize);
|
|
|
ZSTDLIB_STATIC_API size_t ZSTD_estimateDStreamSize_fromFrame(const void* src, size_t srcSize);
|
|
|
-</b><p> ZSTD_estimateCStreamSize() will provide a budget large enough for any compression level up to selected one.
|
|
|
- It will also consider src size to be arbitrarily "large", which is worst case.
|
|
|
+</b><p> ZSTD_estimateCStreamSize() will provide a memory budget large enough for streaming compression
|
|
|
+ using any compression level up to the max specified one.
|
|
|
+ It will also consider src size to be arbitrarily "large", which is a worst case scenario.
|
|
|
If srcSize is known to always be small, ZSTD_estimateCStreamSize_usingCParams() can provide a tighter estimation.
|
|
|
ZSTD_estimateCStreamSize_usingCParams() can be used in tandem with ZSTD_getCParams() to create cParams from compressionLevel.
|
|
|
ZSTD_estimateCStreamSize_usingCCtxParams() can be used in tandem with ZSTD_CCtxParams_setParameter(). Only single-threaded compression is supported. This function will return an error code if ZSTD_c_nbWorkers is >= 1.
|
|
|
Note : CStream size estimation is only correct for single-threaded compression.
|
|
|
- ZSTD_DStream memory budget depends on window Size.
|
|
|
+ ZSTD_estimateCStreamSize_usingCCtxParams() will return an error code if ZSTD_c_nbWorkers is >= 1.
|
|
|
+ Note 2 : ZSTD_estimateCStreamSize* functions are not compatible with the Block-Level Sequence Producer API at this time.
|
|
|
+ Size estimates assume that no external sequence producer is registered.
|
|
|
+
|
|
|
+ ZSTD_DStream memory budget depends on frame's window Size.
|
|
|
This information can be passed manually, using ZSTD_estimateDStreamSize,
|
|
|
or deducted from a valid frame Header, using ZSTD_estimateDStreamSize_fromFrame();
|
|
|
+ Any frame requesting a window size larger than max specified one will be rejected.
|
|
|
Note : if streaming is init with function ZSTD_init?Stream_usingDict(),
|
|
|
an internal ?Dict will be created, which additional size is not estimated here.
|
|
|
In this case, get total size by adding ZSTD_estimate?DictSize
|
|
|
- Note 2 : only single-threaded compression is supported.
|
|
|
- ZSTD_estimateCStreamSize_usingCCtxParams() will return an error code if ZSTD_c_nbWorkers is >= 1.
|
|
|
- Note 3 : ZSTD_estimateCStreamSize* functions are not compatible with the Block-Level Sequence Producer API at this time.
|
|
|
- Size estimates assume that no external sequence producer is registered.
|
|
|
|
|
|
</p></pre><BR>
|
|
|
|
|
@@ -1483,13 +1578,14 @@ static
|
|
|
#ifdef __GNUC__
|
|
|
__attribute__((__unused__))
|
|
|
#endif
|
|
|
-ZSTD_customMem const ZSTD_defaultCMem = { NULL, NULL, NULL }; </b>/**< this constant defers to stdlib's functions */<b>
|
|
|
</b><p> These prototypes make it possible to pass your own allocation/free functions.
|
|
|
ZSTD_customMem is provided at creation time, using ZSTD_create*_advanced() variants listed below.
|
|
|
All allocation/free operations will be completed using these custom variants instead of regular <stdlib.h> ones.
|
|
|
|
|
|
</p></pre><BR>
|
|
|
|
|
|
+<pre><b>ZSTD_customMem const ZSTD_defaultCMem = { NULL, NULL, NULL }; </b>/**< this constant defers to stdlib's functions */<b>
|
|
|
+</b></pre><BR>
|
|
|
<pre><b>typedef struct POOL_ctx_s ZSTD_threadPool;
|
|
|
ZSTDLIB_STATIC_API ZSTD_threadPool* ZSTD_createThreadPool(size_t numThreads);
|
|
|
ZSTDLIB_STATIC_API void ZSTD_freeThreadPool (ZSTD_threadPool* pool); </b>/* accept NULL pointer */<b>
|
|
@@ -1857,7 +1953,7 @@ size_t ZSTD_resetCStream(ZSTD_CStream* zcs, unsigned long long pledgedSrcSize);
|
|
|
explicitly specified.
|
|
|
|
|
|
start a new frame, using same parameters from previous frame.
|
|
|
- This is typically useful to skip dictionary loading stage, since it will re-use it in-place.
|
|
|
+ This is typically useful to skip dictionary loading stage, since it will reuse it in-place.
|
|
|
Note that zcs must be init at least once before using ZSTD_resetCStream().
|
|
|
If pledgedSrcSize is not known at reset time, use macro ZSTD_CONTENTSIZE_UNKNOWN.
|
|
|
If pledgedSrcSize > 0, its value must be correct, as it will be written in header, and controlled at the end.
|
|
@@ -1918,7 +2014,7 @@ ZSTDLIB_STATIC_API size_t ZSTD_resetDStream(ZSTD_DStream* zds);
|
|
|
</b><p>
|
|
|
ZSTD_DCtx_reset(zds, ZSTD_reset_session_only);
|
|
|
|
|
|
- re-use decompression parameters from previous init; saves dictionary loading
|
|
|
+ reuse decompression parameters from previous init; saves dictionary loading
|
|
|
|
|
|
</p></pre><BR>
|
|
|
|
|
@@ -1926,7 +2022,7 @@ ZSTDLIB_STATIC_API size_t ZSTD_resetDStream(ZSTD_DStream* zds);
|
|
|
ZSTD_registerSequenceProducer(
|
|
|
ZSTD_CCtx* cctx,
|
|
|
void* sequenceProducerState,
|
|
|
- ZSTD_sequenceProducer_F* sequenceProducer
|
|
|
+ ZSTD_sequenceProducer_F sequenceProducer
|
|
|
);
|
|
|
</b><p> Instruct zstd to use a block-level external sequence producer function.
|
|
|
|
|
@@ -1948,6 +2044,22 @@ ZSTD_registerSequenceProducer(
|
|
|
calling this function.
|
|
|
</p></pre><BR>
|
|
|
|
|
|
+<pre><b>ZSTDLIB_STATIC_API void
|
|
|
+ZSTD_CCtxParams_registerSequenceProducer(
|
|
|
+ ZSTD_CCtx_params* params,
|
|
|
+ void* sequenceProducerState,
|
|
|
+ ZSTD_sequenceProducer_F sequenceProducer
|
|
|
+);
|
|
|
+</b><p> Same as ZSTD_registerSequenceProducer(), but operates on ZSTD_CCtx_params.
|
|
|
+ This is used for accurate size estimation with ZSTD_estimateCCtxSize_usingCCtxParams(),
|
|
|
+ which is needed when creating a ZSTD_CCtx with ZSTD_initStaticCCtx().
|
|
|
+
|
|
|
+ If you are using the external sequence producer API in a scenario where ZSTD_initStaticCCtx()
|
|
|
+ is required, then this function is for you. Otherwise, you probably don't need it.
|
|
|
+
|
|
|
+ See tests/zstreamtest.c for example usage.
|
|
|
+</p></pre><BR>
|
|
|
+
|
|
|
<a name="Chapter20"></a><h2>Buffer-less and synchronous inner streaming functions (DEPRECATED)</h2><pre>
|
|
|
This API is deprecated, and will be removed in a future version.
|
|
|
It allows streaming (de)compression with user allocated buffers.
|
|
@@ -1964,7 +2076,7 @@ ZSTD_registerSequenceProducer(
|
|
|
<a name="Chapter21"></a><h2>Buffer-less streaming compression (synchronous mode)</h2><pre>
|
|
|
A ZSTD_CCtx object is required to track streaming operations.
|
|
|
Use ZSTD_createCCtx() / ZSTD_freeCCtx() to manage resource.
|
|
|
- ZSTD_CCtx object can be re-used multiple times within successive compression operations.
|
|
|
+ ZSTD_CCtx object can be reused multiple times within successive compression operations.
|
|
|
|
|
|
Start by initializing a context.
|
|
|
Use ZSTD_compressBegin(), or ZSTD_compressBegin_usingDict() for dictionary compression.
|
|
@@ -1985,7 +2097,7 @@ ZSTD_registerSequenceProducer(
|
|
|
It's possible to use srcSize==0, in which case, it will write a final empty block to end the frame.
|
|
|
Without last block mark, frames are considered unfinished (hence corrupted) by compliant decoders.
|
|
|
|
|
|
- `ZSTD_CCtx` object can be re-used (ZSTD_compressBegin()) to compress again.
|
|
|
+ `ZSTD_CCtx` object can be reused (ZSTD_compressBegin()) to compress again.
|
|
|
<BR></pre>
|
|
|
|
|
|
<h3>Buffer-less streaming compression functions</h3><pre></pre><b><pre>ZSTD_DEPRECATED("The buffer-less API is deprecated in favor of the normal streaming API. See docs.")
|
|
@@ -2002,7 +2114,7 @@ ZSTDLIB_STATIC_API size_t ZSTD_compressBegin_usingCDict(ZSTD_CCtx* cctx, const Z
|
|
|
<a name="Chapter22"></a><h2>Buffer-less streaming decompression (synchronous mode)</h2><pre>
|
|
|
A ZSTD_DCtx object is required to track streaming operations.
|
|
|
Use ZSTD_createDCtx() / ZSTD_freeDCtx() to manage it.
|
|
|
- A ZSTD_DCtx object can be re-used multiple times.
|
|
|
+ A ZSTD_DCtx object can be reused multiple times.
|
|
|
|
|
|
First typical operation is to retrieve frame parameters, using ZSTD_getFrameHeader().
|
|
|
Frame header is extracted from the beginning of compressed frame, so providing only the frame's beginning is enough.
|
|
@@ -2012,7 +2124,7 @@ ZSTDLIB_STATIC_API size_t ZSTD_compressBegin_usingCDict(ZSTD_CCtx* cctx, const Z
|
|
|
>0 : `srcSize` is too small, please provide at least result bytes on next attempt.
|
|
|
errorCode, which can be tested using ZSTD_isError().
|
|
|
|
|
|
- It fills a ZSTD_frameHeader structure with important information to correctly decode the frame,
|
|
|
+ It fills a ZSTD_FrameHeader structure with important information to correctly decode the frame,
|
|
|
such as the dictionary ID, content size, or maximum back-reference distance (`windowSize`).
|
|
|
Note that these values could be wrong, either because of data corruption, or because a 3rd party deliberately spoofs false information.
|
|
|
As a consequence, check that values remain within valid application range.
|