ReactOS 0.4.15-dev-8207-gd73a838
zstd.h File Reference
#include <limits.h>
#include <stddef.h>
Include dependency graph for zstd.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  ZSTD_bounds
 
struct  ZSTD_inBuffer_s
 
struct  ZSTD_outBuffer_s
 

Macros

#define ZSTD_H_235446
 
#define ZSTDLIB_VISIBILITY
 
#define ZSTDLIB_API   ZSTDLIB_VISIBILITY
 
#define ZSTD_VERSION_MAJOR   1
 
#define ZSTD_VERSION_MINOR   4
 
#define ZSTD_VERSION_RELEASE   5
 
#define ZSTD_VERSION_NUMBER   (ZSTD_VERSION_MAJOR *100*100 + ZSTD_VERSION_MINOR *100 + ZSTD_VERSION_RELEASE)
 
#define ZSTD_LIB_VERSION   ZSTD_VERSION_MAJOR.ZSTD_VERSION_MINOR.ZSTD_VERSION_RELEASE
 
#define ZSTD_QUOTE(str)   #str
 
#define ZSTD_EXPAND_AND_QUOTE(str)   ZSTD_QUOTE(str)
 
#define ZSTD_VERSION_STRING   ZSTD_EXPAND_AND_QUOTE(ZSTD_LIB_VERSION)
 
#define ZSTD_CLEVEL_DEFAULT   3
 
#define ZSTD_MAGICNUMBER   0xFD2FB528 /* valid since v0.8.0 */
 
#define ZSTD_MAGIC_DICTIONARY   0xEC30A437 /* valid since v0.7.0 */
 
#define ZSTD_MAGIC_SKIPPABLE_START   0x184D2A50 /* all 16 values, from 0x184D2A50 to 0x184D2A5F, signal the beginning of a skippable frame */
 
#define ZSTD_MAGIC_SKIPPABLE_MASK   0xFFFFFFF0
 
#define ZSTD_BLOCKSIZELOG_MAX   17
 
#define ZSTD_BLOCKSIZE_MAX   (1<<ZSTD_BLOCKSIZELOG_MAX)
 
#define ZSTD_CONTENTSIZE_UNKNOWN   (0ULL - 1)
 
#define ZSTD_CONTENTSIZE_ERROR   (0ULL - 2)
 
#define ZSTD_COMPRESSBOUND(srcSize)   ((srcSize) + ((srcSize)>>8) + (((srcSize) < (128<<10)) ? (((128<<10) - (srcSize)) >> 11) /* 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 */
 

Typedefs

typedef struct ZSTD_CCtx_s ZSTD_CCtx
 
typedef struct ZSTD_DCtx_s ZSTD_DCtx
 
typedef struct ZSTD_inBuffer_s ZSTD_inBuffer
 
typedef struct ZSTD_outBuffer_s ZSTD_outBuffer
 
typedef ZSTD_CCtx ZSTD_CStream
 
typedef ZSTD_DCtx ZSTD_DStream
 
typedef struct ZSTD_CDict_s ZSTD_CDict
 
typedef struct ZSTD_DDict_s ZSTD_DDict
 

Enumerations

enum  ZSTD_strategy {
  ZSTD_fast =1 , ZSTD_dfast =2 , ZSTD_greedy =3 , ZSTD_lazy =4 ,
  ZSTD_lazy2 =5 , ZSTD_btlazy2 =6 , ZSTD_btopt =7 , ZSTD_btultra =8 ,
  ZSTD_btultra2 =9
}
 
enum  ZSTD_cParameter {
  ZSTD_c_compressionLevel =100 , ZSTD_c_windowLog =101 , ZSTD_c_hashLog =102 , ZSTD_c_chainLog =103 ,
  ZSTD_c_searchLog =104 , ZSTD_c_minMatch =105 , ZSTD_c_targetLength =106 , ZSTD_c_strategy =107 ,
  ZSTD_c_enableLongDistanceMatching =160 , ZSTD_c_ldmHashLog =161 , ZSTD_c_ldmMinMatch =162 , ZSTD_c_ldmBucketSizeLog =163 ,
  ZSTD_c_ldmHashRateLog =164 , ZSTD_c_contentSizeFlag =200 , ZSTD_c_checksumFlag =201 , ZSTD_c_dictIDFlag =202 ,
  ZSTD_c_nbWorkers =400 , ZSTD_c_jobSize =401 , ZSTD_c_overlapLog =402 , ZSTD_c_experimentalParam1 =500 ,
  ZSTD_c_experimentalParam2 =10 , ZSTD_c_experimentalParam3 =1000 , ZSTD_c_experimentalParam4 =1001 , ZSTD_c_experimentalParam5 =1002 ,
  ZSTD_c_experimentalParam6 =1003 , ZSTD_c_experimentalParam7 =1004
}
 
enum  ZSTD_ResetDirective { ZSTD_reset_session_only = 1 , ZSTD_reset_parameters = 2 , ZSTD_reset_session_and_parameters = 3 }
 
enum  ZSTD_dParameter { ZSTD_d_windowLogMax =100 , ZSTD_d_experimentalParam1 =1000 , ZSTD_d_experimentalParam2 =1001 }
 
enum  ZSTD_EndDirective { ZSTD_e_continue =0 , ZSTD_e_flush =1 , ZSTD_e_end =2 }
 

Functions

ZSTDLIB_API unsigned ZSTD_versionNumber (void)
 
ZSTDLIB_API const charZSTD_versionString (void)
 
ZSTDLIB_API size_t ZSTD_compress (void *dst, size_t dstCapacity, const void *src, size_t srcSize, int compressionLevel)
 
ZSTDLIB_API size_t ZSTD_decompress (void *dst, size_t dstCapacity, const void *src, size_t compressedSize)
 
ZSTDLIB_API unsigned long long ZSTD_getFrameContentSize (const void *src, size_t srcSize)
 
ZSTDLIB_API unsigned long long ZSTD_getDecompressedSize (const void *src, size_t srcSize)
 
ZSTDLIB_API size_t ZSTD_findFrameCompressedSize (const void *src, size_t srcSize)
 
ZSTDLIB_API size_t ZSTD_compressBound (size_t srcSize)
 
ZSTDLIB_API unsigned ZSTD_isError (size_t code)
 
ZSTDLIB_API const charZSTD_getErrorName (size_t code)
 
ZSTDLIB_API int ZSTD_minCLevel (void)
 
ZSTDLIB_API int ZSTD_maxCLevel (void)
 
ZSTDLIB_API ZSTD_CCtxZSTD_createCCtx (void)
 
ZSTDLIB_API size_t ZSTD_freeCCtx (ZSTD_CCtx *cctx)
 
ZSTDLIB_API size_t ZSTD_compressCCtx (ZSTD_CCtx *cctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, int compressionLevel)
 
ZSTDLIB_API ZSTD_DCtxZSTD_createDCtx (void)
 
ZSTDLIB_API size_t ZSTD_freeDCtx (ZSTD_DCtx *dctx)
 
ZSTDLIB_API size_t ZSTD_decompressDCtx (ZSTD_DCtx *dctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize)
 
ZSTDLIB_API ZSTD_bounds ZSTD_cParam_getBounds (ZSTD_cParameter cParam)
 
ZSTDLIB_API size_t ZSTD_CCtx_setParameter (ZSTD_CCtx *cctx, ZSTD_cParameter param, int value)
 
ZSTDLIB_API size_t ZSTD_CCtx_setPledgedSrcSize (ZSTD_CCtx *cctx, unsigned long long pledgedSrcSize)
 
ZSTDLIB_API size_t ZSTD_CCtx_reset (ZSTD_CCtx *cctx, ZSTD_ResetDirective reset)
 
ZSTDLIB_API size_t ZSTD_compress2 (ZSTD_CCtx *cctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize)
 
ZSTDLIB_API ZSTD_bounds ZSTD_dParam_getBounds (ZSTD_dParameter dParam)
 
ZSTDLIB_API size_t ZSTD_DCtx_setParameter (ZSTD_DCtx *dctx, ZSTD_dParameter param, int value)
 
ZSTDLIB_API size_t ZSTD_DCtx_reset (ZSTD_DCtx *dctx, ZSTD_ResetDirective reset)
 
ZSTDLIB_API ZSTD_CStreamZSTD_createCStream (void)
 
ZSTDLIB_API size_t ZSTD_freeCStream (ZSTD_CStream *zcs)
 
ZSTDLIB_API size_t ZSTD_compressStream2 (ZSTD_CCtx *cctx, ZSTD_outBuffer *output, ZSTD_inBuffer *input, ZSTD_EndDirective endOp)
 
ZSTDLIB_API size_t ZSTD_CStreamInSize (void)
 
ZSTDLIB_API size_t ZSTD_CStreamOutSize (void)
 
ZSTDLIB_API size_t ZSTD_initCStream (ZSTD_CStream *zcs, int compressionLevel)
 
ZSTDLIB_API size_t ZSTD_compressStream (ZSTD_CStream *zcs, ZSTD_outBuffer *output, ZSTD_inBuffer *input)
 
ZSTDLIB_API size_t ZSTD_flushStream (ZSTD_CStream *zcs, ZSTD_outBuffer *output)
 
ZSTDLIB_API size_t ZSTD_endStream (ZSTD_CStream *zcs, ZSTD_outBuffer *output)
 
ZSTDLIB_API ZSTD_DStreamZSTD_createDStream (void)
 
ZSTDLIB_API size_t ZSTD_freeDStream (ZSTD_DStream *zds)
 
ZSTDLIB_API size_t ZSTD_initDStream (ZSTD_DStream *zds)
 
ZSTDLIB_API size_t ZSTD_decompressStream (ZSTD_DStream *zds, ZSTD_outBuffer *output, ZSTD_inBuffer *input)
 
ZSTDLIB_API size_t ZSTD_DStreamInSize (void)
 
ZSTDLIB_API size_t ZSTD_DStreamOutSize (void)
 
ZSTDLIB_API size_t ZSTD_compress_usingDict (ZSTD_CCtx *ctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, const void *dict, size_t dictSize, int compressionLevel)
 
ZSTDLIB_API size_t ZSTD_decompress_usingDict (ZSTD_DCtx *dctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, const void *dict, size_t dictSize)
 
ZSTDLIB_API ZSTD_CDictZSTD_createCDict (const void *dictBuffer, size_t dictSize, int compressionLevel)
 
ZSTDLIB_API size_t ZSTD_freeCDict (ZSTD_CDict *CDict)
 
ZSTDLIB_API size_t ZSTD_compress_usingCDict (ZSTD_CCtx *cctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, const ZSTD_CDict *cdict)
 
ZSTDLIB_API ZSTD_DDictZSTD_createDDict (const void *dictBuffer, size_t dictSize)
 
ZSTDLIB_API size_t ZSTD_freeDDict (ZSTD_DDict *ddict)
 
ZSTDLIB_API size_t ZSTD_decompress_usingDDict (ZSTD_DCtx *dctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, const ZSTD_DDict *ddict)
 
ZSTDLIB_API unsigned ZSTD_getDictID_fromDict (const void *dict, size_t dictSize)
 
ZSTDLIB_API unsigned ZSTD_getDictID_fromDDict (const ZSTD_DDict *ddict)
 
ZSTDLIB_API unsigned ZSTD_getDictID_fromFrame (const void *src, size_t srcSize)
 
ZSTDLIB_API size_t ZSTD_CCtx_loadDictionary (ZSTD_CCtx *cctx, const void *dict, size_t dictSize)
 
ZSTDLIB_API size_t ZSTD_CCtx_refCDict (ZSTD_CCtx *cctx, const ZSTD_CDict *cdict)
 
ZSTDLIB_API size_t ZSTD_CCtx_refPrefix (ZSTD_CCtx *cctx, const void *prefix, size_t prefixSize)
 
ZSTDLIB_API size_t ZSTD_DCtx_loadDictionary (ZSTD_DCtx *dctx, const void *dict, size_t dictSize)
 
ZSTDLIB_API size_t ZSTD_DCtx_refDDict (ZSTD_DCtx *dctx, const ZSTD_DDict *ddict)
 
ZSTDLIB_API size_t ZSTD_DCtx_refPrefix (ZSTD_DCtx *dctx, const void *prefix, size_t prefixSize)
 
ZSTDLIB_API size_t ZSTD_sizeof_CCtx (const ZSTD_CCtx *cctx)
 
ZSTDLIB_API size_t ZSTD_sizeof_DCtx (const ZSTD_DCtx *dctx)
 
ZSTDLIB_API size_t ZSTD_sizeof_CStream (const ZSTD_CStream *zcs)
 
ZSTDLIB_API size_t ZSTD_sizeof_DStream (const ZSTD_DStream *zds)
 
ZSTDLIB_API size_t ZSTD_sizeof_CDict (const ZSTD_CDict *cdict)
 
ZSTDLIB_API size_t ZSTD_sizeof_DDict (const ZSTD_DDict *ddict)
 

Macro Definition Documentation

◆ ZSTD_BLOCKSIZE_MAX

#define ZSTD_BLOCKSIZE_MAX   (1<<ZSTD_BLOCKSIZELOG_MAX)

Definition at line 104 of file zstd.h.

◆ ZSTD_BLOCKSIZELOG_MAX

#define ZSTD_BLOCKSIZELOG_MAX   17

Definition at line 103 of file zstd.h.

◆ ZSTD_CLEVEL_DEFAULT

#define ZSTD_CLEVEL_DEFAULT   3

Definition at line 90 of file zstd.h.

◆ ZSTD_COMPRESSBOUND

#define ZSTD_COMPRESSBOUND (   srcSize)    ((srcSize) + ((srcSize)>>8) + (((srcSize) < (128<<10)) ? (((128<<10) - (srcSize)) >> 11) /* 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 */

Definition at line 174 of file zstd.h.

◆ ZSTD_CONTENTSIZE_ERROR

#define ZSTD_CONTENTSIZE_ERROR   (0ULL - 2)

Definition at line 153 of file zstd.h.

◆ ZSTD_CONTENTSIZE_UNKNOWN

#define ZSTD_CONTENTSIZE_UNKNOWN   (0ULL - 1)

ZSTD_getFrameContentSize() : requires v1.3.0+ 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.

Returns
: - 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()

Definition at line 152 of file zstd.h.

◆ ZSTD_EXPAND_AND_QUOTE

#define ZSTD_EXPAND_AND_QUOTE (   str)    ZSTD_QUOTE(str)

Definition at line 82 of file zstd.h.

◆ ZSTD_H_235446

#define ZSTD_H_235446

Definition at line 15 of file zstd.h.

◆ ZSTD_LIB_VERSION

Definition at line 80 of file zstd.h.

◆ ZSTD_MAGIC_DICTIONARY

#define ZSTD_MAGIC_DICTIONARY   0xEC30A437 /* valid since v0.7.0 */

Definition at line 99 of file zstd.h.

◆ ZSTD_MAGIC_SKIPPABLE_MASK

#define ZSTD_MAGIC_SKIPPABLE_MASK   0xFFFFFFF0

Definition at line 101 of file zstd.h.

◆ ZSTD_MAGIC_SKIPPABLE_START

#define ZSTD_MAGIC_SKIPPABLE_START   0x184D2A50 /* all 16 values, from 0x184D2A50 to 0x184D2A5F, signal the beginning of a skippable frame */

Definition at line 100 of file zstd.h.

◆ ZSTD_MAGICNUMBER

#define ZSTD_MAGICNUMBER   0xFD2FB528 /* valid since v0.8.0 */

Definition at line 98 of file zstd.h.

◆ ZSTD_QUOTE

#define ZSTD_QUOTE (   str)    #str

Definition at line 81 of file zstd.h.

◆ ZSTD_VERSION_MAJOR

#define ZSTD_VERSION_MAJOR   1

Definition at line 73 of file zstd.h.

◆ ZSTD_VERSION_MINOR

#define ZSTD_VERSION_MINOR   4

Definition at line 74 of file zstd.h.

◆ ZSTD_VERSION_NUMBER

#define ZSTD_VERSION_NUMBER   (ZSTD_VERSION_MAJOR *100*100 + ZSTD_VERSION_MINOR *100 + ZSTD_VERSION_RELEASE)

Definition at line 77 of file zstd.h.

◆ ZSTD_VERSION_RELEASE

#define ZSTD_VERSION_RELEASE   5

Definition at line 75 of file zstd.h.

◆ ZSTD_VERSION_STRING

#define ZSTD_VERSION_STRING   ZSTD_EXPAND_AND_QUOTE(ZSTD_LIB_VERSION)

Definition at line 83 of file zstd.h.

◆ ZSTDLIB_API

#define ZSTDLIB_API   ZSTDLIB_VISIBILITY

Definition at line 35 of file zstd.h.

◆ ZSTDLIB_VISIBILITY

#define ZSTDLIB_VISIBILITY

Definition at line 27 of file zstd.h.

Typedef Documentation

◆ ZSTD_CCtx

Definition at line 195 of file zstd.h.

◆ ZSTD_CDict

Definition at line 813 of file zstd.h.

◆ ZSTD_CStream

CCtx and CStream are now effectively same object (>= v1.3.0)

Definition at line 641 of file zstd.h.

◆ ZSTD_DCtx

Definition at line 218 of file zstd.h.

◆ ZSTD_DDict

Definition at line 845 of file zstd.h.

◆ ZSTD_DStream

DCtx and DStream are now effectively same object (>= v1.3.0)

Definition at line 761 of file zstd.h.

◆ ZSTD_inBuffer

◆ ZSTD_outBuffer

Enumeration Type Documentation

◆ ZSTD_cParameter

Enumerator
ZSTD_c_compressionLevel 
ZSTD_c_windowLog 
ZSTD_c_hashLog 
ZSTD_c_chainLog 
ZSTD_c_searchLog 
ZSTD_c_minMatch 
ZSTD_c_targetLength 
ZSTD_c_strategy 
ZSTD_c_enableLongDistanceMatching 
ZSTD_c_ldmHashLog 
ZSTD_c_ldmMinMatch 
ZSTD_c_ldmBucketSizeLog 
ZSTD_c_ldmHashRateLog 
ZSTD_c_contentSizeFlag 
ZSTD_c_checksumFlag 
ZSTD_c_dictIDFlag 
ZSTD_c_nbWorkers 
ZSTD_c_jobSize 
ZSTD_c_overlapLog 
ZSTD_c_experimentalParam1 
ZSTD_c_experimentalParam2 
ZSTD_c_experimentalParam3 
ZSTD_c_experimentalParam4 
ZSTD_c_experimentalParam5 
ZSTD_c_experimentalParam6 
ZSTD_c_experimentalParam7 

Definition at line 265 of file zstd.h.

265 {
266
267 /* compression parameters
268 * Note: When compressing with a ZSTD_CDict these parameters are superseded
269 * by the parameters used to construct the ZSTD_CDict.
270 * See ZSTD_CCtx_refCDict() for more info (superseded-by-cdict). */
271 ZSTD_c_compressionLevel=100, /* Set compression parameters according to pre-defined cLevel table.
272 * Note that exact compression parameters are dynamically determined,
273 * depending on both compression level and srcSize (when known).
274 * Default level is ZSTD_CLEVEL_DEFAULT==3.
275 * Special: value 0 means default, which is controlled by ZSTD_CLEVEL_DEFAULT.
276 * Note 1 : it's possible to pass a negative compression level.
277 * Note 2 : setting a level does not automatically set all other compression parameters
278 * to default. Setting this will however eventually dynamically impact the compression
279 * parameters which have not been manually set. The manually set
280 * ones will 'stick'. */
281 /* Advanced compression parameters :
282 * It's possible to pin down compression parameters to some specific values.
283 * In which case, these values are no longer dynamically selected by the compressor */
284 ZSTD_c_windowLog=101, /* Maximum allowed back-reference distance, expressed as power of 2.
285 * This will set a memory budget for streaming decompression,
286 * with larger values requiring more memory
287 * and typically compressing more.
288 * Must be clamped between ZSTD_WINDOWLOG_MIN and ZSTD_WINDOWLOG_MAX.
289 * Special: value 0 means "use default windowLog".
290 * Note: Using a windowLog greater than ZSTD_WINDOWLOG_LIMIT_DEFAULT
291 * requires explicitly allowing such size at streaming decompression stage. */
292 ZSTD_c_hashLog=102, /* Size of the initial probe table, as a power of 2.
293 * Resulting memory usage is (1 << (hashLog+2)).
294 * Must be clamped between ZSTD_HASHLOG_MIN and ZSTD_HASHLOG_MAX.
295 * Larger tables improve compression ratio of strategies <= dFast,
296 * and improve speed of strategies > dFast.
297 * Special: value 0 means "use default hashLog". */
298 ZSTD_c_chainLog=103, /* Size of the multi-probe search table, as a power of 2.
299 * Resulting memory usage is (1 << (chainLog+2)).
300 * Must be clamped between ZSTD_CHAINLOG_MIN and ZSTD_CHAINLOG_MAX.
301 * Larger tables result in better and slower compression.
302 * This parameter is useless for "fast" strategy.
303 * It's still useful when using "dfast" strategy,
304 * in which case it defines a secondary probe table.
305 * Special: value 0 means "use default chainLog". */
306 ZSTD_c_searchLog=104, /* Number of search attempts, as a power of 2.
307 * More attempts result in better and slower compression.
308 * This parameter is useless for "fast" and "dFast" strategies.
309 * Special: value 0 means "use default searchLog". */
310 ZSTD_c_minMatch=105, /* Minimum size of searched matches.
311 * Note that Zstandard can still find matches of smaller size,
312 * it just tweaks its search algorithm to look for this size and larger.
313 * Larger values increase compression and decompression speed, but decrease ratio.
314 * Must be clamped between ZSTD_MINMATCH_MIN and ZSTD_MINMATCH_MAX.
315 * Note that currently, for all strategies < btopt, effective minimum is 4.
316 * , for all strategies > fast, effective maximum is 6.
317 * Special: value 0 means "use default minMatchLength". */
318 ZSTD_c_targetLength=106, /* Impact of this field depends on strategy.
319 * For strategies btopt, btultra & btultra2:
320 * Length of Match considered "good enough" to stop search.
321 * Larger values make compression stronger, and slower.
322 * For strategy fast:
323 * Distance between match sampling.
324 * Larger values make compression faster, and weaker.
325 * Special: value 0 means "use default targetLength". */
326 ZSTD_c_strategy=107, /* See ZSTD_strategy enum definition.
327 * The higher the value of selected strategy, the more complex it is,
328 * resulting in stronger and slower compression.
329 * Special: value 0 means "use default strategy". */
330
331 /* LDM mode parameters */
332 ZSTD_c_enableLongDistanceMatching=160, /* Enable long distance matching.
333 * This parameter is designed to improve compression ratio
334 * for large inputs, by finding large matches at long distance.
335 * It increases memory usage and window size.
336 * Note: enabling this parameter increases default ZSTD_c_windowLog to 128 MB
337 * except when expressly set to a different value. */
338 ZSTD_c_ldmHashLog=161, /* Size of the table for long distance matching, as a power of 2.
339 * Larger values increase memory usage and compression ratio,
340 * but decrease compression speed.
341 * Must be clamped between ZSTD_HASHLOG_MIN and ZSTD_HASHLOG_MAX
342 * default: windowlog - 7.
343 * Special: value 0 means "automatically determine hashlog". */
344 ZSTD_c_ldmMinMatch=162, /* Minimum match size for long distance matcher.
345 * Larger/too small values usually decrease compression ratio.
346 * Must be clamped between ZSTD_LDM_MINMATCH_MIN and ZSTD_LDM_MINMATCH_MAX.
347 * Special: value 0 means "use default value" (default: 64). */
348 ZSTD_c_ldmBucketSizeLog=163, /* Log size of each bucket in the LDM hash table for collision resolution.
349 * Larger values improve collision resolution but decrease compression speed.
350 * The maximum value is ZSTD_LDM_BUCKETSIZELOG_MAX.
351 * Special: value 0 means "use default value" (default: 3). */
352 ZSTD_c_ldmHashRateLog=164, /* Frequency of inserting/looking up entries into the LDM hash table.
353 * Must be clamped between 0 and (ZSTD_WINDOWLOG_MAX - ZSTD_HASHLOG_MIN).
354 * Default is MAX(0, (windowLog - ldmHashLog)), optimizing hash table usage.
355 * Larger values improve compression speed.
356 * Deviating far from default value will likely result in a compression ratio decrease.
357 * Special: value 0 means "automatically determine hashRateLog". */
358
359 /* frame parameters */
360 ZSTD_c_contentSizeFlag=200, /* Content size will be written into frame header _whenever known_ (default:1)
361 * Content size must be known at the beginning of compression.
362 * This is automatically the case when using ZSTD_compress2(),
363 * For streaming scenarios, content size must be provided with ZSTD_CCtx_setPledgedSrcSize() */
364 ZSTD_c_checksumFlag=201, /* A 32-bits checksum of content is written at end of frame (default:0) */
365 ZSTD_c_dictIDFlag=202, /* When applicable, dictionary's ID is written into frame header (default:1) */
366
367 /* multi-threading parameters */
368 /* These parameters are only useful if multi-threading is enabled (compiled with build macro ZSTD_MULTITHREAD).
369 * They return an error otherwise. */
370 ZSTD_c_nbWorkers=400, /* Select how many threads will be spawned to compress in parallel.
371 * When nbWorkers >= 1, triggers asynchronous mode when used with ZSTD_compressStream*() :
372 * ZSTD_compressStream*() consumes input and flush output if possible, but immediately gives back control to caller,
373 * while compression work is performed in parallel, within worker threads.
374 * (note : a strong exception to this rule is when first invocation of ZSTD_compressStream2() sets ZSTD_e_end :
375 * in which case, ZSTD_compressStream2() delegates to ZSTD_compress2(), which is always a blocking call).
376 * More workers improve speed, but also increase memory usage.
377 * Default value is `0`, aka "single-threaded mode" : no worker is spawned, compression is performed inside Caller's thread, all invocations are blocking */
378 ZSTD_c_jobSize=401, /* Size of a compression job. This value is enforced only when nbWorkers >= 1.
379 * Each compression job is completed in parallel, so this value can indirectly impact the nb of active threads.
380 * 0 means default, which is dynamically determined based on compression parameters.
381 * Job size must be a minimum of overlap size, or 1 MB, whichever is largest.
382 * The minimum size is automatically and transparently enforced. */
383 ZSTD_c_overlapLog=402, /* Control the overlap size, as a fraction of window size.
384 * The overlap size is an amount of data reloaded from previous job at the beginning of a new job.
385 * It helps preserve compression ratio, while each job is compressed in parallel.
386 * This value is enforced only when nbWorkers >= 1.
387 * Larger values increase compression ratio, but decrease speed.
388 * Possible values range from 0 to 9 :
389 * - 0 means "default" : value will be determined by the library, depending on strategy
390 * - 1 means "no overlap"
391 * - 9 means "full overlap", using a full window size.
392 * Each intermediate rank increases/decreases load size by a factor 2 :
393 * 9: full window; 8: w/2; 7: w/4; 6: w/8; 5:w/16; 4: w/32; 3:w/64; 2:w/128; 1:no overlap; 0:default
394 * default value varies between 6 and 9, depending on strategy */
395
396 /* note : additional experimental parameters are also available
397 * within the experimental section of the API.
398 * At the time of this writing, they include :
399 * ZSTD_c_rsyncable
400 * ZSTD_c_format
401 * ZSTD_c_forceMaxWindow
402 * ZSTD_c_forceAttachDict
403 * ZSTD_c_literalCompressionMode
404 * ZSTD_c_targetCBlockSize
405 * ZSTD_c_srcSizeHint
406 * Because they are not stable, it's necessary to define ZSTD_STATIC_LINKING_ONLY to access them.
407 * note : never ever use experimentalParam? names directly;
408 * also, the enums values themselves are unstable and can still change.
409 */
ZSTD_cParameter
Definition: zstd.h:265
@ ZSTD_c_ldmHashRateLog
Definition: zstd.h:352
@ ZSTD_c_checksumFlag
Definition: zstd.h:364
@ ZSTD_c_ldmHashLog
Definition: zstd.h:338
@ ZSTD_c_experimentalParam2
Definition: zstd.h:411
@ ZSTD_c_jobSize
Definition: zstd.h:378
@ ZSTD_c_chainLog
Definition: zstd.h:298
@ ZSTD_c_hashLog
Definition: zstd.h:292
@ ZSTD_c_dictIDFlag
Definition: zstd.h:365
@ ZSTD_c_strategy
Definition: zstd.h:326
@ ZSTD_c_windowLog
Definition: zstd.h:284
@ ZSTD_c_experimentalParam4
Definition: zstd.h:413
@ ZSTD_c_experimentalParam1
Definition: zstd.h:410
@ ZSTD_c_experimentalParam3
Definition: zstd.h:412
@ ZSTD_c_contentSizeFlag
Definition: zstd.h:360
@ ZSTD_c_overlapLog
Definition: zstd.h:383
@ ZSTD_c_enableLongDistanceMatching
Definition: zstd.h:332
@ ZSTD_c_searchLog
Definition: zstd.h:306
@ ZSTD_c_compressionLevel
Definition: zstd.h:271
@ ZSTD_c_targetLength
Definition: zstd.h:318
@ ZSTD_c_minMatch
Definition: zstd.h:310
@ ZSTD_c_nbWorkers
Definition: zstd.h:370
@ ZSTD_c_experimentalParam5
Definition: zstd.h:414
@ ZSTD_c_experimentalParam6
Definition: zstd.h:415
@ ZSTD_c_ldmBucketSizeLog
Definition: zstd.h:348
@ ZSTD_c_experimentalParam7
Definition: zstd.h:416
@ ZSTD_c_ldmMinMatch
Definition: zstd.h:344

◆ ZSTD_dParameter

Enumerator
ZSTD_d_windowLogMax 
ZSTD_d_experimentalParam1 
ZSTD_d_experimentalParam2 

Definition at line 513 of file zstd.h.

513 {
514
515 ZSTD_d_windowLogMax=100, /* Select a size limit (in power of 2) beyond which
516 * the streaming API will refuse to allocate memory buffer
517 * in order to protect the host from unreasonable memory requirements.
518 * This parameter is only useful in streaming mode, since no internal buffer is allocated in single-pass mode.
519 * By default, a decompression context accepts window sizes <= (1 << ZSTD_WINDOWLOG_LIMIT_DEFAULT).
520 * Special: value 0 means "use default maximum windowLog". */
521
522 /* note : additional experimental parameters are also available
523 * within the experimental section of the API.
524 * At the time of this writing, they include :
525 * ZSTD_d_format
526 * ZSTD_d_stableOutBuffer
527 * Because they are not stable, it's necessary to define ZSTD_STATIC_LINKING_ONLY to access them.
528 * note : never ever use experimentalParam? names directly
529 */
532
ZSTD_dParameter
Definition: zstd.h:513
@ ZSTD_d_experimentalParam1
Definition: zstd.h:530
@ ZSTD_d_windowLogMax
Definition: zstd.h:515
@ ZSTD_d_experimentalParam2
Definition: zstd.h:531

◆ ZSTD_EndDirective

Enumerator
ZSTD_e_continue 
ZSTD_e_flush 
ZSTD_e_end 

Definition at line 648 of file zstd.h.

648 {
649 ZSTD_e_continue=0, /* collect more data, encoder decides when to output compressed result, for optimal compression ratio */
650 ZSTD_e_flush=1, /* flush any data provided so far,
651 * it creates (at least) one new block, that can be decoded immediately on reception;
652 * frame will continue: any future data can still reference previously compressed data, improving compression.
653 * note : multithreaded compression will block to flush as much output as possible. */
654 ZSTD_e_end=2 /* flush any remaining data _and_ close current frame.
655 * note that frame is only closed after compressed data is fully flushed (return value == 0).
656 * After that point, any additional data starts a new frame.
657 * note : each frame is independent (does not reference any content from previous frame).
658 : note : multithreaded compression will block to flush as much output as possible. */
ZSTD_EndDirective
Definition: zstd.h:648
@ ZSTD_e_flush
Definition: zstd.h:650
@ ZSTD_e_continue
Definition: zstd.h:649
@ ZSTD_e_end
Definition: zstd.h:654

◆ ZSTD_ResetDirective

Enumerator
ZSTD_reset_session_only 
ZSTD_reset_parameters 
ZSTD_reset_session_and_parameters 

Definition at line 464 of file zstd.h.

464 {
ZSTD_ResetDirective
Definition: zstd.h:464
@ ZSTD_reset_session_only
Definition: zstd.h:465
@ ZSTD_reset_parameters
Definition: zstd.h:466
@ ZSTD_reset_session_and_parameters
Definition: zstd.h:467

◆ ZSTD_strategy

Enumerator
ZSTD_fast 
ZSTD_dfast 
ZSTD_greedy 
ZSTD_lazy 
ZSTD_lazy2 
ZSTD_btlazy2 
ZSTD_btopt 
ZSTD_btultra 
ZSTD_btultra2 

Definition at line 251 of file zstd.h.

251 { ZSTD_fast=1,
252 ZSTD_dfast=2,
253 ZSTD_greedy=3,
254 ZSTD_lazy=4,
255 ZSTD_lazy2=5,
256 ZSTD_btlazy2=6,
257 ZSTD_btopt=7,
258 ZSTD_btultra=8,
260 /* note : new strategies _might_ be added in the future.
261 Only the order (from fast to strong) is guaranteed */
ZSTD_strategy
Definition: zstd.h:251
@ ZSTD_btlazy2
Definition: zstd.h:256
@ ZSTD_lazy
Definition: zstd.h:254
@ ZSTD_btultra
Definition: zstd.h:258
@ ZSTD_greedy
Definition: zstd.h:253
@ ZSTD_dfast
Definition: zstd.h:252
@ ZSTD_fast
Definition: zstd.h:251
@ ZSTD_lazy2
Definition: zstd.h:255
@ ZSTD_btopt
Definition: zstd.h:257
@ ZSTD_btultra2
Definition: zstd.h:259

Function Documentation

◆ ZSTD_CCtx_loadDictionary()

ZSTDLIB_API size_t ZSTD_CCtx_loadDictionary ( ZSTD_CCtx cctx,
const void dict,
size_t  dictSize 
)

ZSTD_CCtx_loadDictionary() : Create an internal CDict from dict buffer. Decompression will have to use same dictionary.

Returns
: 0, or an error code (which can be tested with ZSTD_isError()). Special: Loading a NULL (or 0-size) dictionary invalidates previous dictionary, meaning "return to no-dictionary mode". Note 1 : Dictionary is sticky, it will be used for all future compressed frames. To return to "no-dictionary" situation, load a NULL dictionary (or reset parameters). Note 2 : Loading a dictionary involves building tables. It's also a CPU consuming operation, with non-negligible impact on latency. Tables are dependent on compression parameters, and for this reason, compression parameters can no longer be changed after loading a dictionary. Note 3 :dict content will be copied internally. Use experimental ZSTD_CCtx_loadDictionary_byReference() to reference content instead. In such a case, dictionary buffer must outlive its users. Note 4 : Use ZSTD_CCtx_loadDictionary_advanced() to precisely select how dictionary content must be interpreted.

Definition at line 924 of file zstd_compress.c.

925{
927 cctx, dict, dictSize, ZSTD_dlm_byCopy, ZSTD_dct_auto);
928}
size_t ZSTD_CCtx_loadDictionary_advanced(ZSTD_CCtx *cctx, const void *dict, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictContentType_e dictContentType)

Referenced by ZSTD_initCStream_advanced(), ZSTD_initCStream_internal(), and ZSTD_initCStream_usingDict().

◆ ZSTD_CCtx_refCDict()

ZSTDLIB_API size_t ZSTD_CCtx_refCDict ( ZSTD_CCtx cctx,
const ZSTD_CDict cdict 
)

ZSTD_CCtx_refCDict() : Reference a prepared dictionary, to be used for all next compressed frames. Note that compression parameters are enforced from within CDict, and supersede any compression parameter previously set within CCtx. The parameters ignored are labled as "superseded-by-cdict" in the ZSTD_cParameter enum docs. The ignored parameters will be used again if the CCtx is returned to no-dictionary mode. The dictionary will remain valid for future compressed frames using same CCtx.

Returns
: 0, or an error code (which can be tested with ZSTD_isError()). Special : Referencing a NULL CDict means "return to no-dictionary mode". Note 1 : Currently, only one dictionary can be managed. Referencing a new dictionary effectively "discards" any previous one. Note 2 : CDict is just referenced, its lifetime must outlive its usage within CCtx.

Definition at line 931 of file zstd_compress.c.

932{
933 RETURN_ERROR_IF(cctx->streamStage != zcss_init, stage_wrong,
934 "Can't ref a dict when ctx not in init stage.");
935 /* Free the existing local cdict (if any) to save memory. */
936 ZSTD_clearAllDicts(cctx);
937 cctx->cdict = cdict;
938 return 0;
939}
ZSTD_cStreamStage streamStage
const ZSTD_CDict * cdict
static void ZSTD_clearAllDicts(ZSTD_CCtx *cctx)
#define RETURN_ERROR_IF(cond, err,...)
Definition: zstd_internal.h:91

Referenced by ZSTD_initCStream(), ZSTD_initCStream_internal(), ZSTD_initCStream_srcSize(), ZSTD_initCStream_usingCDict(), and ZSTD_initCStream_usingCDict_advanced().

◆ ZSTD_CCtx_refPrefix()

ZSTDLIB_API size_t ZSTD_CCtx_refPrefix ( ZSTD_CCtx cctx,
const void prefix,
size_t  prefixSize 
)

ZSTD_CCtx_refPrefix() : Reference a prefix (single-usage dictionary) for next compressed frame. A prefix is only used once. Tables are discarded at end of frame (ZSTD_e_end). Decompression will need same prefix to properly regenerate data. Compressing with a prefix is similar in outcome as performing a diff and compressing it, but performs much faster, especially during decompression (compression speed is tunable with compression level).

Returns
: 0, or an error code (which can be tested with ZSTD_isError()). Special: Adding any prefix (including NULL) invalidates any previous prefix or dictionary Note 1 : Prefix buffer is referenced. It must outlive compression. Its content must remain unmodified during compression. Note 2 : If the intention is to diff some large src data blob with some prior version of itself, ensure that the window size is large enough to contain the entire source. See ZSTD_c_windowLog. Note 3 : Referencing a prefix involves building tables, which are dependent on compression parameters. It's a CPU consuming operation, with non-negligible impact on latency. If there is a need to use the same prefix multiple times, consider loadDictionary instead. Note 4 : By default, the prefix is interpreted as raw content (ZSTD_dct_rawContent). Use experimental ZSTD_CCtx_refPrefix_advanced() to alter dictionary interpretation.

Definition at line 941 of file zstd_compress.c.

942{
943 return ZSTD_CCtx_refPrefix_advanced(cctx, prefix, prefixSize, ZSTD_dct_rawContent);
944}
size_t ZSTD_CCtx_refPrefix_advanced(ZSTD_CCtx *cctx, const void *prefix, size_t prefixSize, ZSTD_dictContentType_e dictContentType)

◆ ZSTD_CCtx_reset()

ZSTDLIB_API size_t ZSTD_CCtx_reset ( ZSTD_CCtx cctx,
ZSTD_ResetDirective  reset 
)

ZSTD_CCtx_reset() : There are 2 different things that can be reset, independently or jointly :

  • The session : will stop compressing current frame, and make CCtx ready to start a new one. Useful after an error, or to interrupt any ongoing compression. Any internal data not yet flushed is cancelled. Compression parameters and dictionary remain unchanged. They will be used to compress next frame. Resetting session never fails.
  • The parameters : changes all parameters back to "default". This removes any reference to any dictionary too. Parameters can only be changed between 2 sessions (i.e. no compression is currently ongoing) otherwise the reset fails, and function returns an error value (which can be tested using ZSTD_isError())
  • Both : similar to resetting the session, followed by resetting parameters.

ZSTD_CCtx_reset() : Also dumps dictionary

Definition at line 962 of file zstd_compress.c.

963{
966 cctx->streamStage = zcss_init;
967 cctx->pledgedSrcSizePlusOne = 0;
968 }
971 RETURN_ERROR_IF(cctx->streamStage != zcss_init, stage_wrong,
972 "Can't reset parameters only when not in init stage.");
973 ZSTD_clearAllDicts(cctx);
975 }
976 return 0;
977}
GLboolean reset
Definition: glext.h:5666
ZSTD_CCtx_params requestedParams
unsigned long long pledgedSrcSizePlusOne
size_t ZSTD_CCtxParams_reset(ZSTD_CCtx_params *params)

Referenced by ZSTD_compress2(), ZSTD_compressStream2(), ZSTD_compressStream_generic(), ZSTD_initCCtx(), ZSTD_initCStream(), ZSTD_initCStream_advanced(), ZSTD_initCStream_internal(), ZSTD_initCStream_srcSize(), ZSTD_initCStream_usingCDict(), ZSTD_initCStream_usingCDict_advanced(), ZSTD_initCStream_usingDict(), and ZSTD_resetCStream().

◆ ZSTD_CCtx_setParameter()

ZSTDLIB_API size_t ZSTD_CCtx_setParameter ( ZSTD_CCtx cctx,
ZSTD_cParameter  param,
int  value 
)

ZSTD_CCtx_setParameter() : Set one compression parameter, selected by enum ZSTD_cParameter. All parameters have valid bounds. Bounds can be queried using ZSTD_cParam_getBounds(). Providing a value beyond bound will either clamp it, or trigger an error (depending on parameter). Setting a parameter is generally only possible during frame initialization (before starting compression). Exception : when using multi-threading mode (nbWorkers >= 1), the following parameters can be updated during compression (within same frame): => compressionLevel, hashLog, chainLog, searchLog, minMatch, targetLength and strategy. new parameters will be active for next job only (after a flush()).

Returns
: an error code (which can be tested using ZSTD_isError()).

Definition at line 482 of file zstd_compress.c.

483{
484 DEBUGLOG(4, "ZSTD_CCtx_setParameter (%i, %i)", (int)param, value);
485 if (cctx->streamStage != zcss_init) {
487 cctx->cParamsChanged = 1;
488 } else {
489 RETURN_ERROR(stage_wrong, "can only set params in ctx init stage");
490 } }
491
492 switch(param)
493 {
494 case ZSTD_c_nbWorkers:
495 RETURN_ERROR_IF((value!=0) && cctx->staticSize, parameter_unsupported,
496 "MT not compatible with static alloc");
497 break;
498
500 case ZSTD_c_windowLog:
501 case ZSTD_c_hashLog:
502 case ZSTD_c_chainLog:
503 case ZSTD_c_searchLog:
504 case ZSTD_c_minMatch:
506 case ZSTD_c_strategy:
508 case ZSTD_c_format:
512 case ZSTD_c_forceMaxWindow:
513 case ZSTD_c_forceAttachDict:
514 case ZSTD_c_literalCompressionMode:
515 case ZSTD_c_jobSize:
517 case ZSTD_c_rsyncable:
522 case ZSTD_c_targetCBlockSize:
523 case ZSTD_c_srcSizeHint:
524 break;
525
526 default: RETURN_ERROR(parameter_unsupported, "unknown parameter");
527 }
529}
#define RETURN_ERROR(StatusCode)
Definition: Base.h:751
#define DEBUGLOG(l,...)
Definition: debug.h:106
GLfloat param
Definition: glext.h:5796
Definition: pdh_main.c:94
static int ZSTD_isUpdateAuthorized(ZSTD_cParameter param)
size_t ZSTD_CCtxParams_setParameter(ZSTD_CCtx_params *CCtxParams, ZSTD_cParameter param, int value)

Referenced by ZSTD_initCStream(), ZSTD_initCStream_srcSize(), and ZSTD_initCStream_usingDict().

◆ ZSTD_CCtx_setPledgedSrcSize()

ZSTDLIB_API size_t ZSTD_CCtx_setPledgedSrcSize ( ZSTD_CCtx cctx,
unsigned long long  pledgedSrcSize 
)

ZSTD_CCtx_setPledgedSrcSize() : Total input data size to be compressed as a single frame. Value will be written in frame header, unless if explicitly forbidden using ZSTD_c_contentSizeFlag. This value will also be controlled at end of frame, and trigger an error if not respected.

Returns
: 0, or an error code (which can be tested with ZSTD_isError()). Note 1 : pledgedSrcSize==0 actually means zero, aka an empty frame. In order to mean "unknown content size", pass constant ZSTD_CONTENTSIZE_UNKNOWN. ZSTD_CONTENTSIZE_UNKNOWN is default value for any new frame. Note 2 : pledgedSrcSize is only valid once, for the next frame. It's discarded at the end of the frame, and replaced by ZSTD_CONTENTSIZE_UNKNOWN. Note 3 : Whenever all input data is provided and consumed in a single round, for example with ZSTD_compress2(), or invoking immediately ZSTD_compressStream2(,,,ZSTD_e_end), this value is automatically overridden by srcSize instead.

Definition at line 844 of file zstd_compress.c.

845{
846 DEBUGLOG(4, "ZSTD_CCtx_setPledgedSrcSize to %u bytes", (U32)pledgedSrcSize);
847 RETURN_ERROR_IF(cctx->streamStage != zcss_init, stage_wrong,
848 "Can't set pledgedSrcSize when not in init stage.");
849 cctx->pledgedSrcSizePlusOne = pledgedSrcSize+1;
850 return 0;
851}
unsigned int U32
Definition: xxhash.c:195

Referenced by ZSTD_initCStream_advanced(), ZSTD_initCStream_internal(), ZSTD_initCStream_srcSize(), ZSTD_initCStream_usingCDict_advanced(), and ZSTD_resetCStream().

◆ ZSTD_compress()

ZSTDLIB_API size_t ZSTD_compress ( void dst,
size_t  dstCapacity,
const void src,
size_t  srcSize,
int  compressionLevel 
)

ZSTD_compress() : Compresses src content as a single zstd compressed frame into already allocated dst. Hint : compression runs faster if dstCapacity >= ZSTD_compressBound(srcSize).

Returns
: compressed size written into dst (<= `dstCapacity), or an error code if it fails (which can be tested using ZSTD_isError()).

Definition at line 3307 of file zstd_compress.c.

3310{
3311 size_t result;
3312 ZSTD_CCtx ctxBody;
3313 ZSTD_initCCtx(&ctxBody, ZSTD_defaultCMem);
3314 result = ZSTD_compressCCtx(&ctxBody, dst, dstCapacity, src, srcSize, compressionLevel);
3315 ZSTD_freeCCtxContent(&ctxBody); /* can't free ctxBody itself, as it's on stack; free only heap content */
3316 return result;
3317}
GLenum src
Definition: glext.h:6340
GLenum GLenum dst
Definition: glext.h:6340
GLuint64EXT * result
Definition: glext.h:11304
size_t ZSTD_compressCCtx(ZSTD_CCtx *cctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, int compressionLevel)
static void ZSTD_initCCtx(ZSTD_CCtx *cctx, ZSTD_customMem memManager)
Definition: zstd_compress.c:69
static void ZSTD_freeCCtxContent(ZSTD_CCtx *cctx)

◆ ZSTD_compress2()

ZSTDLIB_API size_t ZSTD_compress2 ( ZSTD_CCtx cctx,
void dst,
size_t  dstCapacity,
const void src,
size_t  srcSize 
)

ZSTD_compress2() : Behave the same as ZSTD_compressCCtx(), but compression parameters are set using the advanced API. 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*()
  • The function is always blocking, returns when compression is completed. Hint : compression runs faster if dstCapacity >= ZSTD_compressBound(srcSize).
    Returns
    : compressed size written into dst (<= `dstCapacity), or an error code if it fails (which can be tested using ZSTD_isError()).

Definition at line 4064 of file zstd_compress.c.

4067{
4068 DEBUGLOG(4, "ZSTD_compress2 (srcSize=%u)", (unsigned)srcSize);
4070 { size_t oPos = 0;
4071 size_t iPos = 0;
4072 size_t const result = ZSTD_compressStream2_simpleArgs(cctx,
4073 dst, dstCapacity, &oPos,
4074 src, srcSize, &iPos,
4075 ZSTD_e_end);
4076 FORWARD_IF_ERROR(result, "ZSTD_compressStream2_simpleArgs failed");
4077 if (result != 0) { /* compression not completed, due to lack of output space */
4078 assert(oPos == dstCapacity);
4079 RETURN_ERROR(dstSize_tooSmall, "");
4080 }
4081 assert(iPos == srcSize); /* all input is expected consumed */
4082 return oPos;
4083 }
4084}
#define assert(x)
Definition: debug.h:53
size_t ZSTD_compressStream2_simpleArgs(ZSTD_CCtx *cctx, void *dst, size_t dstCapacity, size_t *dstPos, const void *src, size_t srcSize, size_t *srcPos, ZSTD_EndDirective endOp)
size_t ZSTD_CCtx_reset(ZSTD_CCtx *cctx, ZSTD_ResetDirective reset)
#define FORWARD_IF_ERROR(err,...)

Referenced by ZSTD_getSequences().

◆ ZSTD_compress_usingCDict()

ZSTDLIB_API size_t ZSTD_compress_usingCDict ( ZSTD_CCtx cctx,
void dst,
size_t  dstCapacity,
const void src,
size_t  srcSize,
const ZSTD_CDict cdict 
)

ZSTD_compress_usingCDict() : Compression using a digested Dictionary. Recommended when same dictionary is used multiple times. Note : compression level is decided at dictionary creation time, and frame parameters are hardcoded (dictID=yes, contentSize=yes, checksum=no)

ZSTD_compress_usingCDict() : Compression using a digested Dictionary. Faster startup than ZSTD_compress_usingDict(), recommended when same dictionary is used multiple times. Note that compression parameters are decided at CDict creation time while frame parameters are hardcoded

Definition at line 3596 of file zstd_compress.c.

3600{
3601 ZSTD_frameParameters const fParams = { 1 /*content*/, 0 /*checksum*/, 0 /*noDictID*/ };
3602 return ZSTD_compress_usingCDict_advanced(cctx, dst, dstCapacity, src, srcSize, cdict, fParams);
3603}
size_t ZSTD_compress_usingCDict_advanced(ZSTD_CCtx *cctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, const ZSTD_CDict *cdict, ZSTD_frameParameters fParams)

◆ ZSTD_compress_usingDict()

ZSTDLIB_API size_t ZSTD_compress_usingDict ( ZSTD_CCtx ctx,
void dst,
size_t  dstCapacity,
const void src,
size_t  srcSize,
const void dict,
size_t  dictSize,
int  compressionLevel 
)

ZSTD_compress_usingDict() : Compression at an explicit compression level using a Dictionary. A dictionary can be any arbitrary data segment (also called a prefix), or a buffer with specified information (see dictBuilder/zdict.h). Note : This function loads the dictionary, resulting in significant startup delay. It's intended for a dictionary used only once. Note 2 : When dict == NULL || dictSize < 8 no dictionary is used.

Definition at line 3284 of file zstd_compress.c.

3289{
3290 ZSTD_parameters const params = ZSTD_getParams_internal(compressionLevel, srcSize, dict ? dictSize : 0);
3291 ZSTD_CCtx_params cctxParams = ZSTD_assignParamsToCCtxParams(&cctx->requestedParams, &params);
3292 DEBUGLOG(4, "ZSTD_compress_usingDict (srcSize=%u)", (unsigned)srcSize);
3293 assert(params.fParams.contentSizeFlag == 1);
3294 return ZSTD_compress_advanced_internal(cctx, dst, dstCapacity, src, srcSize, dict, dictSize, &cctxParams);
3295}
GLenum const GLfloat * params
Definition: glext.h:5645
size_t ZSTD_compress_advanced_internal(ZSTD_CCtx *cctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, const void *dict, size_t dictSize, const ZSTD_CCtx_params *params)
static ZSTD_CCtx_params ZSTD_assignParamsToCCtxParams(const ZSTD_CCtx_params *cctxParams, const ZSTD_parameters *params)
static ZSTD_parameters ZSTD_getParams_internal(int compressionLevel, unsigned long long srcSizeHint, size_t dictSize)

Referenced by ZSTD_compressCCtx().

◆ ZSTD_compressBound()

ZSTDLIB_API size_t ZSTD_compressBound ( size_t  srcSize)

maximum compressed size in worst case single-pass scenario

Definition at line 44 of file zstd_compress.c.

44 {
45 return ZSTD_COMPRESSBOUND(srcSize);
46}
#define ZSTD_COMPRESSBOUND(srcSize)
Definition: zstd.h:174

Referenced by ZSTD_compressStream_generic(), ZSTD_CStreamOutSize(), ZSTD_estimateCStreamSize_usingCCtxParams(), ZSTD_getSequences(), and ZSTD_resetCCtx_internal().

◆ ZSTD_compressCCtx()

ZSTDLIB_API size_t ZSTD_compressCCtx ( ZSTD_CCtx cctx,
void dst,
size_t  dstCapacity,
const void src,
size_t  srcSize,
int  compressionLevel 
)

ZSTD_compressCCtx() : 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 . If any advanced parameter was set using the advanced API, they will all be reset. Only compressionLevel remains.

Definition at line 3297 of file zstd_compress.c.

3301{
3302 DEBUGLOG(4, "ZSTD_compressCCtx (srcSize=%u)", (unsigned)srcSize);
3303 assert(cctx != NULL);
3304 return ZSTD_compress_usingDict(cctx, dst, dstCapacity, src, srcSize, NULL, 0, compressionLevel);
3305}
#define NULL
Definition: types.h:112
size_t ZSTD_compress_usingDict(ZSTD_CCtx *cctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, const void *dict, size_t dictSize, int compressionLevel)

Referenced by ZSTD_compress().

◆ ZSTD_compressStream()

ZSTDLIB_API size_t ZSTD_compressStream ( ZSTD_CStream zcs,
ZSTD_outBuffer output,
ZSTD_inBuffer input 
)

Alternative for ZSTD_compressStream2(zcs, output, input, ZSTD_e_continue). NOTE: The return value is different. ZSTD_compressStream() returns a hint for the next read size (if non-zero and not an error). ZSTD_compressStream2() returns the minimum nb of bytes left to flush (if non-zero and not an error).

Definition at line 3956 of file zstd_compress.c.

3957{
3960}
GLenum GLenum GLenum input
Definition: glext.h:9031
size_t ZSTD_compressStream2(ZSTD_CCtx *cctx, ZSTD_outBuffer *output, ZSTD_inBuffer *input, ZSTD_EndDirective endOp)
static size_t ZSTD_nextInputSizeHint_MTorST(const ZSTD_CCtx *cctx)

Referenced by zstd_compress().

◆ ZSTD_compressStream2()

ZSTDLIB_API size_t ZSTD_compressStream2 ( ZSTD_CCtx cctx,
ZSTD_outBuffer output,
ZSTD_inBuffer input,
ZSTD_EndDirective  endOp 
)

ZSTD_compressStream2() : Behaves about the same as ZSTD_compressStream, with additional control on end directive.

  • Compression parameters are pushed into CCtx before starting compression, using ZSTD_CCtx_set*()
  • Compression parameters cannot be changed once compression is started (save a list of exceptions in multi-threading mode)
  • output->pos must be <= dstCapacity, input->pos must be <= srcSize
  • output->pos and input->pos will be updated. They are guaranteed to remain below their respective limit.
  • When nbWorkers==0 (default), function is blocking : it completes its job before returning to caller.
  • When nbWorkers>=1, function is non-blocking : it just acquires a copy of input, and distributes jobs to internal worker threads, flush whatever is available, and then immediately returns, just indicating that there is some data remaining to be flushed. The function nonetheless guarantees forward progress : it will return only after it reads or write at least 1+ byte.
  • Exception : if the first call requests a ZSTD_e_end directive and provides enough dstCapacity, the function delegates to ZSTD_compress2() which is always blocking.
  • Returns
    provides a minimum amount of data remaining to be flushed from internal buffers or an error code, which can be tested using ZSTD_isError(). if
    != 0, flush is not fully completed, there is still some data left within internal buffers. This is useful for ZSTD_e_flush, since in this case more flushes are necessary to empty all buffers. For ZSTD_e_end,
    == 0 when internal buffers are fully flushed and frame is completed.
  • after a ZSTD_e_end directive, if internal buffer is not fully flushed (
    Returns
    != 0), 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.

Definition at line 3963 of file zstd_compress.c.

3967{
3968 DEBUGLOG(5, "ZSTD_compressStream2, endOp=%u ", (unsigned)endOp);
3969 /* check conditions */
3970 RETURN_ERROR_IF(output->pos > output->size, GENERIC, "invalid buffer");
3971 RETURN_ERROR_IF(input->pos > input->size, GENERIC, "invalid buffer");
3972 assert(cctx!=NULL);
3973
3974 /* transparent initialization stage */
3975 if (cctx->streamStage == zcss_init) {
3976 ZSTD_CCtx_params params = cctx->requestedParams;
3977 ZSTD_prefixDict const prefixDict = cctx->prefixDict;
3978 FORWARD_IF_ERROR( ZSTD_initLocalDict(cctx) , ""); /* Init the local dict if present. */
3979 memset(&cctx->prefixDict, 0, sizeof(cctx->prefixDict)); /* single usage */
3980 assert(prefixDict.dict==NULL || cctx->cdict==NULL); /* only one can be set */
3981 DEBUGLOG(4, "ZSTD_compressStream2 : transparent init stage");
3982 if (endOp == ZSTD_e_end) cctx->pledgedSrcSizePlusOne = input->size + 1; /* auto-fix pledgedSrcSize */
3984 &cctx->requestedParams, cctx->pledgedSrcSizePlusOne-1, 0 /*dictSize*/);
3985
3986
3987#ifdef ZSTD_MULTITHREAD
3988 if ((cctx->pledgedSrcSizePlusOne-1) <= ZSTDMT_JOBSIZE_MIN) {
3989 params.nbWorkers = 0; /* do not invoke multi-threading when src size is too small */
3990 }
3991 if (params.nbWorkers > 0) {
3992 /* mt context creation */
3993 if (cctx->mtctx == NULL) {
3994 DEBUGLOG(4, "ZSTD_compressStream2: creating new mtctx for nbWorkers=%u",
3995 params.nbWorkers);
3996 cctx->mtctx = ZSTDMT_createCCtx_advanced((U32)params.nbWorkers, cctx->customMem);
3997 RETURN_ERROR_IF(cctx->mtctx == NULL, memory_allocation, "NULL pointer!");
3998 }
3999 /* mt compression */
4000 DEBUGLOG(4, "call ZSTDMT_initCStream_internal as nbWorkers=%u", params.nbWorkers);
4001 FORWARD_IF_ERROR( ZSTDMT_initCStream_internal(
4002 cctx->mtctx,
4003 prefixDict.dict, prefixDict.dictSize, prefixDict.dictContentType,
4004 cctx->cdict, params, cctx->pledgedSrcSizePlusOne-1) , "");
4005 cctx->streamStage = zcss_load;
4006 cctx->appliedParams.nbWorkers = params.nbWorkers;
4007 } else
4008#endif
4010 prefixDict.dict, prefixDict.dictSize, prefixDict.dictContentType,
4011 cctx->cdict,
4012 params, cctx->pledgedSrcSizePlusOne-1) , "");
4013 assert(cctx->streamStage == zcss_load);
4014 assert(cctx->appliedParams.nbWorkers == 0);
4015 } }
4016 /* end of transparent initialization stage */
4017
4018 /* compression stage */
4019#ifdef ZSTD_MULTITHREAD
4020 if (cctx->appliedParams.nbWorkers > 0) {
4021 int const forceMaxProgress = (endOp == ZSTD_e_flush || endOp == ZSTD_e_end);
4022 size_t flushMin;
4023 assert(forceMaxProgress || endOp == ZSTD_e_continue /* Protection for a new flush type */);
4024 if (cctx->cParamsChanged) {
4025 ZSTDMT_updateCParams_whileCompressing(cctx->mtctx, &cctx->requestedParams);
4026 cctx->cParamsChanged = 0;
4027 }
4028 do {
4029 flushMin = ZSTDMT_compressStream_generic(cctx->mtctx, output, input, endOp);
4030 if ( ZSTD_isError(flushMin)
4031 || (endOp == ZSTD_e_end && flushMin == 0) ) { /* compression completed */
4033 }
4034 FORWARD_IF_ERROR(flushMin, "ZSTDMT_compressStream_generic failed");
4035 } while (forceMaxProgress && flushMin != 0 && output->pos < output->size);
4036 DEBUGLOG(5, "completed ZSTD_compressStream2 delegating to ZSTDMT_compressStream_generic");
4037 /* Either we don't require maximum forward progress, we've finished the
4038 * flush, or we are out of output space.
4039 */
4040 assert(!forceMaxProgress || flushMin == 0 || output->pos == output->size);
4041 return flushMin;
4042 }
4043#endif
4044 FORWARD_IF_ERROR( ZSTD_compressStream_generic(cctx, output, input, endOp) , "");
4045 DEBUGLOG(5, "completed ZSTD_compressStream2");
4046 return cctx->outBuffContentSize - cctx->outBuffFlushedSize; /* remaining to flush */
4047}
#define memset(x, y, z)
Definition: compat.h:39
ZSTD_CCtx_params appliedParams
ZSTD_customMem customMem
ZSTD_prefixDict prefixDict
size_t size
Definition: zstd.h:574
size_t pos
Definition: zstd.h:575
ZSTD_dictContentType_e dictContentType
static size_t ZSTD_compressStream_generic(ZSTD_CStream *zcs, ZSTD_outBuffer *output, ZSTD_inBuffer *input, ZSTD_EndDirective const flushMode)
static size_t ZSTD_initLocalDict(ZSTD_CCtx *cctx)
ZSTD_compressionParameters ZSTD_getCParamsFromCCtxParams(const ZSTD_CCtx_params *CCtxParams, U64 srcSizeHint, size_t dictSize)
static size_t ZSTD_resetCStream_internal(ZSTD_CStream *cctx, const void *const dict, size_t const dictSize, ZSTD_dictContentType_e const dictContentType, const ZSTD_CDict *const cdict, ZSTD_CCtx_params params, unsigned long long const pledgedSrcSize)
#define ZSTD_isError
Definition: zstd_internal.h:46

Referenced by ZSTD_compressStream(), ZSTD_compressStream2_simpleArgs(), ZSTD_endStream(), and ZSTD_flushStream().

◆ ZSTD_cParam_getBounds()

ZSTDLIB_API ZSTD_bounds ZSTD_cParam_getBounds ( ZSTD_cParameter  cParam)

ZSTD_cParam_getBounds() : All parameters must belong to an interval with lower and upper bounds, otherwise they will either trigger an error or be automatically clamped.

Returns
: a structure, ZSTD_bounds, which contains
  • an error status field, which must be tested using ZSTD_isError()
  • lower and upper bounds, both inclusive

Definition at line 268 of file zstd_compress.c.

269{
270 ZSTD_bounds bounds = { 0, 0, 0 };
271
272 switch(param)
273 {
275 bounds.lowerBound = ZSTD_minCLevel();
276 bounds.upperBound = ZSTD_maxCLevel();
277 return bounds;
278
279 case ZSTD_c_windowLog:
280 bounds.lowerBound = ZSTD_WINDOWLOG_MIN;
281 bounds.upperBound = ZSTD_WINDOWLOG_MAX;
282 return bounds;
283
284 case ZSTD_c_hashLog:
285 bounds.lowerBound = ZSTD_HASHLOG_MIN;
286 bounds.upperBound = ZSTD_HASHLOG_MAX;
287 return bounds;
288
289 case ZSTD_c_chainLog:
290 bounds.lowerBound = ZSTD_CHAINLOG_MIN;
291 bounds.upperBound = ZSTD_CHAINLOG_MAX;
292 return bounds;
293
294 case ZSTD_c_searchLog:
295 bounds.lowerBound = ZSTD_SEARCHLOG_MIN;
296 bounds.upperBound = ZSTD_SEARCHLOG_MAX;
297 return bounds;
298
299 case ZSTD_c_minMatch:
300 bounds.lowerBound = ZSTD_MINMATCH_MIN;
301 bounds.upperBound = ZSTD_MINMATCH_MAX;
302 return bounds;
303
305 bounds.lowerBound = ZSTD_TARGETLENGTH_MIN;
306 bounds.upperBound = ZSTD_TARGETLENGTH_MAX;
307 return bounds;
308
309 case ZSTD_c_strategy:
310 bounds.lowerBound = ZSTD_STRATEGY_MIN;
311 bounds.upperBound = ZSTD_STRATEGY_MAX;
312 return bounds;
313
315 bounds.lowerBound = 0;
316 bounds.upperBound = 1;
317 return bounds;
318
320 bounds.lowerBound = 0;
321 bounds.upperBound = 1;
322 return bounds;
323
325 bounds.lowerBound = 0;
326 bounds.upperBound = 1;
327 return bounds;
328
329 case ZSTD_c_nbWorkers:
330 bounds.lowerBound = 0;
331#ifdef ZSTD_MULTITHREAD
332 bounds.upperBound = ZSTDMT_NBWORKERS_MAX;
333#else
334 bounds.upperBound = 0;
335#endif
336 return bounds;
337
338 case ZSTD_c_jobSize:
339 bounds.lowerBound = 0;
340#ifdef ZSTD_MULTITHREAD
341 bounds.upperBound = ZSTDMT_JOBSIZE_MAX;
342#else
343 bounds.upperBound = 0;
344#endif
345 return bounds;
346
348#ifdef ZSTD_MULTITHREAD
349 bounds.lowerBound = ZSTD_OVERLAPLOG_MIN;
350 bounds.upperBound = ZSTD_OVERLAPLOG_MAX;
351#else
352 bounds.lowerBound = 0;
353 bounds.upperBound = 0;
354#endif
355 return bounds;
356
358 bounds.lowerBound = 0;
359 bounds.upperBound = 1;
360 return bounds;
361
363 bounds.lowerBound = ZSTD_LDM_HASHLOG_MIN;
364 bounds.upperBound = ZSTD_LDM_HASHLOG_MAX;
365 return bounds;
366
368 bounds.lowerBound = ZSTD_LDM_MINMATCH_MIN;
369 bounds.upperBound = ZSTD_LDM_MINMATCH_MAX;
370 return bounds;
371
373 bounds.lowerBound = ZSTD_LDM_BUCKETSIZELOG_MIN;
374 bounds.upperBound = ZSTD_LDM_BUCKETSIZELOG_MAX;
375 return bounds;
376
378 bounds.lowerBound = ZSTD_LDM_HASHRATELOG_MIN;
379 bounds.upperBound = ZSTD_LDM_HASHRATELOG_MAX;
380 return bounds;
381
382 /* experimental parameters */
383 case ZSTD_c_rsyncable:
384 bounds.lowerBound = 0;
385 bounds.upperBound = 1;
386 return bounds;
387
388 case ZSTD_c_forceMaxWindow :
389 bounds.lowerBound = 0;
390 bounds.upperBound = 1;
391 return bounds;
392
393 case ZSTD_c_format:
394 ZSTD_STATIC_ASSERT(ZSTD_f_zstd1 < ZSTD_f_zstd1_magicless);
395 bounds.lowerBound = ZSTD_f_zstd1;
396 bounds.upperBound = ZSTD_f_zstd1_magicless; /* note : how to ensure at compile time that this is the highest value enum ? */
397 return bounds;
398
399 case ZSTD_c_forceAttachDict:
400 ZSTD_STATIC_ASSERT(ZSTD_dictDefaultAttach < ZSTD_dictForceCopy);
401 bounds.lowerBound = ZSTD_dictDefaultAttach;
402 bounds.upperBound = ZSTD_dictForceLoad; /* note : how to ensure at compile time that this is the highest value enum ? */
403 return bounds;
404
405 case ZSTD_c_literalCompressionMode:
406 ZSTD_STATIC_ASSERT(ZSTD_lcm_auto < ZSTD_lcm_huffman && ZSTD_lcm_huffman < ZSTD_lcm_uncompressed);
407 bounds.lowerBound = ZSTD_lcm_auto;
408 bounds.upperBound = ZSTD_lcm_uncompressed;
409 return bounds;
410
411 case ZSTD_c_targetCBlockSize:
412 bounds.lowerBound = ZSTD_TARGETCBLOCKSIZE_MIN;
413 bounds.upperBound = ZSTD_TARGETCBLOCKSIZE_MAX;
414 return bounds;
415
416 case ZSTD_c_srcSizeHint:
417 bounds.lowerBound = ZSTD_SRCSIZEHINT_MIN;
418 bounds.upperBound = ZSTD_SRCSIZEHINT_MAX;
419 return bounds;
420
421 default:
422 bounds.error = ERROR(parameter_unsupported);
423 return bounds;
424 }
425}
#define ERROR(name)
Definition: error_private.h:53
int upperBound
Definition: zstd.h:422
size_t error
Definition: zstd.h:420
int lowerBound
Definition: zstd.h:421
int ZSTD_maxCLevel(void)
int ZSTD_minCLevel(void)
#define ZSTD_STATIC_ASSERT(c)
Definition: zstd_internal.h:45

Referenced by ZSTD_cParam_clampBounds().

◆ ZSTD_createCCtx()

ZSTDLIB_API ZSTD_CCtx * ZSTD_createCCtx ( void  )

Definition at line 64 of file zstd_compress.c.

65{
66 return ZSTD_createCCtx_advanced(ZSTD_defaultCMem);
67}
ZSTD_CCtx * ZSTD_createCCtx_advanced(ZSTD_customMem customMem)
Definition: zstd_compress.c:81

◆ ZSTD_createCDict()

ZSTDLIB_API ZSTD_CDict * ZSTD_createCDict ( const void dictBuffer,
size_t  dictSize,
int  compressionLevel 
)

ZSTD_createCDict() : When compressing multiple messages or blocks using the same dictionary, it's recommended to digest the dictionary only once, since it's a costly operation. ZSTD_createCDict() will create a state from digesting a dictionary. The resulting state can be used for future compression operations with very limited startup cost. ZSTD_CDict can be created once and shared by multiple threads concurrently, since its usage is read-only. @dictBuffer can be released after ZSTD_CDict creation, because its content is copied within CDict. Note 1 : Consider experimental function ZSTD_createCDict_byReference() if you prefer to not duplicate @dictBuffer content. Note 2 : A ZSTD_CDict can be created from an empty @dictBuffer, in which case the only thing that it transports is the @compressionLevel. This can be useful in a pipeline featuring ZSTD_compress_usingCDict() exclusively, expecting a ZSTD_CDict parameter with any data, including those without a known dictionary.

Definition at line 3447 of file zstd_compress.c.

3448{
3449 ZSTD_compressionParameters cParams = ZSTD_getCParams_internal(compressionLevel, ZSTD_CONTENTSIZE_UNKNOWN, dictSize);
3450 ZSTD_CDict* cdict = ZSTD_createCDict_advanced(dict, dictSize,
3451 ZSTD_dlm_byCopy, ZSTD_dct_auto,
3452 cParams, ZSTD_defaultCMem);
3453 if (cdict)
3454 cdict->compressionLevel = compressionLevel == 0 ? ZSTD_CLEVEL_DEFAULT : compressionLevel;
3455 return cdict;
3456}
int compressionLevel
Definition: zstd_compress.c:61
#define ZSTD_CONTENTSIZE_UNKNOWN
Definition: zstd.h:152
#define ZSTD_CLEVEL_DEFAULT
Definition: zstd.h:90
ZSTD_CDict * ZSTD_createCDict_advanced(const void *dictBuffer, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictContentType_e dictContentType, ZSTD_compressionParameters cParams, ZSTD_customMem customMem)
static ZSTD_compressionParameters ZSTD_getCParams_internal(int compressionLevel, unsigned long long srcSizeHint, size_t dictSize)

◆ ZSTD_createCStream()

ZSTDLIB_API ZSTD_CStream * ZSTD_createCStream ( void  )

Definition at line 3611 of file zstd_compress.c.

3612{
3613 DEBUGLOG(3, "ZSTD_createCStream");
3614 return ZSTD_createCStream_advanced(ZSTD_defaultCMem);
3615}
ZSTD_CStream * ZSTD_createCStream_advanced(ZSTD_customMem customMem)

◆ ZSTD_createDCtx()

ZSTDLIB_API ZSTD_DCtx * ZSTD_createDCtx ( void  )

Definition at line 147 of file zstd_decompress.c.

148{
149 DEBUGLOG(3, "ZSTD_createDCtx");
150 return ZSTD_createDCtx_advanced(ZSTD_defaultCMem);
151}
ZSTD_DCtx * ZSTD_createDCtx_advanced(ZSTD_customMem customMem)

Referenced by ZSTD_decompress().

◆ ZSTD_createDDict()

ZSTDLIB_API ZSTD_DDict * ZSTD_createDDict ( const void dict,
size_t  dictSize 
)

ZSTD_createDDict() : Create a digested dictionary, ready to start decompression operation without startup delay. dictBuffer can be released after DDict creation, as its content is copied inside DDict.

ZSTD_createDDict() : Create a digested dictionary, to start decompression without startup delay. dict content is copied inside DDict. Consequently, dict can be released after ZSTD_DDict creation

Definition at line 170 of file zstd_ddict.c.

171{
172 ZSTD_customMem const allocator = { NULL, NULL, NULL };
173 return ZSTD_createDDict_advanced(dict, dictSize, ZSTD_dlm_byCopy, ZSTD_dct_auto, allocator);
174}
ZSTD_DDict * ZSTD_createDDict_advanced(const void *dict, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictContentType_e dictContentType, ZSTD_customMem customMem)
Definition: zstd_ddict.c:145

◆ ZSTD_createDStream()

ZSTDLIB_API ZSTD_DStream * ZSTD_createDStream ( void  )

Definition at line 1265 of file zstd_decompress.c.

1266{
1267 DEBUGLOG(3, "ZSTD_createDStream");
1268 return ZSTD_createDStream_advanced(ZSTD_defaultCMem);
1269}
ZSTD_DStream * ZSTD_createDStream_advanced(ZSTD_customMem customMem)

◆ ZSTD_CStreamInSize()

ZSTDLIB_API size_t ZSTD_CStreamInSize ( void  )

recommended size for input buffer

Definition at line 3636 of file zstd_compress.c.

3636{ return ZSTD_BLOCKSIZE_MAX; }
#define ZSTD_BLOCKSIZE_MAX
Definition: zstd.h:104

◆ ZSTD_CStreamOutSize()

ZSTDLIB_API size_t ZSTD_CStreamOutSize ( void  )

recommended size for output buffer. Guarantee to successfully flush at least one complete compressed block.

Definition at line 3638 of file zstd_compress.c.

3639{
3640 return ZSTD_compressBound(ZSTD_BLOCKSIZE_MAX) + ZSTD_blockHeaderSize + 4 /* 32-bits hash */ ;
3641}
size_t ZSTD_compressBound(size_t srcSize)
Definition: zstd_compress.c:44
static const size_t ZSTD_blockHeaderSize

◆ ZSTD_DCtx_loadDictionary()

ZSTDLIB_API size_t ZSTD_DCtx_loadDictionary ( ZSTD_DCtx dctx,
const void dict,
size_t  dictSize 
)

ZSTD_DCtx_loadDictionary() : Create an internal DDict from dict buffer, to be used to decompress next frames. The dictionary remains valid for all future frames, until explicitly invalidated.

Returns
: 0, or an error code (which can be tested with ZSTD_isError()). Special : Adding a NULL (or 0-size) dictionary invalidates any previous dictionary, meaning "return to no-dictionary mode". Note 1 : Loading a dictionary involves building tables, which has a non-negligible impact on CPU usage and latency. It's recommended to "load once, use many times", to amortize the cost Note 2 :dict content will be copied internally, so dict can be released after loading. Use ZSTD_DCtx_loadDictionary_byReference() to reference dictionary content instead. Note 3 : Use ZSTD_DCtx_loadDictionary_advanced() to take control of how dictionary content is loaded and interpreted.

Definition at line 1313 of file zstd_decompress.c.

1314{
1315 return ZSTD_DCtx_loadDictionary_advanced(dctx, dict, dictSize, ZSTD_dlm_byCopy, ZSTD_dct_auto);
1316}
size_t ZSTD_DCtx_loadDictionary_advanced(ZSTD_DCtx *dctx, const void *dict, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictContentType_e dictContentType)

Referenced by ZSTD_initDStream_usingDict().

◆ ZSTD_DCtx_refDDict()

ZSTDLIB_API size_t ZSTD_DCtx_refDDict ( ZSTD_DCtx dctx,
const ZSTD_DDict ddict 
)

ZSTD_DCtx_refDDict() : Reference a prepared dictionary, to be used to decompress next frames. The dictionary remains active for decompression of future frames using same DCtx.

Returns
: 0, or an error code (which can be tested with ZSTD_isError()). Note 1 : Currently, only one dictionary can be managed. Referencing a new dictionary effectively "discards" any previous one. Special: referencing a NULL DDict means "return to no-dictionary mode". Note 2 : DDict is just referenced, its lifetime must outlive its usage from DCtx.

Definition at line 1369 of file zstd_decompress.c.

1370{
1371 RETURN_ERROR_IF(dctx->streamStage != zdss_init, stage_wrong, "");
1372 ZSTD_clearDict(dctx);
1373 if (ddict) {
1374 dctx->ddict = ddict;
1376 }
1377 return 0;
1378}
ZSTD_dStreamStage streamStage
const ZSTD_DDict * ddict
ZSTD_dictUses_e dictUses
static void ZSTD_clearDict(ZSTD_DCtx *dctx)
@ ZSTD_use_indefinitely

Referenced by ZSTD_initDStream_usingDDict().

◆ ZSTD_DCtx_refPrefix()

ZSTDLIB_API size_t ZSTD_DCtx_refPrefix ( ZSTD_DCtx dctx,
const void prefix,
size_t  prefixSize 
)

ZSTD_DCtx_refPrefix() : Reference a prefix (single-usage dictionary) to decompress next frame. This is the reverse operation of ZSTD_CCtx_refPrefix(), and must use the same prefix as the one used during compression. Prefix is only used once. Reference is discarded at end of frame. End of frame is reached when ZSTD_decompressStream() returns 0.

Returns
: 0, or an error code (which can be tested with ZSTD_isError()). Note 1 : Adding any prefix (including NULL) invalidates any previously set prefix or dictionary Note 2 : Prefix buffer is referenced. It must outlive decompression. Prefix buffer must remain unmodified up to the end of frame, reached when ZSTD_decompressStream() returns 0. Note 3 : By default, the prefix is treated as raw content (ZSTD_dct_rawContent). Use ZSTD_CCtx_refPrefix_advanced() to alter dictMode (Experimental section) Note 4 : Referencing a raw content prefix has almost no cpu nor memory cost. A full dictionary is more costly, as it requires building tables.

Definition at line 1325 of file zstd_decompress.c.

1326{
1327 return ZSTD_DCtx_refPrefix_advanced(dctx, prefix, prefixSize, ZSTD_dct_rawContent);
1328}
size_t ZSTD_DCtx_refPrefix_advanced(ZSTD_DCtx *dctx, const void *prefix, size_t prefixSize, ZSTD_dictContentType_e dictContentType)

◆ ZSTD_DCtx_reset()

ZSTDLIB_API size_t ZSTD_DCtx_reset ( ZSTD_DCtx dctx,
ZSTD_ResetDirective  reset 
)

ZSTD_DCtx_reset() : Return a DCtx to clean state. Session and parameters can be reset jointly or separately. Parameters can only be reset when no active frame is being decompressed.

Returns
: 0, or an error code, which can be tested with ZSTD_isError()

Definition at line 1461 of file zstd_decompress.c.

1462{
1465 dctx->streamStage = zdss_init;
1466 dctx->noForwardProgress = 0;
1467 }
1470 RETURN_ERROR_IF(dctx->streamStage != zdss_init, stage_wrong, "");
1471 ZSTD_clearDict(dctx);
1472 dctx->format = ZSTD_f_zstd1;
1474 }
1475 return 0;
1476}
#define ZSTD_MAXWINDOWSIZE_DEFAULT

Referenced by ZSTD_initDStream_usingDDict(), ZSTD_initDStream_usingDict(), and ZSTD_resetDStream().

◆ ZSTD_DCtx_setParameter()

ZSTDLIB_API size_t ZSTD_DCtx_setParameter ( ZSTD_DCtx dctx,
ZSTD_dParameter  param,
int  value 
)

ZSTD_DCtx_setParameter() : Set one compression parameter, selected by enum ZSTD_dParameter. All parameters have valid bounds. Bounds can be queried using ZSTD_dParam_getBounds(). Providing a value beyond bound will either clamp it, or trigger an error (depending on parameter). Setting a parameter is only possible during frame initialization (before starting decompression).

Returns
: 0, or an error code (which can be tested using ZSTD_isError()).

Definition at line 1439 of file zstd_decompress.c.

1440{
1441 RETURN_ERROR_IF(dctx->streamStage != zdss_init, stage_wrong, "");
1442 switch(dParam) {
1444 if (value == 0) value = ZSTD_WINDOWLOG_LIMIT_DEFAULT;
1446 dctx->maxWindowSize = ((size_t)1) << value;
1447 return 0;
1448 case ZSTD_d_format:
1449 CHECK_DBOUNDS(ZSTD_d_format, value);
1450 dctx->format = (ZSTD_format_e)value;
1451 return 0;
1452 case ZSTD_d_stableOutBuffer:
1453 CHECK_DBOUNDS(ZSTD_d_stableOutBuffer, value);
1455 return 0;
1456 default:;
1457 }
1458 RETURN_ERROR(parameter_unsupported, "");
1459}
__kernel_size_t size_t
Definition: linux.h:237
ZSTD_outBufferMode_e outBufferMode
#define CHECK_DBOUNDS(p, v)

Referenced by ZSTD_DCtx_setFormat().

◆ ZSTD_decompress()

ZSTDLIB_API size_t ZSTD_decompress ( void dst,
size_t  dstCapacity,
const void src,
size_t  compressedSize 
)

ZSTD_decompress() : 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.

Returns
: the number of bytes decompressed into dst (<= dstCapacity), or an errorCode if it fails (which can be tested using ZSTD_isError()).

Definition at line 819 of file zstd_decompress.c.

820{
821#if defined(ZSTD_HEAPMODE) && (ZSTD_HEAPMODE>=1)
822 size_t regenSize;
823 ZSTD_DCtx* const dctx = ZSTD_createDCtx();
824 RETURN_ERROR_IF(dctx==NULL, memory_allocation, "NULL pointer!");
825 regenSize = ZSTD_decompressDCtx(dctx, dst, dstCapacity, src, srcSize);
826 ZSTD_freeDCtx(dctx);
827 return regenSize;
828#else /* stack mode */
829 ZSTD_DCtx dctx;
831 return ZSTD_decompressDCtx(&dctx, dst, dstCapacity, src, srcSize);
832#endif
833}
size_t ZSTD_freeDCtx(ZSTD_DCtx *dctx)
static void ZSTD_initDCtx_internal(ZSTD_DCtx *dctx)
size_t ZSTD_decompressDCtx(ZSTD_DCtx *dctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize)
ZSTD_DCtx * ZSTD_createDCtx(void)

◆ ZSTD_decompress_usingDDict()

ZSTDLIB_API size_t ZSTD_decompress_usingDDict ( ZSTD_DCtx dctx,
void dst,
size_t  dstCapacity,
const void src,
size_t  srcSize,
const ZSTD_DDict ddict 
)

ZSTD_decompress_usingDDict() : Decompression using a digested Dictionary. Recommended when same dictionary is used multiple times.

ZSTD_decompress_usingDDict() : Decompression using a pre-digested Dictionary Use dictionary without significant overhead.

Definition at line 1249 of file zstd_decompress.c.

1253{
1254 /* pass content and size in case legacy frames are encountered */
1255 return ZSTD_decompressMultiFrame(dctx, dst, dstCapacity, src, srcSize,
1256 NULL, 0,
1257 ddict);
1258}
static size_t ZSTD_decompressMultiFrame(ZSTD_DCtx *dctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, const void *dict, size_t dictSize, const ZSTD_DDict *ddict)

Referenced by ZSTD_decompressDCtx(), and ZSTD_decompressStream().

◆ ZSTD_decompress_usingDict()

ZSTDLIB_API size_t ZSTD_decompress_usingDict ( ZSTD_DCtx dctx,
void dst,
size_t  dstCapacity,
const void src,
size_t  srcSize,
const void dict,
size_t  dictSize 
)

ZSTD_decompress_usingDict() : Decompression using a known Dictionary. Dictionary must be identical to the one used during compression. Note : This function loads the dictionary, resulting in significant startup delay. It's intended for a dictionary used only once. Note : When dict == NULL || dictSize < 8 no dictionary is used.

Definition at line 787 of file zstd_decompress.c.

791{
792 return ZSTD_decompressMultiFrame(dctx, dst, dstCapacity, src, srcSize, dict, dictSize, NULL);
793}

◆ ZSTD_decompressDCtx()

ZSTDLIB_API size_t ZSTD_decompressDCtx ( ZSTD_DCtx dctx,
void dst,
size_t  dstCapacity,
const void src,
size_t  srcSize 
)

ZSTD_decompressDCtx() : Same as ZSTD_decompress(), requires an allocated ZSTD_DCtx. Compatible with sticky parameters.

Definition at line 813 of file zstd_decompress.c.

814{
815 return ZSTD_decompress_usingDDict(dctx, dst, dstCapacity, src, srcSize, ZSTD_getDDict(dctx));
816}
static ZSTD_DDict const * ZSTD_getDDict(ZSTD_DCtx *dctx)
size_t ZSTD_decompress_usingDDict(ZSTD_DCtx *dctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, const ZSTD_DDict *ddict)

Referenced by ZSTD_decompress().

◆ ZSTD_decompressStream()

ZSTDLIB_API size_t ZSTD_decompressStream ( ZSTD_DStream zds,
ZSTD_outBuffer output,
ZSTD_inBuffer input 
)

Definition at line 1588 of file zstd_decompress.c.

1589{
1590 const char* const src = (const char*)input->src;
1591 const char* const istart = input->pos != 0 ? src + input->pos : src;
1592 const char* const iend = input->size != 0 ? src + input->size : src;
1593 const char* ip = istart;
1594 char* const dst = (char*)output->dst;
1595 char* const ostart = output->pos != 0 ? dst + output->pos : dst;
1596 char* const oend = output->size != 0 ? dst + output->size : dst;
1597 char* op = ostart;
1598 U32 someMoreWork = 1;
1599
1600 DEBUGLOG(5, "ZSTD_decompressStream");
1602 input->pos > input->size,
1603 srcSize_wrong,
1604 "forbidden. in: pos: %u vs size: %u",
1605 (U32)input->pos, (U32)input->size);
1607 output->pos > output->size,
1608 dstSize_tooSmall,
1609 "forbidden. out: pos: %u vs size: %u",
1610 (U32)output->pos, (U32)output->size);
1611 DEBUGLOG(5, "input size : %u", (U32)(input->size - input->pos));
1612 FORWARD_IF_ERROR(ZSTD_checkOutBuffer(zds, output), "");
1613
1614 while (someMoreWork) {
1615 switch(zds->streamStage)
1616 {
1617 case zdss_init :
1618 DEBUGLOG(5, "stage zdss_init => transparent reset ");
1620 zds->lhSize = zds->inPos = zds->outStart = zds->outEnd = 0;
1621 zds->legacyVersion = 0;
1622 zds->hostageByte = 0;
1623 zds->expectedOutBuffer = *output;
1624 /* fall-through */
1625
1626 case zdss_loadHeader :
1627 DEBUGLOG(5, "stage zdss_loadHeader (srcSize : %u)", (U32)(iend - ip));
1628#if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT>=1)
1629 if (zds->legacyVersion) {
1630 RETURN_ERROR_IF(zds->staticSize, memory_allocation,
1631 "legacy support is incompatible with static dctx");
1632 { size_t const hint = ZSTD_decompressLegacyStream(zds->legacyContext, zds->legacyVersion, output, input);
1633 if (hint==0) zds->streamStage = zdss_init;
1634 return hint;
1635 } }
1636#endif
1637 { size_t const hSize = ZSTD_getFrameHeader_advanced(&zds->fParams, zds->headerBuffer, zds->lhSize, zds->format);
1638 DEBUGLOG(5, "header size : %u", (U32)hSize);
1639 if (ZSTD_isError(hSize)) {
1640#if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT>=1)
1641 U32 const legacyVersion = ZSTD_isLegacy(istart, iend-istart);
1642 if (legacyVersion) {
1643 ZSTD_DDict const* const ddict = ZSTD_getDDict(zds);
1644 const void* const dict = ddict ? ZSTD_DDict_dictContent(ddict) : NULL;
1645 size_t const dictSize = ddict ? ZSTD_DDict_dictSize(ddict) : 0;
1646 DEBUGLOG(5, "ZSTD_decompressStream: detected legacy version v0.%u", legacyVersion);
1647 RETURN_ERROR_IF(zds->staticSize, memory_allocation,
1648 "legacy support is incompatible with static dctx");
1649 FORWARD_IF_ERROR(ZSTD_initLegacyStream(&zds->legacyContext,
1650 zds->previousLegacyVersion, legacyVersion,
1651 dict, dictSize), "");
1652 zds->legacyVersion = zds->previousLegacyVersion = legacyVersion;
1653 { size_t const hint = ZSTD_decompressLegacyStream(zds->legacyContext, legacyVersion, output, input);
1654 if (hint==0) zds->streamStage = zdss_init; /* or stay in stage zdss_loadHeader */
1655 return hint;
1656 } }
1657#endif
1658 return hSize; /* error */
1659 }
1660 if (hSize != 0) { /* need more input */
1661 size_t const toLoad = hSize - zds->lhSize; /* if hSize!=0, hSize > zds->lhSize */
1662 size_t const remainingInput = (size_t)(iend-ip);
1663 assert(iend >= ip);
1664 if (toLoad > remainingInput) { /* not enough input to load full header */
1665 if (remainingInput > 0) {
1666 memcpy(zds->headerBuffer + zds->lhSize, ip, remainingInput);
1667 zds->lhSize += remainingInput;
1668 }
1669 input->pos = input->size;
1670 return (MAX((size_t)ZSTD_FRAMEHEADERSIZE_MIN(zds->format), hSize) - zds->lhSize) + ZSTD_blockHeaderSize; /* remaining header bytes + next block header */
1671 }
1672 assert(ip != NULL);
1673 memcpy(zds->headerBuffer + zds->lhSize, ip, toLoad); zds->lhSize = hSize; ip += toLoad;
1674 break;
1675 } }
1676
1677 /* check for single-pass mode opportunity */
1678 if (zds->fParams.frameContentSize != ZSTD_CONTENTSIZE_UNKNOWN
1679 && zds->fParams.frameType != ZSTD_skippableFrame
1680 && (U64)(size_t)(oend-op) >= zds->fParams.frameContentSize) {
1681 size_t const cSize = ZSTD_findFrameCompressedSize(istart, iend-istart);
1682 if (cSize <= (size_t)(iend-istart)) {
1683 /* shortcut : using single-pass mode */
1684 size_t const decompressedSize = ZSTD_decompress_usingDDict(zds, op, oend-op, istart, cSize, ZSTD_getDDict(zds));
1685 if (ZSTD_isError(decompressedSize)) return decompressedSize;
1686 DEBUGLOG(4, "shortcut to single-pass ZSTD_decompress_usingDDict()")
1687 ip = istart + cSize;
1688 op += decompressedSize;
1689 zds->expected = 0;
1690 zds->streamStage = zdss_init;
1691 someMoreWork = 0;
1692 break;
1693 } }
1694
1695 /* Check output buffer is large enough for ZSTD_odm_stable. */
1696 if (zds->outBufferMode == ZSTD_obm_stable
1697 && zds->fParams.frameType != ZSTD_skippableFrame
1698 && zds->fParams.frameContentSize != ZSTD_CONTENTSIZE_UNKNOWN
1699 && (U64)(size_t)(oend-op) < zds->fParams.frameContentSize) {
1700 RETURN_ERROR(dstSize_tooSmall, "ZSTD_obm_stable passed but ZSTD_outBuffer is too small");
1701 }
1702
1703 /* Consume header (see ZSTDds_decodeFrameHeader) */
1704 DEBUGLOG(4, "Consume header");
1706
1707 if ((MEM_readLE32(zds->headerBuffer) & ZSTD_MAGIC_SKIPPABLE_MASK) == ZSTD_MAGIC_SKIPPABLE_START) { /* skippable frame */
1709 zds->stage = ZSTDds_skipFrame;
1710 } else {
1714 }
1715
1716 /* control buffer memory usage */
1717 DEBUGLOG(4, "Control max memory usage (%u KB <= max %u KB)",
1718 (U32)(zds->fParams.windowSize >>10),
1719 (U32)(zds->maxWindowSize >> 10) );
1720 zds->fParams.windowSize = MAX(zds->fParams.windowSize, 1U << ZSTD_WINDOWLOG_ABSOLUTEMIN);
1721 RETURN_ERROR_IF(zds->fParams.windowSize > zds->maxWindowSize,
1722 frameParameter_windowTooLarge, "");
1723
1724 /* Adapt buffer sizes to frame header instructions */
1725 { size_t const neededInBuffSize = MAX(zds->fParams.blockSizeMax, 4 /* frame checksum */);
1726 size_t const neededOutBuffSize = zds->outBufferMode == ZSTD_obm_buffered
1727 ? ZSTD_decodingBufferSize_min(zds->fParams.windowSize, zds->fParams.frameContentSize)
1728 : 0;
1729
1730 ZSTD_DCtx_updateOversizedDuration(zds, neededInBuffSize, neededOutBuffSize);
1731
1732 { int const tooSmall = (zds->inBuffSize < neededInBuffSize) || (zds->outBuffSize < neededOutBuffSize);
1733 int const tooLarge = ZSTD_DCtx_isOversizedTooLong(zds);
1734
1735 if (tooSmall || tooLarge) {
1736 size_t const bufferSize = neededInBuffSize + neededOutBuffSize;
1737 DEBUGLOG(4, "inBuff : from %u to %u",
1738 (U32)zds->inBuffSize, (U32)neededInBuffSize);
1739 DEBUGLOG(4, "outBuff : from %u to %u",
1740 (U32)zds->outBuffSize, (U32)neededOutBuffSize);
1741 if (zds->staticSize) { /* static DCtx */
1742 DEBUGLOG(4, "staticSize : %u", (U32)zds->staticSize);
1743 assert(zds->staticSize >= sizeof(ZSTD_DCtx)); /* controlled at init */
1745 bufferSize > zds->staticSize - sizeof(ZSTD_DCtx),
1746 memory_allocation, "");
1747 } else {
1748 ZSTD_free(zds->inBuff, zds->customMem);
1749 zds->inBuffSize = 0;
1750 zds->outBuffSize = 0;
1751 zds->inBuff = (char*)ZSTD_malloc(bufferSize, zds->customMem);
1752 RETURN_ERROR_IF(zds->inBuff == NULL, memory_allocation, "");
1753 }
1754 zds->inBuffSize = neededInBuffSize;
1755 zds->outBuff = zds->inBuff + zds->inBuffSize;
1756 zds->outBuffSize = neededOutBuffSize;
1757 } } }
1758 zds->streamStage = zdss_read;
1759 /* fall-through */
1760
1761 case zdss_read:
1762 DEBUGLOG(5, "stage zdss_read");
1763 { size_t const neededInSize = ZSTD_nextSrcSizeToDecompressWithInputSize(zds, iend - ip);
1764 DEBUGLOG(5, "neededInSize = %u", (U32)neededInSize);
1765 if (neededInSize==0) { /* end of frame */
1766 zds->streamStage = zdss_init;
1767 someMoreWork = 0;
1768 break;
1769 }
1770 if ((size_t)(iend-ip) >= neededInSize) { /* decode directly from src */
1771 FORWARD_IF_ERROR(ZSTD_decompressContinueStream(zds, &op, oend, ip, neededInSize), "");
1772 ip += neededInSize;
1773 /* Function modifies the stage so we must break */
1774 break;
1775 } }
1776 if (ip==iend) { someMoreWork = 0; break; } /* no more input */
1777 zds->streamStage = zdss_load;
1778 /* fall-through */
1779
1780 case zdss_load:
1781 { size_t const neededInSize = ZSTD_nextSrcSizeToDecompress(zds);
1782 size_t const toLoad = neededInSize - zds->inPos;
1783 int const isSkipFrame = ZSTD_isSkipFrame(zds);
1784 size_t loadedSize;
1785 /* At this point we shouldn't be decompressing a block that we can stream. */
1786 assert(neededInSize == ZSTD_nextSrcSizeToDecompressWithInputSize(zds, iend - ip));
1787 if (isSkipFrame) {
1788 loadedSize = MIN(toLoad, (size_t)(iend-ip));
1789 } else {
1790 RETURN_ERROR_IF(toLoad > zds->inBuffSize - zds->inPos,
1791 corruption_detected,
1792 "should never happen");
1793 loadedSize = ZSTD_limitCopy(zds->inBuff + zds->inPos, toLoad, ip, iend-ip);
1794 }
1795 ip += loadedSize;
1796 zds->inPos += loadedSize;
1797 if (loadedSize < toLoad) { someMoreWork = 0; break; } /* not enough input, wait for more */
1798
1799 /* decode loaded input */
1800 zds->inPos = 0; /* input is consumed */
1801 FORWARD_IF_ERROR(ZSTD_decompressContinueStream(zds, &op, oend, zds->inBuff, neededInSize), "");
1802 /* Function modifies the stage so we must break */
1803 break;
1804 }
1805 case zdss_flush:
1806 { size_t const toFlushSize = zds->outEnd - zds->outStart;
1807 size_t const flushedSize = ZSTD_limitCopy(op, oend-op, zds->outBuff + zds->outStart, toFlushSize);
1808 op += flushedSize;
1809 zds->outStart += flushedSize;
1810 if (flushedSize == toFlushSize) { /* flush completed */
1811 zds->streamStage = zdss_read;
1812 if ( (zds->outBuffSize < zds->fParams.frameContentSize)
1813 && (zds->outStart + zds->fParams.blockSizeMax > zds->outBuffSize) ) {
1814 DEBUGLOG(5, "restart filling outBuff from beginning (left:%i, needed:%u)",
1815 (int)(zds->outBuffSize - zds->outStart),
1816 (U32)zds->fParams.blockSizeMax);
1817 zds->outStart = zds->outEnd = 0;
1818 }
1819 break;
1820 } }
1821 /* cannot complete flush */
1822 someMoreWork = 0;
1823 break;
1824
1825 default:
1826 assert(0); /* impossible */
1827 RETURN_ERROR(GENERIC, "impossible to reach"); /* some compiler require default to do something */
1828 } }
1829
1830 /* result */
1831 input->pos = (size_t)(ip - (const char*)(input->src));
1832 output->pos = (size_t)(op - (char*)(output->dst));
1833
1834 /* Update the expected output buffer for ZSTD_obm_stable. */
1835 zds->expectedOutBuffer = *output;
1836
1837 if ((ip==istart) && (op==ostart)) { /* no forward progress */
1838 zds->noForwardProgress ++;
1840 RETURN_ERROR_IF(op==oend, dstSize_tooSmall, "");
1841 RETURN_ERROR_IF(ip==iend, srcSize_wrong, "");
1842 assert(0);
1843 }
1844 } else {
1845 zds->noForwardProgress = 0;
1846 }
1847 { size_t nextSrcSizeHint = ZSTD_nextSrcSizeToDecompress(zds);
1848 if (!nextSrcSizeHint) { /* frame fully decoded */
1849 if (zds->outEnd == zds->outStart) { /* output fully flushed */
1850 if (zds->hostageByte) {
1851 if (input->pos >= input->size) {
1852 /* can't release hostage (not present) */
1853 zds->streamStage = zdss_read;
1854 return 1;
1855 }
1856 input->pos++; /* release hostage */
1857 } /* zds->hostageByte */
1858 return 0;
1859 } /* zds->outEnd == zds->outStart */
1860 if (!zds->hostageByte) { /* output not fully flushed; keep last byte as hostage; will be released when all output is flushed */
1861 input->pos--; /* note : pos > 0, otherwise, impossible to finish reading last block */
1862 zds->hostageByte=1;
1863 }
1864 return 1;
1865 } /* nextSrcSizeHint==0 */
1866 nextSrcSizeHint += ZSTD_blockHeaderSize * (ZSTD_nextInputType(zds) == ZSTDnit_block); /* preload header of next block */
1867 assert(zds->inPos <= nextSrcSizeHint);
1868 nextSrcSizeHint -= zds->inPos; /* part already loaded*/
1869 return nextSrcSizeHint;
1870 }
1871}
#define MIN(x, y)
Definition: rdesktop.h:171
#define MAX(x, y)
Definition: rdesktop.h:175
UINT op
Definition: effect.c:236
MEM_STATIC U32 MEM_readLE32(const void *memPtr)
Definition: mem.h:346
size_t bufferSize
if(dx< 0)
Definition: linetemp.h:194
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
BOOL expected
Definition: store.c:2063
ZSTD_customMem customMem
ZSTD_outBuffer expectedOutBuffer
BYTE headerBuffer[ZSTD_FRAMEHEADERSIZE_MAX]
ZSTD_frameHeader fParams
void * dst
Definition: zstd.h:573
Definition: dhcpd.h:62
DWORD hint
Definition: vfdcmd.c:88
unsigned long long U64
Definition: xxhash.c:197
#define ZSTD_MAGIC_SKIPPABLE_MASK
Definition: zstd.h:101
#define ZSTD_MAGIC_SKIPPABLE_START
Definition: zstd.h:100
void ZSTD_free(void *ptr, ZSTD_customMem customMem)
Definition: zstd_common.c:70
void * ZSTD_malloc(size_t size, ZSTD_customMem customMem)
Definition: zstd_common.c:56
const void * ZSTD_DDict_dictContent(const ZSTD_DDict *ddict)
Definition: zstd_ddict.c:46
size_t ZSTD_DDict_dictSize(const ZSTD_DDict *ddict)
Definition: zstd_ddict.c:52
size_t ZSTD_nextSrcSizeToDecompress(ZSTD_DCtx *dctx)
size_t ZSTD_decodingBufferSize_min(unsigned long long windowSize, unsigned long long frameContentSize)
size_t ZSTD_decompressBegin_usingDDict(ZSTD_DCtx *dctx, const ZSTD_DDict *ddict)
ZSTD_nextInputType_e ZSTD_nextInputType(ZSTD_DCtx *dctx)
static size_t ZSTD_decodeFrameHeader(ZSTD_DCtx *dctx, const void *src, size_t headerSize)
static size_t ZSTD_decompressContinueStream(ZSTD_DStream *zds, char **op, char *oend, void const *src, size_t srcSize)
size_t ZSTD_getFrameHeader_advanced(ZSTD_frameHeader *zfhPtr, const void *src, size_t srcSize, ZSTD_format_e format)
static int ZSTD_isSkipFrame(ZSTD_DCtx *dctx)
static void ZSTD_DCtx_updateOversizedDuration(ZSTD_DStream *zds, size_t const neededInBuffSize, size_t const neededOutBuffSize)
static size_t ZSTD_checkOutBuffer(ZSTD_DStream const *zds, ZSTD_outBuffer const *output)
static int ZSTD_DCtx_isOversizedTooLong(ZSTD_DStream *zds)
static size_t ZSTD_nextSrcSizeToDecompressWithInputSize(ZSTD_DCtx *dctx, size_t inputSize)
size_t ZSTD_findFrameCompressedSize(const void *src, size_t srcSize)
#define ZSTD_NO_FORWARD_PROGRESS_MAX
@ ZSTD_obm_buffered
@ ZSTDds_skipFrame
@ ZSTDds_decodeBlockHeader
#define ZSTD_WINDOWLOG_ABSOLUTEMIN
MEM_STATIC size_t ZSTD_limitCopy(void *dst, size_t dstCapacity, const void *src, size_t srcSize)
#define ZSTD_FRAMEIDSIZE

Referenced by zstd_decompress(), and ZSTD_decompressStream_simpleArgs().

◆ ZSTD_dParam_getBounds()

ZSTDLIB_API ZSTD_bounds ZSTD_dParam_getBounds ( ZSTD_dParameter  dParam)

ZSTD_dParam_getBounds() : All parameters must belong to an interval with lower and upper bounds, otherwise they will either trigger an error or be automatically clamped.

Returns
: a structure, ZSTD_bounds, which contains
  • an error status field, which must be tested using ZSTD_isError()
  • both lower and upper bounds, inclusive

Definition at line 1400 of file zstd_decompress.c.

1401{
1402 ZSTD_bounds bounds = { 0, 0, 0 };
1403 switch(dParam) {
1406 bounds.upperBound = ZSTD_WINDOWLOG_MAX;
1407 return bounds;
1408 case ZSTD_d_format:
1409 bounds.lowerBound = (int)ZSTD_f_zstd1;
1410 bounds.upperBound = (int)ZSTD_f_zstd1_magicless;
1411 ZSTD_STATIC_ASSERT(ZSTD_f_zstd1 < ZSTD_f_zstd1_magicless);
1412 return bounds;
1413 case ZSTD_d_stableOutBuffer:
1415 bounds.upperBound = (int)ZSTD_obm_stable;
1416 return bounds;
1417 default:;
1418 }
1419 bounds.error = ERROR(parameter_unsupported);
1420 return bounds;
1421}
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31

Referenced by ZSTD_DCtx_setMaxWindowSize(), and ZSTD_dParam_withinBounds().

◆ ZSTD_DStreamInSize()

ZSTDLIB_API size_t ZSTD_DStreamInSize ( void  )

recommended size for input buffer

Definition at line 1289 of file zstd_decompress.c.

◆ ZSTD_DStreamOutSize()

ZSTDLIB_API size_t ZSTD_DStreamOutSize ( void  )

recommended size for output buffer. Guarantee to successfully flush at least one complete block in all circumstances.

Definition at line 1290 of file zstd_decompress.c.

1290{ return ZSTD_BLOCKSIZE_MAX; }

◆ ZSTD_endStream()

ZSTDLIB_API size_t ZSTD_endStream ( ZSTD_CStream zcs,
ZSTD_outBuffer output 
)

Equivalent to ZSTD_compressStream2(zcs, output, &emptyInput, ZSTD_e_end).

Definition at line 4097 of file zstd_compress.c.

4098{
4099 ZSTD_inBuffer input = { NULL, 0, 0 };
4100 size_t const remainingToFlush = ZSTD_compressStream2(zcs, output, &input, ZSTD_e_end);
4101 FORWARD_IF_ERROR( remainingToFlush , "ZSTD_compressStream2 failed");
4102 if (zcs->appliedParams.nbWorkers > 0) return remainingToFlush; /* minimal estimation */
4103 /* single thread mode : attempt to calculate remaining to flush more precisely */
4104 { size_t const lastBlockSize = zcs->frameEnded ? 0 : ZSTD_BLOCKHEADERSIZE;
4105 size_t const checksumSize = (size_t)(zcs->frameEnded ? 0 : zcs->appliedParams.fParams.checksumFlag * 4);
4106 size_t const toFlush = remainingToFlush + lastBlockSize + checksumSize;
4107 DEBUGLOG(4, "ZSTD_endStream : remaining to flush : %u", (unsigned)toFlush);
4108 return toFlush;
4109 }
4110}
#define ZSTD_BLOCKHEADERSIZE

Referenced by zstd_compress().

◆ ZSTD_findFrameCompressedSize()

ZSTDLIB_API size_t ZSTD_findFrameCompressedSize ( const void src,
size_t  srcSize 
)

ZSTD_findFrameCompressedSize() : src should point to the start of a ZSTD frame or skippable frame. srcSize must be >= first frame size

Returns
: the compressed size of the first frame starting at src, suitable to pass as srcSize to ZSTD_decompress or similar, or an error code if input is invalid

ZSTD_findFrameCompressedSize() : compatible with legacy mode src must point to the start of a ZSTD frame, ZSTD legacy frame, or skippable frame srcSize must be at least as large as the frame contained

Returns
: the compressed size of the frame starting at src

Definition at line 532 of file zstd_decompress.c.

533{
534 ZSTD_frameSizeInfo const frameSizeInfo = ZSTD_findFrameSizeInfo(src, srcSize);
535 return frameSizeInfo.compressedSize;
536}
static ZSTD_frameSizeInfo ZSTD_findFrameSizeInfo(const void *src, size_t srcSize)

Referenced by ZSTD_decompressStream(), and ZSTD_findDecompressedSize().

◆ ZSTD_flushStream()

ZSTDLIB_API size_t ZSTD_flushStream ( ZSTD_CStream zcs,
ZSTD_outBuffer output 
)

Equivalent to ZSTD_compressStream2(zcs, output, &emptyInput, ZSTD_e_flush).

ZSTD_flushStream() :

Returns
: amount of data remaining to flush

Definition at line 4090 of file zstd_compress.c.

4091{
4092 ZSTD_inBuffer input = { NULL, 0, 0 };
4093 return ZSTD_compressStream2(zcs, output, &input, ZSTD_e_flush);
4094}

◆ ZSTD_freeCCtx()

ZSTDLIB_API size_t ZSTD_freeCCtx ( ZSTD_CCtx cctx)

Definition at line 147 of file zstd_compress.c.

148{
149 if (cctx==NULL) return 0; /* support free on NULL */
150 RETURN_ERROR_IF(cctx->staticSize, memory_allocation,
151 "not compatible with static CCtx");
152 {
153 int cctxInWorkspace = ZSTD_cwksp_owns_buffer(&cctx->workspace, cctx);
155 if (!cctxInWorkspace) {
156 ZSTD_free(cctx, cctx->customMem);
157 }
158 }
159 return 0;
160}
MEM_STATIC int ZSTD_cwksp_owns_buffer(const ZSTD_cwksp *ws, const void *ptr)
Definition: zstd_cwksp.h:217

Referenced by ZSTD_freeCStream().

◆ ZSTD_freeCDict()

ZSTDLIB_API size_t ZSTD_freeCDict ( ZSTD_CDict CDict)

ZSTD_freeCDict() : Function frees memory allocated by ZSTD_createCDict().

Definition at line 3466 of file zstd_compress.c.

3467{
3468 if (cdict==NULL) return 0; /* support free on NULL */
3469 { ZSTD_customMem const cMem = cdict->customMem;
3470 int cdictInWorkspace = ZSTD_cwksp_owns_buffer(&cdict->workspace, cdict);
3471 ZSTD_cwksp_free(&cdict->workspace, cMem);
3472 if (!cdictInWorkspace) {
3473 ZSTD_free(cdict, cMem);
3474 }
3475 return 0;
3476 }
3477}
MEM_STATIC void ZSTD_cwksp_free(ZSTD_cwksp *ws, ZSTD_customMem customMem)
Definition: zstd_cwksp.h:466

Referenced by ZSTD_clearAllDicts(), and ZSTD_createCDict_advanced().

◆ ZSTD_freeCStream()

ZSTDLIB_API size_t ZSTD_freeCStream ( ZSTD_CStream zcs)

Definition at line 3627 of file zstd_compress.c.

3628{
3629 return ZSTD_freeCCtx(zcs); /* same object */
3630}
size_t ZSTD_freeCCtx(ZSTD_CCtx *cctx)

Referenced by zstd_compress().

◆ ZSTD_freeDCtx()

ZSTDLIB_API size_t ZSTD_freeDCtx ( ZSTD_DCtx dctx)

Definition at line 161 of file zstd_decompress.c.

162{
163 if (dctx==NULL) return 0; /* support free on NULL */
164 RETURN_ERROR_IF(dctx->staticSize, memory_allocation, "not compatible with static DCtx");
165 { ZSTD_customMem const cMem = dctx->customMem;
166 ZSTD_clearDict(dctx);
167 ZSTD_free(dctx->inBuff, cMem);
168 dctx->inBuff = NULL;
169#if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT >= 1)
170 if (dctx->legacyContext)
171 ZSTD_freeLegacyStreamContext(dctx->legacyContext, dctx->previousLegacyVersion);
172#endif
173 ZSTD_free(dctx, cMem);
174 return 0;
175 }
176}

Referenced by ZSTD_decompress(), and ZSTD_freeDStream().

◆ ZSTD_freeDDict()

ZSTDLIB_API size_t ZSTD_freeDDict ( ZSTD_DDict ddict)

ZSTD_freeDDict() : Function frees memory allocated with ZSTD_createDDict()

Definition at line 212 of file zstd_ddict.c.

213{
214 if (ddict==NULL) return 0; /* support free on NULL */
215 { ZSTD_customMem const cMem = ddict->cMem;
216 ZSTD_free(ddict->dictBuffer, cMem);
217 ZSTD_free(ddict, cMem);
218 return 0;
219 }
220}
void * dictBuffer
Definition: zstd_ddict.c:37
ZSTD_customMem cMem
Definition: zstd_ddict.c:43

Referenced by ZSTD_clearDict(), and ZSTD_createDDict_advanced().

◆ ZSTD_freeDStream()

ZSTDLIB_API size_t ZSTD_freeDStream ( ZSTD_DStream zds)

Definition at line 1281 of file zstd_decompress.c.

1282{
1283 return ZSTD_freeDCtx(zds);
1284}

Referenced by zstd_decompress().

◆ ZSTD_getDecompressedSize()

ZSTDLIB_API unsigned long long ZSTD_getDecompressedSize ( const void src,
size_t  srcSize 
)

ZSTD_getDecompressedSize() : NOTE: This function is now obsolete, in favor of ZSTD_getFrameContentSize(). Both functions work the same way, but ZSTD_getDecompressedSize() blends "empty", "unknown" and "error" results to the same return value (0), while ZSTD_getFrameContentSize() gives them separate return values.

Returns
: decompressed size of src frame content if known and not empty, 0 otherwise.

ZSTD_getDecompressedSize() : compatible with legacy mode

Returns
: decompressed size if known, 0 otherwise note : 0 can mean any of the following :
  • frame content is empty
  • decompressed size field is not present in frame header
  • frame header unknown / not supported
  • frame header not complete (srcSize too small)

Definition at line 426 of file zstd_decompress.c.

427{
428 unsigned long long const ret = ZSTD_getFrameContentSize(src, srcSize);
430 return (ret >= ZSTD_CONTENTSIZE_ERROR) ? 0 : ret;
431}
int ret
#define ZSTD_CONTENTSIZE_ERROR
Definition: zstd.h:153
unsigned long long ZSTD_getFrameContentSize(const void *src, size_t srcSize)

◆ ZSTD_getDictID_fromDDict()

ZSTDLIB_API unsigned ZSTD_getDictID_fromDDict ( const ZSTD_DDict ddict)

ZSTD_getDictID_fromDDict() : Provides the dictID of the dictionary loaded into ddict. If

Returns
== 0, the dictionary is not conformant to Zstandard specification, or empty. Non-conformant dictionaries can still be loaded, but as content-only dictionaries.

Definition at line 240 of file zstd_ddict.c.

241{
242 if (ddict==NULL) return 0;
243 return ZSTD_getDictID_fromDict(ddict->dictContent, ddict->dictSize);
244}
size_t dictSize
Definition: zstd_ddict.c:39
const void * dictContent
Definition: zstd_ddict.c:38
ZSTDLIB_API unsigned ZSTD_getDictID_fromDict(const void *dict, size_t dictSize)

◆ ZSTD_getDictID_fromDict()

ZSTDLIB_API unsigned ZSTD_getDictID_fromDict ( const void dict,
size_t  dictSize 
)

ZSTD_getDictID_fromDict() : Provides the dictID stored within dictionary. if

Returns
== 0, the dictionary is not conformant with Zstandard specification. It can still be loaded, but as a content-only dictionary.

Definition at line 1217 of file zstd_decompress.c.

1218{
1219 if (dictSize < 8) return 0;
1220 if (MEM_readLE32(dict) != ZSTD_MAGIC_DICTIONARY) return 0;
1221 return MEM_readLE32((const char*)dict + ZSTD_FRAMEIDSIZE);
1222}
#define ZSTD_MAGIC_DICTIONARY
Definition: zstd.h:99

Referenced by ZSTD_getDictID_fromDDict().

◆ ZSTD_getDictID_fromFrame()

ZSTDLIB_API unsigned ZSTD_getDictID_fromFrame ( const void src,
size_t  srcSize 
)

ZSTD_getDictID_fromFrame() : Provides the dictID required to decompressed the frame stored within src. If

Returns
== 0, the dictID could not be decoded. This could for one of the following reasons :
  • The frame does not require a dictionary to be decoded (most common case).
  • The frame was built with dictID intentionally removed. Whatever dictionary is necessary is a hidden information. Note : this use case also happens when using a non-conformant dictionary.
  • srcSize is too small, and as a result, the frame header could not be decoded (only possible if srcSize < ZSTD_FRAMEHEADERSIZE_MAX).
  • This is not a Zstandard frame. When identifying the exact failure cause, it's possible to use ZSTD_getFrameHeader(), which will provide a more precise error code.

ZSTD_getDictID_fromFrame() : Provides the dictID required to decompress frame stored within src. If

Returns
== 0, the dictID could not be decoded. This could for one of the following reasons :
  • The frame does not require a dictionary (most common case).
  • The frame was built with dictID intentionally removed. Needed dictionary is a hidden information. Note : this use case also happens when using a non-conformant dictionary.
  • srcSize is too small, and as a result, frame header could not be decoded. Note : possible if srcSize < ZSTD_FRAMEHEADERSIZE_MAX.
  • This is not a Zstandard frame. When identifying the exact failure cause, it's possible to use ZSTD_getFrameHeader(), which will provide a more precise error code.

Definition at line 1237 of file zstd_decompress.c.

1238{
1239 ZSTD_frameHeader zfp = { 0, 0, 0, ZSTD_frame, 0, 0, 0 };
1240 size_t const hError = ZSTD_getFrameHeader(&zfp, src, srcSize);
1241 if (ZSTD_isError(hError)) return 0;
1242 return zfp.dictID;
1243}
size_t ZSTD_getFrameHeader(ZSTD_frameHeader *zfhPtr, const void *src, size_t srcSize)

◆ ZSTD_getErrorName()

ZSTDLIB_API const char * ZSTD_getErrorName ( size_t  code)

provides readable string from an error code

ZSTD_getErrorName() : provides error code string from function result (useful for debugging)

Definition at line 41 of file zstd_common.c.

41{ return ERR_getErrorName(code); }
ERR_STATIC const char * ERR_getErrorName(size_t code)
Definition: error_private.h:71
Definition: inflate.c:139

Referenced by zstd_compress(), ZSTD_compressSubBlock_literal(), and zstd_decompress().

◆ ZSTD_getFrameContentSize()

ZSTDLIB_API unsigned long long ZSTD_getFrameContentSize ( const void src,
size_t  srcSize 
)

ZSTD_getFrameContentSize() : compatible with legacy mode

Returns
: decompressed size of the single frame pointed to be src if known, otherwise
  • ZSTD_CONTENTSIZE_UNKNOWN if the size cannot be determined
  • ZSTD_CONTENTSIZE_ERROR if an error occurred (e.g. invalid magic number, srcSize too small)

Definition at line 337 of file zstd_decompress.c.

338{
339#if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT >= 1)
340 if (ZSTD_isLegacy(src, srcSize)) {
341 unsigned long long const ret = ZSTD_getDecompressedSize_legacy(src, srcSize);
342 return ret == 0 ? ZSTD_CONTENTSIZE_UNKNOWN : ret;
343 }
344#endif
345 { ZSTD_frameHeader zfh;
346 if (ZSTD_getFrameHeader(&zfh, src, srcSize) != 0)
348 if (zfh.frameType == ZSTD_skippableFrame) {
349 return 0;
350 } else {
351 return zfh.frameContentSize;
352 } }
353}

Referenced by ZSTD_findDecompressedSize(), and ZSTD_getDecompressedSize().

◆ ZSTD_initCStream()

ZSTDLIB_API size_t ZSTD_initCStream ( ZSTD_CStream zcs,
int  compressionLevel 
)

Equivalent to:

ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
ZSTD_CCtx_refCDict(zcs, NULL); // clear the dictionary (if any)
ZSTD_CCtx_setParameter(zcs, ZSTD_c_compressionLevel, compressionLevel);

Definition at line 3781 of file zstd_compress.c.

3782{
3783 DEBUGLOG(4, "ZSTD_initCStream");
3787 return 0;
3788}
size_t ZSTD_CCtx_setParameter(ZSTD_CCtx *cctx, ZSTD_cParameter param, int value)
size_t ZSTD_CCtx_refCDict(ZSTD_CCtx *cctx, const ZSTD_CDict *cdict)

◆ ZSTD_initDStream()

ZSTDLIB_API size_t ZSTD_initDStream ( ZSTD_DStream zds)

Definition at line 1343 of file zstd_decompress.c.

1344{
1345 DEBUGLOG(4, "ZSTD_initDStream");
1346 return ZSTD_initDStream_usingDDict(zds, NULL);
1347}
size_t ZSTD_initDStream_usingDDict(ZSTD_DStream *dctx, const ZSTD_DDict *ddict)

Referenced by zstd_decompress().

◆ ZSTD_isError()

ZSTDLIB_API unsigned ZSTD_isError ( size_t  code)

tells if a size_t function result is an error code

ZSTD_isError() : tells if a return value is an error code symbol is required for external callers

Definition at line 37 of file zstd_common.c.

37{ return ERR_isError(code); }
ERR_STATIC unsigned ERR_isError(size_t code)
Definition: error_private.h:56

◆ ZSTD_maxCLevel()

ZSTDLIB_API int ZSTD_maxCLevel ( void  )

maximum compression level available

Definition at line 4116 of file zstd_compress.c.

4116{ return ZSTD_MAX_CLEVEL; }
#define ZSTD_MAX_CLEVEL

Referenced by registry_load_volume_options(), and ZSTD_cParam_getBounds().

◆ ZSTD_minCLevel()

ZSTDLIB_API int ZSTD_minCLevel ( void  )

minimum negative compression level allowed

Definition at line 4117 of file zstd_compress.c.

4117{ return (int)-ZSTD_TARGETLENGTH_MAX; }

Referenced by ZSTD_cParam_getBounds().

◆ ZSTD_sizeof_CCtx()

ZSTDLIB_API size_t ZSTD_sizeof_CCtx ( const ZSTD_CCtx cctx)

ZSTD_sizeof_*() : These functions give the current memory usage of selected object. Note that object memory usage can evolve (increase or decrease) over time.

Definition at line 174 of file zstd_compress.c.

175{
176 if (cctx==NULL) return 0; /* support sizeof on NULL */
177 /* cctx may be in the workspace */
178 return (cctx->workspace.workspace == cctx ? 0 : sizeof(*cctx))
181 + ZSTD_sizeof_mtctx(cctx);
182}
ZSTD_localDict localDict
void * workspace
Definition: zstd_cwksp.h:132
static size_t ZSTD_sizeof_localDict(ZSTD_localDict dict)
static size_t ZSTD_sizeof_mtctx(const ZSTD_CCtx *cctx)
MEM_STATIC size_t ZSTD_cwksp_sizeof(const ZSTD_cwksp *ws)
Definition: zstd_cwksp.h:482

Referenced by ZSTD_sizeof_CStream().

◆ ZSTD_sizeof_CDict()

ZSTDLIB_API size_t ZSTD_sizeof_CDict ( const ZSTD_CDict cdict)

Definition at line 3342 of file zstd_compress.c.

3343{
3344 if (cdict==NULL) return 0; /* support sizeof on NULL */
3345 DEBUGLOG(5, "sizeof(*cdict) : %u", (unsigned)sizeof(*cdict));
3346 /* cdict may be in the workspace */
3347 return (cdict->workspace.workspace == cdict ? 0 : sizeof(*cdict))
3348 + ZSTD_cwksp_sizeof(&cdict->workspace);
3349}
ZSTD_cwksp workspace
Definition: zstd_compress.c:56

Referenced by ZSTD_sizeof_localDict().

◆ ZSTD_sizeof_CStream()

ZSTDLIB_API size_t ZSTD_sizeof_CStream ( const ZSTD_CStream zcs)

Definition at line 184 of file zstd_compress.c.

185{
186 return ZSTD_sizeof_CCtx(zcs); /* same object */
187}
size_t ZSTD_sizeof_CCtx(const ZSTD_CCtx *cctx)

◆ ZSTD_sizeof_DCtx()

ZSTDLIB_API size_t ZSTD_sizeof_DCtx ( const ZSTD_DCtx dctx)

Definition at line 78 of file zstd_decompress.c.

79{
80 if (dctx==NULL) return 0; /* support sizeof NULL */
81 return sizeof(*dctx)
83 + dctx->inBuffSize + dctx->outBuffSize;
84}
ZSTDLIB_API size_t ZSTD_sizeof_DDict(const ZSTD_DDict *ddict)
Definition: zstd_ddict.c:230

Referenced by ZSTD_sizeof_DStream().

◆ ZSTD_sizeof_DDict()

ZSTDLIB_API size_t ZSTD_sizeof_DDict ( const ZSTD_DDict ddict)

Definition at line 230 of file zstd_ddict.c.

231{
232 if (ddict==NULL) return 0; /* support sizeof on NULL */
233 return sizeof(*ddict) + (ddict->dictBuffer ? ddict->dictSize : 0) ;
234}

Referenced by ZSTD_sizeof_DCtx().

◆ ZSTD_sizeof_DStream()

ZSTDLIB_API size_t ZSTD_sizeof_DStream ( const ZSTD_DStream zds)

Definition at line 1479 of file zstd_decompress.c.

1480{
1481 return ZSTD_sizeof_DCtx(dctx);
1482}
size_t ZSTD_sizeof_DCtx(const ZSTD_DCtx *dctx)

◆ ZSTD_versionNumber()

ZSTDLIB_API unsigned ZSTD_versionNumber ( void  )

to check runtime library version

Definition at line 25 of file zstd_common.c.

25{ return ZSTD_VERSION_NUMBER; }
#define ZSTD_VERSION_NUMBER
Definition: zstd.h:77

◆ ZSTD_versionString()

ZSTDLIB_API const char * ZSTD_versionString ( void  )

Definition at line 27 of file zstd_common.c.

27{ return ZSTD_VERSION_STRING; }
#define ZSTD_VERSION_STRING
Definition: zstd.h:83