ToolDAQFramework
zstd.h
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  * All rights reserved.
4  *
5  * This source code is licensed under both the BSD-style license (found in the
6  * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7  * in the COPYING file in the root directory of this source tree).
8  * You may select, at your option, one of the above-listed licenses.
9  */
10 
11 #ifndef ZSTD_H_235446
12 #define ZSTD_H_235446
13 
14 
15 /* ====== Dependencies ======*/
16 #include <stddef.h> /* size_t */
17 
18 #include "zstd_errors.h" /* list of errors */
19 #if defined(ZSTD_STATIC_LINKING_ONLY) && !defined(ZSTD_H_ZSTD_STATIC_LINKING_ONLY)
20 #include <limits.h> /* INT_MAX */
21 #endif /* ZSTD_STATIC_LINKING_ONLY */
22 
23 #if defined (__cplusplus)
24 extern "C" {
25 #endif
26 
27 /* ===== ZSTDLIB_API : control library symbols visibility ===== */
28 #ifndef ZSTDLIB_VISIBLE
29  /* Backwards compatibility with old macro name */
30 # ifdef ZSTDLIB_VISIBILITY
31 # define ZSTDLIB_VISIBLE ZSTDLIB_VISIBILITY
32 # elif defined(__GNUC__) && (__GNUC__ >= 4) && !defined(__MINGW32__)
33 # define ZSTDLIB_VISIBLE __attribute__ ((visibility ("default")))
34 # else
35 # define ZSTDLIB_VISIBLE
36 # endif
37 #endif
38 
39 #ifndef ZSTDLIB_HIDDEN
40 # if defined(__GNUC__) && (__GNUC__ >= 4) && !defined(__MINGW32__)
41 # define ZSTDLIB_HIDDEN __attribute__ ((visibility ("hidden")))
42 # else
43 # define ZSTDLIB_HIDDEN
44 # endif
45 #endif
46 
47 #if defined(ZSTD_DLL_EXPORT) && (ZSTD_DLL_EXPORT==1)
48 # define ZSTDLIB_API __declspec(dllexport) ZSTDLIB_VISIBLE
49 #elif defined(ZSTD_DLL_IMPORT) && (ZSTD_DLL_IMPORT==1)
50 # define ZSTDLIB_API __declspec(dllimport) ZSTDLIB_VISIBLE /* It isn't required but allows to generate better code, saving a function pointer load from the IAT and an indirect jump.*/
51 #else
52 # define ZSTDLIB_API ZSTDLIB_VISIBLE
53 #endif
54 
55 /* Deprecation warnings :
56  * Should these warnings be a problem, it is generally possible to disable them,
57  * typically with -Wno-deprecated-declarations for gcc or _CRT_SECURE_NO_WARNINGS in Visual.
58  * Otherwise, it's also possible to define ZSTD_DISABLE_DEPRECATE_WARNINGS.
59  */
60 #ifdef ZSTD_DISABLE_DEPRECATE_WARNINGS
61 # define ZSTD_DEPRECATED(message) /* disable deprecation warnings */
62 #else
63 # if defined (__cplusplus) && (__cplusplus >= 201402) /* C++14 or greater */
64 # define ZSTD_DEPRECATED(message) [[deprecated(message)]]
65 # elif (defined(GNUC) && (GNUC > 4 || (GNUC == 4 && GNUC_MINOR >= 5))) || defined(__clang__) || defined(__IAR_SYSTEMS_ICC__)
66 # define ZSTD_DEPRECATED(message) __attribute__((deprecated(message)))
67 # elif defined(__GNUC__) && (__GNUC__ >= 3)
68 # define ZSTD_DEPRECATED(message) __attribute__((deprecated))
69 # elif defined(_MSC_VER)
70 # define ZSTD_DEPRECATED(message) __declspec(deprecated(message))
71 # else
72 # pragma message("WARNING: You need to implement ZSTD_DEPRECATED for this compiler")
73 # define ZSTD_DEPRECATED(message)
74 # endif
75 #endif /* ZSTD_DISABLE_DEPRECATE_WARNINGS */
76 
77 
78 /*******************************************************************************
79  Introduction
80 
81  zstd, short for Zstandard, is a fast lossless compression algorithm, targeting
82  real-time compression scenarios at zlib-level and better compression ratios.
83  The zstd compression library provides in-memory compression and decompression
84  functions.
85 
86  The library supports regular compression levels from 1 up to ZSTD_maxCLevel(),
87  which is currently 22. Levels >= 20, labeled `--ultra`, should be used with
88  caution, as they require more memory. The library also offers negative
89  compression levels, which extend the range of speed vs. ratio preferences.
90  The lower the level, the faster the speed (at the cost of compression).
91 
92  Compression can be done in:
93  - a single step (described as Simple API)
94  - a single step, reusing a context (described as Explicit context)
95  - unbounded multiple steps (described as Streaming compression)
96 
97  The compression ratio achievable on small data can be highly improved using
98  a dictionary. Dictionary compression can be performed in:
99  - a single step (described as Simple dictionary API)
100  - a single step, reusing a dictionary (described as Bulk-processing
101  dictionary API)
102 
103  Advanced experimental functions can be accessed using
104  `#define ZSTD_STATIC_LINKING_ONLY` before including zstd.h.
105 
106  Advanced experimental APIs should never be used with a dynamically-linked
107  library. They are not "stable"; their definitions or signatures may change in
108  the future. Only static linking is allowed.
109 *******************************************************************************/
110 
111 /*------ Version ------*/
112 #define ZSTD_VERSION_MAJOR 1
113 #define ZSTD_VERSION_MINOR 5
114 #define ZSTD_VERSION_RELEASE 8
115 #define ZSTD_VERSION_NUMBER (ZSTD_VERSION_MAJOR *100*100 + ZSTD_VERSION_MINOR *100 + ZSTD_VERSION_RELEASE)
116 
119 ZSTDLIB_API unsigned ZSTD_versionNumber(void);
120 
121 #define ZSTD_LIB_VERSION ZSTD_VERSION_MAJOR.ZSTD_VERSION_MINOR.ZSTD_VERSION_RELEASE
122 #define ZSTD_QUOTE(str) #str
123 #define ZSTD_EXPAND_AND_QUOTE(str) ZSTD_QUOTE(str)
124 #define ZSTD_VERSION_STRING ZSTD_EXPAND_AND_QUOTE(ZSTD_LIB_VERSION)
125 
128 ZSTDLIB_API const char* ZSTD_versionString(void);
129 
130 /* *************************************
131  * Default constant
132  ***************************************/
133 #ifndef ZSTD_CLEVEL_DEFAULT
134 # define ZSTD_CLEVEL_DEFAULT 3
135 #endif
136 
137 /* *************************************
138  * Constants
139  ***************************************/
140 
141 /* All magic numbers are supposed read/written to/from files/memory using little-endian convention */
142 #define ZSTD_MAGICNUMBER 0xFD2FB528 /* valid since v0.8.0 */
143 #define ZSTD_MAGIC_DICTIONARY 0xEC30A437 /* valid since v0.7.0 */
144 #define ZSTD_MAGIC_SKIPPABLE_START 0x184D2A50 /* all 16 values, from 0x184D2A50 to 0x184D2A5F, signal the beginning of a skippable frame */
145 #define ZSTD_MAGIC_SKIPPABLE_MASK 0xFFFFFFF0
146 const unsigned char ZSTD_MAGIC_BYTES[4] = {0x28,0xB5,0x2F,0xFD}; // ZSTD_MAGICNUMBER from zstd.h BUT REVERSED!
147 // used to check if a byte array is compressed
148 
149 #define ZSTD_BLOCKSIZELOG_MAX 17
150 #define ZSTD_BLOCKSIZE_MAX (1<<ZSTD_BLOCKSIZELOG_MAX)
151 
152 
153 /***************************************
154 * Simple Core API
155 ***************************************/
162 ZSTDLIB_API size_t ZSTD_compress( void* dst, size_t dstCapacity,
163  const void* src, size_t srcSize,
164  int compressionLevel);
165 
175 ZSTDLIB_API size_t ZSTD_decompress( void* dst, size_t dstCapacity,
176  const void* src, size_t compressedSize);
177 
178 
179 /*====== Decompression helper functions ======*/
180 
205 #define ZSTD_CONTENTSIZE_UNKNOWN (0ULL - 1)
206 #define ZSTD_CONTENTSIZE_ERROR (0ULL - 2)
207 ZSTDLIB_API unsigned long long ZSTD_getFrameContentSize(const void *src, size_t srcSize);
208 
215 ZSTD_DEPRECATED("Replaced by ZSTD_getFrameContentSize")
216 ZSTDLIB_API unsigned long long ZSTD_getDecompressedSize(const void* src, size_t srcSize);
217 
229 ZSTDLIB_API size_t ZSTD_findFrameCompressedSize(const void* src, size_t srcSize);
230 
231 
232 /*====== Compression helper functions ======*/
233 
250 #define ZSTD_MAX_INPUT_SIZE ((sizeof(size_t)==8) ? 0xFF00FF00FF00FF00ULL : 0xFF00FF00U)
251 #define ZSTD_COMPRESSBOUND(srcSize) (((size_t)(srcSize) >= ZSTD_MAX_INPUT_SIZE) ? 0 : (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 */
252 ZSTDLIB_API size_t ZSTD_compressBound(size_t srcSize);
255 /*====== Error helper functions ======*/
256 /* ZSTD_isError() :
257  * Most ZSTD_* functions returning a size_t value can be tested for error,
258  * using ZSTD_isError().
259  * @return 1 if error, 0 otherwise
260  */
261 ZSTDLIB_API unsigned ZSTD_isError(size_t result);
262 ZSTDLIB_API ZSTD_ErrorCode ZSTD_getErrorCode(size_t functionResult); /* convert a result into an error code, which can be compared to error enum list */
263 ZSTDLIB_API const char* ZSTD_getErrorName(size_t result);
264 ZSTDLIB_API int ZSTD_minCLevel(void);
265 ZSTDLIB_API int ZSTD_maxCLevel(void);
266 ZSTDLIB_API int ZSTD_defaultCLevel(void);
269 /***************************************
270 * Explicit context
271 ***************************************/
272 /*= Compression context
273  * When compressing many times,
274  * it is recommended to allocate a compression context just once,
275  * and reuse it for each successive compression operation.
276  * This will make the workload easier for system's memory.
277  * Note : re-using context is just a speed / resource optimization.
278  * It doesn't change the compression ratio, which remains identical.
279  * Note 2: For parallel execution in multi-threaded environments,
280  * use one different context per thread .
281  */
282 typedef struct ZSTD_CCtx_s ZSTD_CCtx;
283 ZSTDLIB_API ZSTD_CCtx* ZSTD_createCCtx(void);
284 ZSTDLIB_API size_t ZSTD_freeCCtx(ZSTD_CCtx* cctx); /* compatible with NULL pointer */
285 
294 ZSTDLIB_API size_t ZSTD_compressCCtx(ZSTD_CCtx* cctx,
295  void* dst, size_t dstCapacity,
296  const void* src, size_t srcSize,
297  int compressionLevel);
298 
299 /*= Decompression context
300  * When decompressing many times,
301  * it is recommended to allocate a context only once,
302  * and reuse it for each successive compression operation.
303  * This will make workload friendlier for system's memory.
304  * Use one context per thread for parallel execution. */
305 typedef struct ZSTD_DCtx_s ZSTD_DCtx;
306 ZSTDLIB_API ZSTD_DCtx* ZSTD_createDCtx(void);
307 ZSTDLIB_API size_t ZSTD_freeDCtx(ZSTD_DCtx* dctx); /* accept NULL pointer */
308 
314 ZSTDLIB_API size_t ZSTD_decompressDCtx(ZSTD_DCtx* dctx,
315  void* dst, size_t dstCapacity,
316  const void* src, size_t srcSize);
317 
318 
319 /*********************************************
320 * Advanced compression API (Requires v1.4.0+)
321 **********************************************/
322 
323 /* API design :
324  * Parameters are pushed one by one into an existing context,
325  * using ZSTD_CCtx_set*() functions.
326  * Pushed parameters are sticky : they are valid for next compressed frame, and any subsequent frame.
327  * "sticky" parameters are applicable to `ZSTD_compress2()` and `ZSTD_compressStream*()` !
328  * __They do not apply to one-shot variants such as ZSTD_compressCCtx()__ .
329  *
330  * It's possible to reset all parameters to "default" using ZSTD_CCtx_reset().
331  *
332  * This API supersedes all other "advanced" API entry points in the experimental section.
333  * In the future, we expect to remove API entry points from experimental which are redundant with this API.
334  */
335 
336 
337 /* Compression strategies, listed from fastest to strongest */
338 typedef enum { ZSTD_fast=1,
339  ZSTD_dfast=2,
340  ZSTD_greedy=3,
341  ZSTD_lazy=4,
342  ZSTD_lazy2=5,
343  ZSTD_btlazy2=6,
344  ZSTD_btopt=7,
345  ZSTD_btultra=8,
346  ZSTD_btultra2=9
347  /* note : new strategies _might_ be added in the future.
348  Only the order (from fast to strong) is guaranteed */
349 } ZSTD_strategy;
350 
351 typedef enum {
352 
353  /* compression parameters
354  * Note: When compressing with a ZSTD_CDict these parameters are superseded
355  * by the parameters used to construct the ZSTD_CDict.
356  * See ZSTD_CCtx_refCDict() for more info (superseded-by-cdict). */
357  ZSTD_c_compressionLevel=100, /* Set compression parameters according to pre-defined cLevel table.
358  * Note that exact compression parameters are dynamically determined,
359  * depending on both compression level and srcSize (when known).
360  * Default level is ZSTD_CLEVEL_DEFAULT==3.
361  * Special: value 0 means default, which is controlled by ZSTD_CLEVEL_DEFAULT.
362  * Note 1 : it's possible to pass a negative compression level.
363  * Note 2 : setting a level does not automatically set all other compression parameters
364  * to default. Setting this will however eventually dynamically impact the compression
365  * parameters which have not been manually set. The manually set
366  * ones will 'stick'. */
367  /* Advanced compression parameters :
368  * It's possible to pin down compression parameters to some specific values.
369  * In which case, these values are no longer dynamically selected by the compressor */
370  ZSTD_c_windowLog=101, /* Maximum allowed back-reference distance, expressed as power of 2.
371  * This will set a memory budget for streaming decompression,
372  * with larger values requiring more memory
373  * and typically compressing more.
374  * Must be clamped between ZSTD_WINDOWLOG_MIN and ZSTD_WINDOWLOG_MAX.
375  * Special: value 0 means "use default windowLog".
376  * Note: Using a windowLog greater than ZSTD_WINDOWLOG_LIMIT_DEFAULT
377  * requires explicitly allowing such size at streaming decompression stage. */
378  ZSTD_c_hashLog=102, /* Size of the initial probe table, as a power of 2.
379  * Resulting memory usage is (1 << (hashLog+2)).
380  * Must be clamped between ZSTD_HASHLOG_MIN and ZSTD_HASHLOG_MAX.
381  * Larger tables improve compression ratio of strategies <= dFast,
382  * and improve speed of strategies > dFast.
383  * Special: value 0 means "use default hashLog". */
384  ZSTD_c_chainLog=103, /* Size of the multi-probe search table, as a power of 2.
385  * Resulting memory usage is (1 << (chainLog+2)).
386  * Must be clamped between ZSTD_CHAINLOG_MIN and ZSTD_CHAINLOG_MAX.
387  * Larger tables result in better and slower compression.
388  * This parameter is useless for "fast" strategy.
389  * It's still useful when using "dfast" strategy,
390  * in which case it defines a secondary probe table.
391  * Special: value 0 means "use default chainLog". */
392  ZSTD_c_searchLog=104, /* Number of search attempts, as a power of 2.
393  * More attempts result in better and slower compression.
394  * This parameter is useless for "fast" and "dFast" strategies.
395  * Special: value 0 means "use default searchLog". */
396  ZSTD_c_minMatch=105, /* Minimum size of searched matches.
397  * Note that Zstandard can still find matches of smaller size,
398  * it just tweaks its search algorithm to look for this size and larger.
399  * Larger values increase compression and decompression speed, but decrease ratio.
400  * Must be clamped between ZSTD_MINMATCH_MIN and ZSTD_MINMATCH_MAX.
401  * Note that currently, for all strategies < btopt, effective minimum is 4.
402  * , for all strategies > fast, effective maximum is 6.
403  * Special: value 0 means "use default minMatchLength". */
404  ZSTD_c_targetLength=106, /* Impact of this field depends on strategy.
405  * For strategies btopt, btultra & btultra2:
406  * Length of Match considered "good enough" to stop search.
407  * Larger values make compression stronger, and slower.
408  * For strategy fast:
409  * Distance between match sampling.
410  * Larger values make compression faster, and weaker.
411  * Special: value 0 means "use default targetLength". */
412  ZSTD_c_strategy=107, /* See ZSTD_strategy enum definition.
413  * The higher the value of selected strategy, the more complex it is,
414  * resulting in stronger and slower compression.
415  * Special: value 0 means "use default strategy". */
416 
417  ZSTD_c_targetCBlockSize=130, /* v1.5.6+
418  * Attempts to fit compressed block size into approximately targetCBlockSize.
419  * Bound by ZSTD_TARGETCBLOCKSIZE_MIN and ZSTD_TARGETCBLOCKSIZE_MAX.
420  * Note that it's not a guarantee, just a convergence target (default:0).
421  * No target when targetCBlockSize == 0.
422  * This is helpful in low bandwidth streaming environments to improve end-to-end latency,
423  * when a client can make use of partial documents (a prominent example being Chrome).
424  * Note: this parameter is stable since v1.5.6.
425  * It was present as an experimental parameter in earlier versions,
426  * but it's not recommended using it with earlier library versions
427  * due to massive performance regressions.
428  */
429  /* LDM mode parameters */
430  ZSTD_c_enableLongDistanceMatching=160, /* Enable long distance matching.
431  * This parameter is designed to improve compression ratio
432  * for large inputs, by finding large matches at long distance.
433  * It increases memory usage and window size.
434  * Note: enabling this parameter increases default ZSTD_c_windowLog to 128 MB
435  * except when expressly set to a different value.
436  * Note: will be enabled by default if ZSTD_c_windowLog >= 128 MB and
437  * compression strategy >= ZSTD_btopt (== compression level 16+) */
438  ZSTD_c_ldmHashLog=161, /* Size of the table for long distance matching, as a power of 2.
439  * Larger values increase memory usage and compression ratio,
440  * but decrease compression speed.
441  * Must be clamped between ZSTD_HASHLOG_MIN and ZSTD_HASHLOG_MAX
442  * default: windowlog - 7.
443  * Special: value 0 means "automatically determine hashlog". */
444  ZSTD_c_ldmMinMatch=162, /* Minimum match size for long distance matcher.
445  * Larger/too small values usually decrease compression ratio.
446  * Must be clamped between ZSTD_LDM_MINMATCH_MIN and ZSTD_LDM_MINMATCH_MAX.
447  * Special: value 0 means "use default value" (default: 64). */
448  ZSTD_c_ldmBucketSizeLog=163, /* Log size of each bucket in the LDM hash table for collision resolution.
449  * Larger values improve collision resolution but decrease compression speed.
450  * The maximum value is ZSTD_LDM_BUCKETSIZELOG_MAX.
451  * Special: value 0 means "use default value" (default: 3). */
452  ZSTD_c_ldmHashRateLog=164, /* Frequency of inserting/looking up entries into the LDM hash table.
453  * Must be clamped between 0 and (ZSTD_WINDOWLOG_MAX - ZSTD_HASHLOG_MIN).
454  * Default is MAX(0, (windowLog - ldmHashLog)), optimizing hash table usage.
455  * Larger values improve compression speed.
456  * Deviating far from default value will likely result in a compression ratio decrease.
457  * Special: value 0 means "automatically determine hashRateLog". */
458 
459  /* frame parameters */
460  ZSTD_c_contentSizeFlag=200, /* Content size will be written into frame header _whenever known_ (default:1)
461  * Content size must be known at the beginning of compression.
462  * This is automatically the case when using ZSTD_compress2(),
463  * For streaming scenarios, content size must be provided with ZSTD_CCtx_setPledgedSrcSize() */
464  ZSTD_c_checksumFlag=201, /* A 32-bits checksum of content is written at end of frame (default:0) */
465  ZSTD_c_dictIDFlag=202, /* When applicable, dictionary's ID is written into frame header (default:1) */
466 
467  /* multi-threading parameters */
468  /* These parameters are only active if multi-threading is enabled (compiled with build macro ZSTD_MULTITHREAD).
469  * Otherwise, trying to set any other value than default (0) will be a no-op and return an error.
470  * In a situation where it's unknown if the linked library supports multi-threading or not,
471  * setting ZSTD_c_nbWorkers to any value >= 1 and consulting the return value provides a quick way to check this property.
472  */
473  ZSTD_c_nbWorkers=400, /* Select how many threads will be spawned to compress in parallel.
474  * When nbWorkers >= 1, triggers asynchronous mode when invoking ZSTD_compressStream*() :
475  * ZSTD_compressStream*() consumes input and flush output if possible, but immediately gives back control to caller,
476  * while compression is performed in parallel, within worker thread(s).
477  * (note : a strong exception to this rule is when first invocation of ZSTD_compressStream2() sets ZSTD_e_end :
478  * in which case, ZSTD_compressStream2() delegates to ZSTD_compress2(), which is always a blocking call).
479  * More workers improve speed, but also increase memory usage.
480  * Default value is `0`, aka "single-threaded mode" : no worker is spawned,
481  * compression is performed inside Caller's thread, and all invocations are blocking */
482  ZSTD_c_jobSize=401, /* Size of a compression job. This value is enforced only when nbWorkers >= 1.
483  * Each compression job is completed in parallel, so this value can indirectly impact the nb of active threads.
484  * 0 means default, which is dynamically determined based on compression parameters.
485  * Job size must be a minimum of overlap size, or ZSTDMT_JOBSIZE_MIN (= 512 KB), whichever is largest.
486  * The minimum size is automatically and transparently enforced. */
487  ZSTD_c_overlapLog=402, /* Control the overlap size, as a fraction of window size.
488  * The overlap size is an amount of data reloaded from previous job at the beginning of a new job.
489  * It helps preserve compression ratio, while each job is compressed in parallel.
490  * This value is enforced only when nbWorkers >= 1.
491  * Larger values increase compression ratio, but decrease speed.
492  * Possible values range from 0 to 9 :
493  * - 0 means "default" : value will be determined by the library, depending on strategy
494  * - 1 means "no overlap"
495  * - 9 means "full overlap", using a full window size.
496  * Each intermediate rank increases/decreases load size by a factor 2 :
497  * 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
498  * default value varies between 6 and 9, depending on strategy */
499 
500  /* note : additional experimental parameters are also available
501  * within the experimental section of the API.
502  * At the time of this writing, they include :
503  * ZSTD_c_rsyncable
504  * ZSTD_c_format
505  * ZSTD_c_forceMaxWindow
506  * ZSTD_c_forceAttachDict
507  * ZSTD_c_literalCompressionMode
508  * ZSTD_c_srcSizeHint
509  * ZSTD_c_enableDedicatedDictSearch
510  * ZSTD_c_stableInBuffer
511  * ZSTD_c_stableOutBuffer
512  * ZSTD_c_blockDelimiters
513  * ZSTD_c_validateSequences
514  * ZSTD_c_blockSplitterLevel
515  * ZSTD_c_splitAfterSequences
516  * ZSTD_c_useRowMatchFinder
517  * ZSTD_c_prefetchCDictTables
518  * ZSTD_c_enableSeqProducerFallback
519  * ZSTD_c_maxBlockSize
520  * Because they are not stable, it's necessary to define ZSTD_STATIC_LINKING_ONLY to access them.
521  * note : never ever use experimentalParam? names directly;
522  * also, the enums values themselves are unstable and can still change.
523  */
524  ZSTD_c_experimentalParam1=500,
525  ZSTD_c_experimentalParam2=10,
526  ZSTD_c_experimentalParam3=1000,
527  ZSTD_c_experimentalParam4=1001,
528  ZSTD_c_experimentalParam5=1002,
529  /* was ZSTD_c_experimentalParam6=1003; is now ZSTD_c_targetCBlockSize */
530  ZSTD_c_experimentalParam7=1004,
531  ZSTD_c_experimentalParam8=1005,
532  ZSTD_c_experimentalParam9=1006,
533  ZSTD_c_experimentalParam10=1007,
534  ZSTD_c_experimentalParam11=1008,
535  ZSTD_c_experimentalParam12=1009,
536  ZSTD_c_experimentalParam13=1010,
537  ZSTD_c_experimentalParam14=1011,
538  ZSTD_c_experimentalParam15=1012,
539  ZSTD_c_experimentalParam16=1013,
540  ZSTD_c_experimentalParam17=1014,
541  ZSTD_c_experimentalParam18=1015,
542  ZSTD_c_experimentalParam19=1016,
543  ZSTD_c_experimentalParam20=1017
544 } ZSTD_cParameter;
545 
546 typedef struct {
547  size_t error;
548  int lowerBound;
549  int upperBound;
550 } ZSTD_bounds;
551 
559 ZSTDLIB_API ZSTD_bounds ZSTD_cParam_getBounds(ZSTD_cParameter cParam);
560 
572 ZSTDLIB_API size_t ZSTD_CCtx_setParameter(ZSTD_CCtx* cctx, ZSTD_cParameter param, int value);
573 
589 ZSTDLIB_API size_t ZSTD_CCtx_setPledgedSrcSize(ZSTD_CCtx* cctx, unsigned long long pledgedSrcSize);
590 
591 typedef enum {
592  ZSTD_reset_session_only = 1,
593  ZSTD_reset_parameters = 2,
594  ZSTD_reset_session_and_parameters = 3
595 } ZSTD_ResetDirective;
596 
611 ZSTDLIB_API size_t ZSTD_CCtx_reset(ZSTD_CCtx* cctx, ZSTD_ResetDirective reset);
612 
625 ZSTDLIB_API size_t ZSTD_compress2( ZSTD_CCtx* cctx,
626  void* dst, size_t dstCapacity,
627  const void* src, size_t srcSize);
628 
629 
630 /***********************************************
631 * Advanced decompression API (Requires v1.4.0+)
632 ************************************************/
633 
634 /* The advanced API pushes parameters one by one into an existing DCtx context.
635  * Parameters are sticky, and remain valid for all following frames
636  * using the same DCtx context.
637  * It's possible to reset parameters to default values using ZSTD_DCtx_reset().
638  * Note : This API is compatible with existing ZSTD_decompressDCtx() and ZSTD_decompressStream().
639  * Therefore, no new decompression function is necessary.
640  */
641 
642 typedef enum {
643 
644  ZSTD_d_windowLogMax=100, /* Select a size limit (in power of 2) beyond which
645  * the streaming API will refuse to allocate memory buffer
646  * in order to protect the host from unreasonable memory requirements.
647  * This parameter is only useful in streaming mode, since no internal buffer is allocated in single-pass mode.
648  * By default, a decompression context accepts window sizes <= (1 << ZSTD_WINDOWLOG_LIMIT_DEFAULT).
649  * Special: value 0 means "use default maximum windowLog". */
650 
651  /* note : additional experimental parameters are also available
652  * within the experimental section of the API.
653  * At the time of this writing, they include :
654  * ZSTD_d_format
655  * ZSTD_d_stableOutBuffer
656  * ZSTD_d_forceIgnoreChecksum
657  * ZSTD_d_refMultipleDDicts
658  * ZSTD_d_disableHuffmanAssembly
659  * ZSTD_d_maxBlockSize
660  * Because they are not stable, it's necessary to define ZSTD_STATIC_LINKING_ONLY to access them.
661  * note : never ever use experimentalParam? names directly
662  */
663  ZSTD_d_experimentalParam1=1000,
664  ZSTD_d_experimentalParam2=1001,
665  ZSTD_d_experimentalParam3=1002,
666  ZSTD_d_experimentalParam4=1003,
667  ZSTD_d_experimentalParam5=1004,
668  ZSTD_d_experimentalParam6=1005
669 
670 } ZSTD_dParameter;
671 
679 ZSTDLIB_API ZSTD_bounds ZSTD_dParam_getBounds(ZSTD_dParameter dParam);
680 
688 ZSTDLIB_API size_t ZSTD_DCtx_setParameter(ZSTD_DCtx* dctx, ZSTD_dParameter param, int value);
689 
696 ZSTDLIB_API size_t ZSTD_DCtx_reset(ZSTD_DCtx* dctx, ZSTD_ResetDirective reset);
697 
698 
699 /****************************
700 * Streaming
701 ****************************/
702 
703 typedef struct ZSTD_inBuffer_s {
704  const void* src;
705  size_t size;
706  size_t pos;
707 } ZSTD_inBuffer;
708 
709 typedef struct ZSTD_outBuffer_s {
710  void* dst;
711  size_t size;
712  size_t pos;
714 
715 
716 
717 /*-***********************************************************************
718 * Streaming compression - HowTo
719 *
720 * A ZSTD_CStream object is required to track streaming operation.
721 * Use ZSTD_createCStream() and ZSTD_freeCStream() to create/release resources.
722 * ZSTD_CStream objects can be reused multiple times on consecutive compression operations.
723 * It is recommended to reuse ZSTD_CStream since it will play nicer with system's memory, by re-using already allocated memory.
724 *
725 * For parallel execution, use one separate ZSTD_CStream per thread.
726 *
727 * note : since v1.3.0, ZSTD_CStream and ZSTD_CCtx are the same thing.
728 *
729 * Parameters are sticky : when starting a new compression on the same context,
730 * it will reuse the same sticky parameters as previous compression session.
731 * When in doubt, it's recommended to fully initialize the context before usage.
732 * Use ZSTD_CCtx_reset() to reset the context and ZSTD_CCtx_setParameter(),
733 * ZSTD_CCtx_setPledgedSrcSize(), or ZSTD_CCtx_loadDictionary() and friends to
734 * set more specific parameters, the pledged source size, or load a dictionary.
735 *
736 * Use ZSTD_compressStream2() with ZSTD_e_continue as many times as necessary to
737 * consume input stream. The function will automatically update both `pos`
738 * fields within `input` and `output`.
739 * Note that the function may not consume the entire input, for example, because
740 * the output buffer is already full, in which case `input.pos < input.size`.
741 * The caller must check if input has been entirely consumed.
742 * If not, the caller must make some room to receive more compressed data,
743 * and then present again remaining input data.
744 * note: ZSTD_e_continue is guaranteed to make some forward progress when called,
745 * but doesn't guarantee maximal forward progress. This is especially relevant
746 * when compressing with multiple threads. The call won't block if it can
747 * consume some input, but if it can't it will wait for some, but not all,
748 * output to be flushed.
749 * @return : provides a minimum amount of data remaining to be flushed from internal buffers
750 * or an error code, which can be tested using ZSTD_isError().
751 *
752 * At any moment, it's possible to flush whatever data might remain stuck within internal buffer,
753 * using ZSTD_compressStream2() with ZSTD_e_flush. `output->pos` will be updated.
754 * Note that, if `output->size` is too small, a single invocation with ZSTD_e_flush might not be enough (return code > 0).
755 * In which case, make some room to receive more compressed data, and call again ZSTD_compressStream2() with ZSTD_e_flush.
756 * You must continue calling ZSTD_compressStream2() with ZSTD_e_flush until it returns 0, at which point you can change the
757 * operation.
758 * note: ZSTD_e_flush will flush as much output as possible, meaning when compressing with multiple threads, it will
759 * block until the flush is complete or the output buffer is full.
760 * @return : 0 if internal buffers are entirely flushed,
761 * >0 if some data still present within internal buffer (the value is minimal estimation of remaining size),
762 * or an error code, which can be tested using ZSTD_isError().
763 *
764 * Calling ZSTD_compressStream2() with ZSTD_e_end instructs to finish a frame.
765 * It will perform a flush and write frame epilogue.
766 * The epilogue is required for decoders to consider a frame completed.
767 * flush operation is the same, and follows same rules as calling ZSTD_compressStream2() with ZSTD_e_flush.
768 * You must continue calling ZSTD_compressStream2() with ZSTD_e_end until it returns 0, at which point you are free to
769 * start a new frame.
770 * note: ZSTD_e_end will flush as much output as possible, meaning when compressing with multiple threads, it will
771 * block until the flush is complete or the output buffer is full.
772 * @return : 0 if frame fully completed and fully flushed,
773 * >0 if some data still present within internal buffer (the value is minimal estimation of remaining size),
774 * or an error code, which can be tested using ZSTD_isError().
775 *
776 * *******************************************************************/
777 
778 typedef ZSTD_CCtx ZSTD_CStream;
779  /* Continue to distinguish them for compatibility with older versions <= v1.2.0 */
780 /*===== ZSTD_CStream management functions =====*/
781 ZSTDLIB_API ZSTD_CStream* ZSTD_createCStream(void);
782 ZSTDLIB_API size_t ZSTD_freeCStream(ZSTD_CStream* zcs); /* accept NULL pointer */
783 
784 /*===== Streaming compression functions =====*/
785 typedef enum {
786  ZSTD_e_continue=0, /* collect more data, encoder decides when to output compressed result, for optimal compression ratio */
787  ZSTD_e_flush=1, /* flush any data provided so far,
788  * it creates (at least) one new block, that can be decoded immediately on reception;
789  * frame will continue: any future data can still reference previously compressed data, improving compression.
790  * note : multithreaded compression will block to flush as much output as possible. */
791  ZSTD_e_end=2 /* flush any remaining data _and_ close current frame.
792  * note that frame is only closed after compressed data is fully flushed (return value == 0).
793  * After that point, any additional data starts a new frame.
794  * note : each frame is independent (does not reference any content from previous frame).
795  : note : multithreaded compression will block to flush as much output as possible. */
796 } ZSTD_EndDirective;
797 
825 ZSTDLIB_API size_t ZSTD_compressStream2( ZSTD_CCtx* cctx,
826  ZSTD_outBuffer* output,
827  ZSTD_inBuffer* input,
828  ZSTD_EndDirective endOp);
829 
830 
831 /* These buffer sizes are softly recommended.
832  * They are not required : ZSTD_compressStream*() happily accepts any buffer size, for both input and output.
833  * Respecting the recommended size just makes it a bit easier for ZSTD_compressStream*(),
834  * reducing the amount of memory shuffling and buffering, resulting in minor performance savings.
835  *
836  * However, note that these recommendations are from the perspective of a C caller program.
837  * If the streaming interface is invoked from some other language,
838  * especially managed ones such as Java or Go, through a foreign function interface such as jni or cgo,
839  * a major performance rule is to reduce crossing such interface to an absolute minimum.
840  * It's not rare that performance ends being spent more into the interface, rather than compression itself.
841  * In which cases, prefer using large buffers, as large as practical,
842  * for both input and output, to reduce the nb of roundtrips.
843  */
844 ZSTDLIB_API size_t ZSTD_CStreamInSize(void);
845 ZSTDLIB_API size_t ZSTD_CStreamOutSize(void);
848 /* *****************************************************************************
849  * This following is a legacy streaming API, available since v1.0+ .
850  * It can be replaced by ZSTD_CCtx_reset() and ZSTD_compressStream2().
851  * It is redundant, but remains fully supported.
852  ******************************************************************************/
853 
864 ZSTDLIB_API size_t ZSTD_initCStream(ZSTD_CStream* zcs, int compressionLevel);
871 ZSTDLIB_API size_t ZSTD_compressStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output, ZSTD_inBuffer* input);
873 ZSTDLIB_API size_t ZSTD_flushStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output);
875 ZSTDLIB_API size_t ZSTD_endStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output);
876 
877 
878 /*-***************************************************************************
879 * Streaming decompression - HowTo
880 *
881 * A ZSTD_DStream object is required to track streaming operations.
882 * Use ZSTD_createDStream() and ZSTD_freeDStream() to create/release resources.
883 * ZSTD_DStream objects can be re-employed multiple times.
884 *
885 * Use ZSTD_initDStream() to start a new decompression operation.
886 * @return : recommended first input size
887 * Alternatively, use advanced API to set specific properties.
888 *
889 * Use ZSTD_decompressStream() repetitively to consume your input.
890 * The function will update both `pos` fields.
891 * If `input.pos < input.size`, some input has not been consumed.
892 * It's up to the caller to present again remaining data.
893 *
894 * The function tries to flush all data decoded immediately, respecting output buffer size.
895 * If `output.pos < output.size`, decoder has flushed everything it could.
896 *
897 * However, when `output.pos == output.size`, it's more difficult to know.
898 * If @return > 0, the frame is not complete, meaning
899 * either there is still some data left to flush within internal buffers,
900 * or there is more input to read to complete the frame (or both).
901 * In which case, call ZSTD_decompressStream() again to flush whatever remains in the buffer.
902 * Note : with no additional input provided, amount of data flushed is necessarily <= ZSTD_BLOCKSIZE_MAX.
903 * @return : 0 when a frame is completely decoded and fully flushed,
904 * or an error code, which can be tested using ZSTD_isError(),
905 * or any other value > 0, which means there is still some decoding or flushing to do to complete current frame :
906 * the return value is a suggested next input size (just a hint for better latency)
907 * that will never request more than the remaining content of the compressed frame.
908 * *******************************************************************************/
909 
910 typedef ZSTD_DCtx ZSTD_DStream;
911  /* For compatibility with versions <= v1.2.0, prefer differentiating them. */
912 /*===== ZSTD_DStream management functions =====*/
913 ZSTDLIB_API ZSTD_DStream* ZSTD_createDStream(void);
914 ZSTDLIB_API size_t ZSTD_freeDStream(ZSTD_DStream* zds); /* accept NULL pointer */
915 
916 /*===== Streaming decompression functions =====*/
917 
926 ZSTDLIB_API size_t ZSTD_initDStream(ZSTD_DStream* zds);
927 
950 ZSTDLIB_API size_t ZSTD_decompressStream(ZSTD_DStream* zds, ZSTD_outBuffer* output, ZSTD_inBuffer* input);
951 
952 ZSTDLIB_API size_t ZSTD_DStreamInSize(void);
953 ZSTDLIB_API size_t ZSTD_DStreamOutSize(void);
956 /**************************
957 * Simple dictionary API
958 ***************************/
966 ZSTDLIB_API size_t ZSTD_compress_usingDict(ZSTD_CCtx* ctx,
967  void* dst, size_t dstCapacity,
968  const void* src, size_t srcSize,
969  const void* dict,size_t dictSize,
970  int compressionLevel);
971 
978 ZSTDLIB_API size_t ZSTD_decompress_usingDict(ZSTD_DCtx* dctx,
979  void* dst, size_t dstCapacity,
980  const void* src, size_t srcSize,
981  const void* dict,size_t dictSize);
982 
983 
984 /***********************************
985  * Bulk processing dictionary API
986  **********************************/
987 typedef struct ZSTD_CDict_s ZSTD_CDict;
988 
1001 ZSTDLIB_API ZSTD_CDict* ZSTD_createCDict(const void* dictBuffer, size_t dictSize,
1002  int compressionLevel);
1003 
1007 ZSTDLIB_API size_t ZSTD_freeCDict(ZSTD_CDict* CDict);
1008 
1014 ZSTDLIB_API size_t ZSTD_compress_usingCDict(ZSTD_CCtx* cctx,
1015  void* dst, size_t dstCapacity,
1016  const void* src, size_t srcSize,
1017  const ZSTD_CDict* cdict);
1018 
1019 
1020 typedef struct ZSTD_DDict_s ZSTD_DDict;
1021 
1025 ZSTDLIB_API ZSTD_DDict* ZSTD_createDDict(const void* dictBuffer, size_t dictSize);
1026 
1030 ZSTDLIB_API size_t ZSTD_freeDDict(ZSTD_DDict* ddict);
1031 
1035 ZSTDLIB_API size_t ZSTD_decompress_usingDDict(ZSTD_DCtx* dctx,
1036  void* dst, size_t dstCapacity,
1037  const void* src, size_t srcSize,
1038  const ZSTD_DDict* ddict);
1039 
1040 
1041 /********************************
1042  * Dictionary helper functions
1043  *******************************/
1044 
1049 ZSTDLIB_API unsigned ZSTD_getDictID_fromDict(const void* dict, size_t dictSize);
1050 
1055 ZSTDLIB_API unsigned ZSTD_getDictID_fromCDict(const ZSTD_CDict* cdict);
1056 
1061 ZSTDLIB_API unsigned ZSTD_getDictID_fromDDict(const ZSTD_DDict* ddict);
1062 
1073 ZSTDLIB_API unsigned ZSTD_getDictID_fromFrame(const void* src, size_t srcSize);
1074 
1075 
1076 /*******************************************************************************
1077  * Advanced dictionary and prefix API (Requires v1.4.0+)
1078  *
1079  * This API allows dictionaries to be used with ZSTD_compress2(),
1080  * ZSTD_compressStream2(), and ZSTD_decompressDCtx().
1081  * Dictionaries are sticky, they remain valid when same context is reused,
1082  * they only reset when the context is reset
1083  * with ZSTD_reset_parameters or ZSTD_reset_session_and_parameters.
1084  * In contrast, Prefixes are single-use.
1085  ******************************************************************************/
1086 
1087 
1110 ZSTDLIB_API size_t ZSTD_CCtx_loadDictionary(ZSTD_CCtx* cctx, const void* dict, size_t dictSize);
1111 
1124 ZSTDLIB_API size_t ZSTD_CCtx_refCDict(ZSTD_CCtx* cctx, const ZSTD_CDict* cdict);
1125 
1145 ZSTDLIB_API size_t ZSTD_CCtx_refPrefix(ZSTD_CCtx* cctx,
1146  const void* prefix, size_t prefixSize);
1147 
1163 ZSTDLIB_API size_t ZSTD_DCtx_loadDictionary(ZSTD_DCtx* dctx, const void* dict, size_t dictSize);
1164 
1182 ZSTDLIB_API size_t ZSTD_DCtx_refDDict(ZSTD_DCtx* dctx, const ZSTD_DDict* ddict);
1183 
1200 ZSTDLIB_API size_t ZSTD_DCtx_refPrefix(ZSTD_DCtx* dctx,
1201  const void* prefix, size_t prefixSize);
1202 
1203 /* === Memory management === */
1204 
1208 ZSTDLIB_API size_t ZSTD_sizeof_CCtx(const ZSTD_CCtx* cctx);
1209 ZSTDLIB_API size_t ZSTD_sizeof_DCtx(const ZSTD_DCtx* dctx);
1210 ZSTDLIB_API size_t ZSTD_sizeof_CStream(const ZSTD_CStream* zcs);
1211 ZSTDLIB_API size_t ZSTD_sizeof_DStream(const ZSTD_DStream* zds);
1212 ZSTDLIB_API size_t ZSTD_sizeof_CDict(const ZSTD_CDict* cdict);
1213 ZSTDLIB_API size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict);
1214 
1215 #if defined (__cplusplus)
1216 }
1217 #endif
1218 
1219 #endif /* ZSTD_H_235446 */
1220 
1221 
1222 /* **************************************************************************************
1223  * ADVANCED AND EXPERIMENTAL FUNCTIONS
1224  ****************************************************************************************
1225  * The definitions in the following section are considered experimental.
1226  * They are provided for advanced scenarios.
1227  * They should never be used with a dynamic library, as prototypes may change in the future.
1228  * Use them only in association with static linking.
1229  * ***************************************************************************************/
1230 
1231 #if defined(ZSTD_STATIC_LINKING_ONLY) && !defined(ZSTD_H_ZSTD_STATIC_LINKING_ONLY)
1232 #define ZSTD_H_ZSTD_STATIC_LINKING_ONLY
1233 
1234 #if defined (__cplusplus)
1235 extern "C" {
1236 #endif
1237 
1238 /* This can be overridden externally to hide static symbols. */
1239 #ifndef ZSTDLIB_STATIC_API
1240 # if defined(ZSTD_DLL_EXPORT) && (ZSTD_DLL_EXPORT==1)
1241 # define ZSTDLIB_STATIC_API __declspec(dllexport) ZSTDLIB_VISIBLE
1242 # elif defined(ZSTD_DLL_IMPORT) && (ZSTD_DLL_IMPORT==1)
1243 # define ZSTDLIB_STATIC_API __declspec(dllimport) ZSTDLIB_VISIBLE
1244 # else
1245 # define ZSTDLIB_STATIC_API ZSTDLIB_VISIBLE
1246 # endif
1247 #endif
1248 
1249 /****************************************************************************************
1250  * experimental API (static linking only)
1251  ****************************************************************************************
1252  * The following symbols and constants
1253  * are not planned to join "stable API" status in the near future.
1254  * They can still change in future versions.
1255  * Some of them are planned to remain in the static_only section indefinitely.
1256  * Some of them might be removed in the future (especially when redundant with existing stable functions)
1257  * ***************************************************************************************/
1258 
1259 #define ZSTD_FRAMEHEADERSIZE_PREFIX(format) ((format) == ZSTD_f_zstd1 ? 5 : 1) /* minimum input size required to query frame header size */
1260 #define ZSTD_FRAMEHEADERSIZE_MIN(format) ((format) == ZSTD_f_zstd1 ? 6 : 2)
1261 #define ZSTD_FRAMEHEADERSIZE_MAX 18 /* can be useful for static allocation */
1262 #define ZSTD_SKIPPABLEHEADERSIZE 8
1263 
1264 /* compression parameter bounds */
1265 #define ZSTD_WINDOWLOG_MAX_32 30
1266 #define ZSTD_WINDOWLOG_MAX_64 31
1267 #define ZSTD_WINDOWLOG_MAX ((int)(sizeof(size_t) == 4 ? ZSTD_WINDOWLOG_MAX_32 : ZSTD_WINDOWLOG_MAX_64))
1268 #define ZSTD_WINDOWLOG_MIN 10
1269 #define ZSTD_HASHLOG_MAX ((ZSTD_WINDOWLOG_MAX < 30) ? ZSTD_WINDOWLOG_MAX : 30)
1270 #define ZSTD_HASHLOG_MIN 6
1271 #define ZSTD_CHAINLOG_MAX_32 29
1272 #define ZSTD_CHAINLOG_MAX_64 30
1273 #define ZSTD_CHAINLOG_MAX ((int)(sizeof(size_t) == 4 ? ZSTD_CHAINLOG_MAX_32 : ZSTD_CHAINLOG_MAX_64))
1274 #define ZSTD_CHAINLOG_MIN ZSTD_HASHLOG_MIN
1275 #define ZSTD_SEARCHLOG_MAX (ZSTD_WINDOWLOG_MAX-1)
1276 #define ZSTD_SEARCHLOG_MIN 1
1277 #define ZSTD_MINMATCH_MAX 7 /* only for ZSTD_fast, other strategies are limited to 6 */
1278 #define ZSTD_MINMATCH_MIN 3 /* only for ZSTD_btopt+, faster strategies are limited to 4 */
1279 #define ZSTD_TARGETLENGTH_MAX ZSTD_BLOCKSIZE_MAX
1280 #define ZSTD_TARGETLENGTH_MIN 0 /* note : comparing this constant to an unsigned results in a tautological test */
1281 #define ZSTD_STRATEGY_MIN ZSTD_fast
1282 #define ZSTD_STRATEGY_MAX ZSTD_btultra2
1283 #define ZSTD_BLOCKSIZE_MAX_MIN (1 << 10) /* The minimum valid max blocksize. Maximum blocksizes smaller than this make compressBound() inaccurate. */
1284 
1285 
1286 #define ZSTD_OVERLAPLOG_MIN 0
1287 #define ZSTD_OVERLAPLOG_MAX 9
1288 
1289 #define ZSTD_WINDOWLOG_LIMIT_DEFAULT 27 /* by default, the streaming decoder will refuse any frame
1290  * requiring larger than (1<<ZSTD_WINDOWLOG_LIMIT_DEFAULT) window size,
1291  * to preserve host's memory from unreasonable requirements.
1292  * This limit can be overridden using ZSTD_DCtx_setParameter(,ZSTD_d_windowLogMax,).
1293  * The limit does not apply for one-pass decoders (such as ZSTD_decompress()), since no additional memory is allocated */
1294 
1295 
1296 /* LDM parameter bounds */
1297 #define ZSTD_LDM_HASHLOG_MIN ZSTD_HASHLOG_MIN
1298 #define ZSTD_LDM_HASHLOG_MAX ZSTD_HASHLOG_MAX
1299 #define ZSTD_LDM_MINMATCH_MIN 4
1300 #define ZSTD_LDM_MINMATCH_MAX 4096
1301 #define ZSTD_LDM_BUCKETSIZELOG_MIN 1
1302 #define ZSTD_LDM_BUCKETSIZELOG_MAX 8
1303 #define ZSTD_LDM_HASHRATELOG_MIN 0
1304 #define ZSTD_LDM_HASHRATELOG_MAX (ZSTD_WINDOWLOG_MAX - ZSTD_HASHLOG_MIN)
1305 
1306 /* Advanced parameter bounds */
1307 #define ZSTD_TARGETCBLOCKSIZE_MIN 1340 /* suitable to fit into an ethernet / wifi / 4G transport frame */
1308 #define ZSTD_TARGETCBLOCKSIZE_MAX ZSTD_BLOCKSIZE_MAX
1309 #define ZSTD_SRCSIZEHINT_MIN 0
1310 #define ZSTD_SRCSIZEHINT_MAX INT_MAX
1311 
1312 
1313 /* --- Advanced types --- */
1314 
1315 typedef struct ZSTD_CCtx_params_s ZSTD_CCtx_params;
1316 
1317 typedef struct {
1318  unsigned int offset; /* The offset of the match. (NOT the same as the offset code)
1319  * If offset == 0 and matchLength == 0, this sequence represents the last
1320  * literals in the block of litLength size.
1321  */
1322 
1323  unsigned int litLength; /* Literal length of the sequence. */
1324  unsigned int matchLength; /* Match length of the sequence. */
1325 
1326  /* Note: Users of this API may provide a sequence with matchLength == litLength == offset == 0.
1327  * In this case, we will treat the sequence as a marker for a block boundary.
1328  */
1329 
1330  unsigned int rep; /* Represents which repeat offset is represented by the field 'offset'.
1331  * Ranges from [0, 3].
1332  *
1333  * Repeat offsets are essentially previous offsets from previous sequences sorted in
1334  * recency order. For more detail, see doc/zstd_compression_format.md
1335  *
1336  * If rep == 0, then 'offset' does not contain a repeat offset.
1337  * If rep > 0:
1338  * If litLength != 0:
1339  * rep == 1 --> offset == repeat_offset_1
1340  * rep == 2 --> offset == repeat_offset_2
1341  * rep == 3 --> offset == repeat_offset_3
1342  * If litLength == 0:
1343  * rep == 1 --> offset == repeat_offset_2
1344  * rep == 2 --> offset == repeat_offset_3
1345  * rep == 3 --> offset == repeat_offset_1 - 1
1346  *
1347  * Note: This field is optional. ZSTD_generateSequences() will calculate the value of
1348  * 'rep', but repeat offsets do not necessarily need to be calculated from an external
1349  * sequence provider perspective. For example, ZSTD_compressSequences() does not
1350  * use this 'rep' field at all (as of now).
1351  */
1352 } ZSTD_Sequence;
1353 
1354 typedef struct {
1355  unsigned windowLog;
1356  unsigned chainLog;
1357  unsigned hashLog;
1358  unsigned searchLog;
1359  unsigned minMatch;
1360  unsigned targetLength;
1361  ZSTD_strategy strategy;
1363 
1364 typedef struct {
1365  int contentSizeFlag;
1366  int checksumFlag;
1367  int noDictIDFlag;
1369 
1370 typedef struct {
1372  ZSTD_frameParameters fParams;
1373 } ZSTD_parameters;
1374 
1375 typedef enum {
1376  ZSTD_dct_auto = 0, /* dictionary is "full" when starting with ZSTD_MAGIC_DICTIONARY, otherwise it is "rawContent" */
1377  ZSTD_dct_rawContent = 1, /* ensures dictionary is always loaded as rawContent, even if it starts with ZSTD_MAGIC_DICTIONARY */
1378  ZSTD_dct_fullDict = 2 /* refuses to load a dictionary if it does not respect Zstandard's specification, starting with ZSTD_MAGIC_DICTIONARY */
1379 } ZSTD_dictContentType_e;
1380 
1381 typedef enum {
1382  ZSTD_dlm_byCopy = 0,
1383  ZSTD_dlm_byRef = 1
1385 
1386 typedef enum {
1387  ZSTD_f_zstd1 = 0, /* zstd frame format, specified in zstd_compression_format.md (default) */
1388  ZSTD_f_zstd1_magicless = 1 /* Variant of zstd frame format, without initial 4-bytes magic number.
1389  * Useful to save 4 bytes per generated frame.
1390  * Decoder cannot recognise automatically this format, requiring this instruction. */
1391 } ZSTD_format_e;
1392 
1393 typedef enum {
1394  /* Note: this enum controls ZSTD_d_forceIgnoreChecksum */
1395  ZSTD_d_validateChecksum = 0,
1396  ZSTD_d_ignoreChecksum = 1
1397 } ZSTD_forceIgnoreChecksum_e;
1398 
1399 typedef enum {
1400  /* Note: this enum controls ZSTD_d_refMultipleDDicts */
1401  ZSTD_rmd_refSingleDDict = 0,
1402  ZSTD_rmd_refMultipleDDicts = 1
1403 } ZSTD_refMultipleDDicts_e;
1404 
1405 typedef enum {
1406  /* Note: this enum and the behavior it controls are effectively internal
1407  * implementation details of the compressor. They are expected to continue
1408  * to evolve and should be considered only in the context of extremely
1409  * advanced performance tuning.
1410  *
1411  * Zstd currently supports the use of a CDict in three ways:
1412  *
1413  * - The contents of the CDict can be copied into the working context. This
1414  * means that the compression can search both the dictionary and input
1415  * while operating on a single set of internal tables. This makes
1416  * the compression faster per-byte of input. However, the initial copy of
1417  * the CDict's tables incurs a fixed cost at the beginning of the
1418  * compression. For small compressions (< 8 KB), that copy can dominate
1419  * the cost of the compression.
1420  *
1421  * - The CDict's tables can be used in-place. In this model, compression is
1422  * slower per input byte, because the compressor has to search two sets of
1423  * tables. However, this model incurs no start-up cost (as long as the
1424  * working context's tables can be reused). For small inputs, this can be
1425  * faster than copying the CDict's tables.
1426  *
1427  * - The CDict's tables are not used at all, and instead we use the working
1428  * context alone to reload the dictionary and use params based on the source
1429  * size. See ZSTD_compress_insertDictionary() and ZSTD_compress_usingDict().
1430  * This method is effective when the dictionary sizes are very small relative
1431  * to the input size, and the input size is fairly large to begin with.
1432  *
1433  * Zstd has a simple internal heuristic that selects which strategy to use
1434  * at the beginning of a compression. However, if experimentation shows that
1435  * Zstd is making poor choices, it is possible to override that choice with
1436  * this enum.
1437  */
1438  ZSTD_dictDefaultAttach = 0, /* Use the default heuristic. */
1439  ZSTD_dictForceAttach = 1, /* Never copy the dictionary. */
1440  ZSTD_dictForceCopy = 2, /* Always copy the dictionary. */
1441  ZSTD_dictForceLoad = 3 /* Always reload the dictionary */
1442 } ZSTD_dictAttachPref_e;
1443 
1444 typedef enum {
1445  ZSTD_lcm_auto = 0,
1448  ZSTD_lcm_huffman = 1,
1452 
1453 typedef enum {
1454  /* Note: This enum controls features which are conditionally beneficial.
1455  * Zstd can take a decision on whether or not to enable the feature (ZSTD_ps_auto),
1456  * but setting the switch to ZSTD_ps_enable or ZSTD_ps_disable force enable/disable the feature.
1457  */
1458  ZSTD_ps_auto = 0, /* Let the library automatically determine whether the feature shall be enabled */
1459  ZSTD_ps_enable = 1, /* Force-enable the feature */
1460  ZSTD_ps_disable = 2 /* Do not use the feature */
1461 } ZSTD_ParamSwitch_e;
1462 #define ZSTD_paramSwitch_e ZSTD_ParamSwitch_e /* old name */
1463 
1464 /***************************************
1465 * Frame header and size functions
1466 ***************************************/
1467 
1489 ZSTDLIB_STATIC_API unsigned long long ZSTD_findDecompressedSize(const void* src, size_t srcSize);
1490 
1504 ZSTDLIB_STATIC_API unsigned long long ZSTD_decompressBound(const void* src, size_t srcSize);
1505 
1510 ZSTDLIB_STATIC_API size_t ZSTD_frameHeaderSize(const void* src, size_t srcSize);
1511 
1512 typedef enum { ZSTD_frame, ZSTD_skippableFrame } ZSTD_FrameType_e;
1513 #define ZSTD_frameType_e ZSTD_FrameType_e /* old name */
1514 typedef struct {
1515  unsigned long long frameContentSize; /* if == ZSTD_CONTENTSIZE_UNKNOWN, it means this field is not available. 0 means "empty" */
1516  unsigned long long windowSize; /* can be very large, up to <= frameContentSize */
1517  unsigned blockSizeMax;
1518  ZSTD_FrameType_e frameType; /* if == ZSTD_skippableFrame, frameContentSize is the size of skippable content */
1519  unsigned headerSize;
1520  unsigned dictID; /* for ZSTD_skippableFrame, contains the skippable magic variant [0-15] */
1521  unsigned checksumFlag;
1522  unsigned _reserved1;
1523  unsigned _reserved2;
1525 #define ZSTD_frameHeader ZSTD_FrameHeader /* old name */
1526 
1532 ZSTDLIB_STATIC_API size_t ZSTD_getFrameHeader(ZSTD_FrameHeader* zfhPtr, const void* src, size_t srcSize);
1536 ZSTDLIB_STATIC_API size_t ZSTD_getFrameHeader_advanced(ZSTD_FrameHeader* zfhPtr, const void* src, size_t srcSize, ZSTD_format_e format);
1537 
1561 ZSTDLIB_STATIC_API size_t ZSTD_decompressionMargin(const void* src, size_t srcSize);
1562 
1576 #define ZSTD_DECOMPRESSION_MARGIN(originalSize, blockSize) ((size_t)( \
1577  ZSTD_FRAMEHEADERSIZE_MAX /* Frame header */ + \
1578  4 /* checksum */ + \
1579  ((originalSize) == 0 ? 0 : 3 * (((originalSize) + (blockSize) - 1) / blockSize)) /* 3 bytes per block */ + \
1580  (blockSize) /* One block of margin */ \
1581  ))
1582 
1583 typedef enum {
1584  ZSTD_sf_noBlockDelimiters = 0, /* ZSTD_Sequence[] has no block delimiters, just sequences */
1585  ZSTD_sf_explicitBlockDelimiters = 1 /* ZSTD_Sequence[] contains explicit block delimiters */
1586 } ZSTD_SequenceFormat_e;
1587 #define ZSTD_sequenceFormat_e ZSTD_SequenceFormat_e /* old name */
1588 
1596 ZSTDLIB_STATIC_API size_t ZSTD_sequenceBound(size_t srcSize);
1597 
1626 ZSTD_DEPRECATED("For debugging only, will be replaced by ZSTD_extractSequences()")
1627 ZSTDLIB_STATIC_API size_t
1629  ZSTD_Sequence* outSeqs, size_t outSeqsCapacity,
1630  const void* src, size_t srcSize);
1631 
1643 ZSTDLIB_STATIC_API size_t ZSTD_mergeBlockDelimiters(ZSTD_Sequence* sequences, size_t seqsSize);
1644 
1681 ZSTDLIB_STATIC_API size_t
1683  void* dst, size_t dstCapacity,
1684  const ZSTD_Sequence* inSeqs, size_t inSeqsSize,
1685  const void* src, size_t srcSize);
1686 
1687 
1706 ZSTDLIB_STATIC_API size_t
1708  void* dst, size_t dstCapacity,
1709  const ZSTD_Sequence* inSeqs, size_t nbSequences,
1710  const void* literals, size_t litSize, size_t litBufCapacity,
1711  size_t decompressedSize);
1712 
1713 
1727 ZSTDLIB_STATIC_API size_t ZSTD_writeSkippableFrame(void* dst, size_t dstCapacity,
1728  const void* src, size_t srcSize,
1729  unsigned magicVariant);
1730 
1742 ZSTDLIB_STATIC_API size_t ZSTD_readSkippableFrame(void* dst, size_t dstCapacity,
1743  unsigned* magicVariant,
1744  const void* src, size_t srcSize);
1745 
1749 ZSTDLIB_STATIC_API unsigned ZSTD_isSkippableFrame(const void* buffer, size_t size);
1750 
1751 
1752 
1753 /***************************************
1754 * Memory management
1755 ***************************************/
1756 
1784 ZSTDLIB_STATIC_API size_t ZSTD_estimateCCtxSize(int maxCompressionLevel);
1785 ZSTDLIB_STATIC_API size_t ZSTD_estimateCCtxSize_usingCParams(ZSTD_compressionParameters cParams);
1786 ZSTDLIB_STATIC_API size_t ZSTD_estimateCCtxSize_usingCCtxParams(const ZSTD_CCtx_params* params);
1787 ZSTDLIB_STATIC_API size_t ZSTD_estimateDCtxSize(void);
1788 
1809 ZSTDLIB_STATIC_API size_t ZSTD_estimateCStreamSize(int maxCompressionLevel);
1810 ZSTDLIB_STATIC_API size_t ZSTD_estimateCStreamSize_usingCParams(ZSTD_compressionParameters cParams);
1811 ZSTDLIB_STATIC_API size_t ZSTD_estimateCStreamSize_usingCCtxParams(const ZSTD_CCtx_params* params);
1812 ZSTDLIB_STATIC_API size_t ZSTD_estimateDStreamSize(size_t maxWindowSize);
1813 ZSTDLIB_STATIC_API size_t ZSTD_estimateDStreamSize_fromFrame(const void* src, size_t srcSize);
1814 
1820 ZSTDLIB_STATIC_API size_t ZSTD_estimateCDictSize(size_t dictSize, int compressionLevel);
1821 ZSTDLIB_STATIC_API size_t ZSTD_estimateCDictSize_advanced(size_t dictSize, ZSTD_compressionParameters cParams, ZSTD_dictLoadMethod_e dictLoadMethod);
1822 ZSTDLIB_STATIC_API size_t ZSTD_estimateDDictSize(size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod);
1823 
1845 ZSTDLIB_STATIC_API ZSTD_CCtx* ZSTD_initStaticCCtx(void* workspace, size_t workspaceSize);
1846 ZSTDLIB_STATIC_API ZSTD_CStream* ZSTD_initStaticCStream(void* workspace, size_t workspaceSize);
1848 ZSTDLIB_STATIC_API ZSTD_DCtx* ZSTD_initStaticDCtx(void* workspace, size_t workspaceSize);
1849 ZSTDLIB_STATIC_API ZSTD_DStream* ZSTD_initStaticDStream(void* workspace, size_t workspaceSize);
1851 ZSTDLIB_STATIC_API const ZSTD_CDict* ZSTD_initStaticCDict(
1852  void* workspace, size_t workspaceSize,
1853  const void* dict, size_t dictSize,
1854  ZSTD_dictLoadMethod_e dictLoadMethod,
1855  ZSTD_dictContentType_e dictContentType,
1856  ZSTD_compressionParameters cParams);
1857 
1858 ZSTDLIB_STATIC_API const ZSTD_DDict* ZSTD_initStaticDDict(
1859  void* workspace, size_t workspaceSize,
1860  const void* dict, size_t dictSize,
1861  ZSTD_dictLoadMethod_e dictLoadMethod,
1862  ZSTD_dictContentType_e dictContentType);
1863 
1864 
1870 typedef void* (*ZSTD_allocFunction) (void* opaque, size_t size);
1871 typedef void (*ZSTD_freeFunction) (void* opaque, void* address);
1872 typedef struct { ZSTD_allocFunction customAlloc; ZSTD_freeFunction customFree; void* opaque; } ZSTD_customMem;
1873 #if defined(__clang__) && __clang_major__ >= 5
1874 #pragma clang diagnostic push
1875 #pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant"
1876 #endif
1877 static
1878 #ifdef __GNUC__
1879 __attribute__((__unused__))
1880 #endif
1881 ZSTD_customMem const ZSTD_defaultCMem = { NULL, NULL, NULL };
1882 #if defined(__clang__) && __clang_major__ >= 5
1883 #pragma clang diagnostic pop
1884 #endif
1885 
1886 ZSTDLIB_STATIC_API ZSTD_CCtx* ZSTD_createCCtx_advanced(ZSTD_customMem customMem);
1887 ZSTDLIB_STATIC_API ZSTD_CStream* ZSTD_createCStream_advanced(ZSTD_customMem customMem);
1888 ZSTDLIB_STATIC_API ZSTD_DCtx* ZSTD_createDCtx_advanced(ZSTD_customMem customMem);
1889 ZSTDLIB_STATIC_API ZSTD_DStream* ZSTD_createDStream_advanced(ZSTD_customMem customMem);
1890 
1891 ZSTDLIB_STATIC_API ZSTD_CDict* ZSTD_createCDict_advanced(const void* dict, size_t dictSize,
1892  ZSTD_dictLoadMethod_e dictLoadMethod,
1893  ZSTD_dictContentType_e dictContentType,
1895  ZSTD_customMem customMem);
1896 
1907 typedef struct POOL_ctx_s ZSTD_threadPool;
1908 ZSTDLIB_STATIC_API ZSTD_threadPool* ZSTD_createThreadPool(size_t numThreads);
1909 ZSTDLIB_STATIC_API void ZSTD_freeThreadPool (ZSTD_threadPool* pool); /* accept NULL pointer */
1910 ZSTDLIB_STATIC_API size_t ZSTD_CCtx_refThreadPool(ZSTD_CCtx* cctx, ZSTD_threadPool* pool);
1911 
1912 
1913 /*
1914  * This API is temporary and is expected to change or disappear in the future!
1915  */
1916 ZSTDLIB_STATIC_API ZSTD_CDict* ZSTD_createCDict_advanced2(
1917  const void* dict, size_t dictSize,
1918  ZSTD_dictLoadMethod_e dictLoadMethod,
1919  ZSTD_dictContentType_e dictContentType,
1920  const ZSTD_CCtx_params* cctxParams,
1921  ZSTD_customMem customMem);
1922 
1923 ZSTDLIB_STATIC_API ZSTD_DDict* ZSTD_createDDict_advanced(
1924  const void* dict, size_t dictSize,
1925  ZSTD_dictLoadMethod_e dictLoadMethod,
1926  ZSTD_dictContentType_e dictContentType,
1927  ZSTD_customMem customMem);
1928 
1929 
1930 /***************************************
1931 * Advanced compression functions
1932 ***************************************/
1933 
1940 ZSTDLIB_STATIC_API ZSTD_CDict* ZSTD_createCDict_byReference(const void* dictBuffer, size_t dictSize, int compressionLevel);
1941 
1945 ZSTDLIB_STATIC_API ZSTD_compressionParameters ZSTD_getCParams(int compressionLevel, unsigned long long estimatedSrcSize, size_t dictSize);
1946 
1950 ZSTDLIB_STATIC_API ZSTD_parameters ZSTD_getParams(int compressionLevel, unsigned long long estimatedSrcSize, size_t dictSize);
1951 
1955 ZSTDLIB_STATIC_API size_t ZSTD_checkCParams(ZSTD_compressionParameters params);
1956 
1963 ZSTDLIB_STATIC_API ZSTD_compressionParameters ZSTD_adjustCParams(ZSTD_compressionParameters cPar, unsigned long long srcSize, size_t dictSize);
1964 
1972 ZSTDLIB_STATIC_API size_t ZSTD_CCtx_setCParams(ZSTD_CCtx* cctx, ZSTD_compressionParameters cparams);
1973 
1978 ZSTDLIB_STATIC_API size_t ZSTD_CCtx_setFParams(ZSTD_CCtx* cctx, ZSTD_frameParameters fparams);
1979 
1984 ZSTDLIB_STATIC_API size_t ZSTD_CCtx_setParams(ZSTD_CCtx* cctx, ZSTD_parameters params);
1985 
1990 ZSTD_DEPRECATED("use ZSTD_compress2")
1991 ZSTDLIB_STATIC_API
1992 size_t ZSTD_compress_advanced(ZSTD_CCtx* cctx,
1993  void* dst, size_t dstCapacity,
1994  const void* src, size_t srcSize,
1995  const void* dict,size_t dictSize,
1996  ZSTD_parameters params);
1997 
2002 ZSTD_DEPRECATED("use ZSTD_compress2 with ZSTD_CCtx_loadDictionary")
2003 ZSTDLIB_STATIC_API
2005  void* dst, size_t dstCapacity,
2006  const void* src, size_t srcSize,
2007  const ZSTD_CDict* cdict,
2008  ZSTD_frameParameters fParams);
2009 
2010 
2014 ZSTDLIB_STATIC_API size_t ZSTD_CCtx_loadDictionary_byReference(ZSTD_CCtx* cctx, const void* dict, size_t dictSize);
2015 
2020 ZSTDLIB_STATIC_API size_t ZSTD_CCtx_loadDictionary_advanced(ZSTD_CCtx* cctx, const void* dict, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictContentType_e dictContentType);
2021 
2025 ZSTDLIB_STATIC_API size_t ZSTD_CCtx_refPrefix_advanced(ZSTD_CCtx* cctx, const void* prefix, size_t prefixSize, ZSTD_dictContentType_e dictContentType);
2026 
2027 /* === experimental parameters === */
2028 /* these parameters can be used with ZSTD_setParameter()
2029  * they are not guaranteed to remain supported in the future */
2030 
2031  /* Enables rsyncable mode,
2032  * which makes compressed files more rsync friendly
2033  * by adding periodic synchronization points to the compressed data.
2034  * The target average block size is ZSTD_c_jobSize / 2.
2035  * It's possible to modify the job size to increase or decrease
2036  * the granularity of the synchronization point.
2037  * Once the jobSize is smaller than the window size,
2038  * it will result in compression ratio degradation.
2039  * NOTE 1: rsyncable mode only works when multithreading is enabled.
2040  * NOTE 2: rsyncable performs poorly in combination with long range mode,
2041  * since it will decrease the effectiveness of synchronization points,
2042  * though mileage may vary.
2043  * NOTE 3: Rsyncable mode limits maximum compression speed to ~400 MB/s.
2044  * If the selected compression level is already running significantly slower,
2045  * the overall speed won't be significantly impacted.
2046  */
2047  #define ZSTD_c_rsyncable ZSTD_c_experimentalParam1
2048 
2049 /* Select a compression format.
2050  * The value must be of type ZSTD_format_e.
2051  * See ZSTD_format_e enum definition for details */
2052 #define ZSTD_c_format ZSTD_c_experimentalParam2
2053 
2054 /* Force back-reference distances to remain < windowSize,
2055  * even when referencing into Dictionary content (default:0) */
2056 #define ZSTD_c_forceMaxWindow ZSTD_c_experimentalParam3
2057 
2058 /* Controls whether the contents of a CDict
2059  * are used in place, or copied into the working context.
2060  * Accepts values from the ZSTD_dictAttachPref_e enum.
2061  * See the comments on that enum for an explanation of the feature. */
2062 #define ZSTD_c_forceAttachDict ZSTD_c_experimentalParam4
2063 
2064 /* Controlled with ZSTD_ParamSwitch_e enum.
2065  * Default is ZSTD_ps_auto.
2066  * Set to ZSTD_ps_disable to never compress literals.
2067  * Set to ZSTD_ps_enable to always compress literals. (Note: uncompressed literals
2068  * may still be emitted if huffman is not beneficial to use.)
2069  *
2070  * By default, in ZSTD_ps_auto, the library will decide at runtime whether to use
2071  * literals compression based on the compression parameters - specifically,
2072  * negative compression levels do not use literal compression.
2073  */
2074 #define ZSTD_c_literalCompressionMode ZSTD_c_experimentalParam5
2075 
2076 /* User's best guess of source size.
2077  * Hint is not valid when srcSizeHint == 0.
2078  * There is no guarantee that hint is close to actual source size,
2079  * but compression ratio may regress significantly if guess considerably underestimates */
2080 #define ZSTD_c_srcSizeHint ZSTD_c_experimentalParam7
2081 
2082 /* Controls whether the new and experimental "dedicated dictionary search
2083  * structure" can be used. This feature is still rough around the edges, be
2084  * prepared for surprising behavior!
2085  *
2086  * How to use it:
2087  *
2088  * When using a CDict, whether to use this feature or not is controlled at
2089  * CDict creation, and it must be set in a CCtxParams set passed into that
2090  * construction (via ZSTD_createCDict_advanced2()). A compression will then
2091  * use the feature or not based on how the CDict was constructed; the value of
2092  * this param, set in the CCtx, will have no effect.
2093  *
2094  * However, when a dictionary buffer is passed into a CCtx, such as via
2095  * ZSTD_CCtx_loadDictionary(), this param can be set on the CCtx to control
2096  * whether the CDict that is created internally can use the feature or not.
2097  *
2098  * What it does:
2099  *
2100  * Normally, the internal data structures of the CDict are analogous to what
2101  * would be stored in a CCtx after compressing the contents of a dictionary.
2102  * To an approximation, a compression using a dictionary can then use those
2103  * data structures to simply continue what is effectively a streaming
2104  * compression where the simulated compression of the dictionary left off.
2105  * Which is to say, the search structures in the CDict are normally the same
2106  * format as in the CCtx.
2107  *
2108  * It is possible to do better, since the CDict is not like a CCtx: the search
2109  * structures are written once during CDict creation, and then are only read
2110  * after that, while the search structures in the CCtx are both read and
2111  * written as the compression goes along. This means we can choose a search
2112  * structure for the dictionary that is read-optimized.
2113  *
2114  * This feature enables the use of that different structure.
2115  *
2116  * Note that some of the members of the ZSTD_compressionParameters struct have
2117  * different semantics and constraints in the dedicated search structure. It is
2118  * highly recommended that you simply set a compression level in the CCtxParams
2119  * you pass into the CDict creation call, and avoid messing with the cParams
2120  * directly.
2121  *
2122  * Effects:
2123  *
2124  * This will only have any effect when the selected ZSTD_strategy
2125  * implementation supports this feature. Currently, that's limited to
2126  * ZSTD_greedy, ZSTD_lazy, and ZSTD_lazy2.
2127  *
2128  * Note that this means that the CDict tables can no longer be copied into the
2129  * CCtx, so the dict attachment mode ZSTD_dictForceCopy will no longer be
2130  * usable. The dictionary can only be attached or reloaded.
2131  *
2132  * In general, you should expect compression to be faster--sometimes very much
2133  * so--and CDict creation to be slightly slower. Eventually, we will probably
2134  * make this mode the default.
2135  */
2136 #define ZSTD_c_enableDedicatedDictSearch ZSTD_c_experimentalParam8
2137 
2138 /* ZSTD_c_stableInBuffer
2139  * Experimental parameter.
2140  * Default is 0 == disabled. Set to 1 to enable.
2141  *
2142  * Tells the compressor that input data presented with ZSTD_inBuffer
2143  * will ALWAYS be the same between calls.
2144  * Technically, the @src pointer must never be changed,
2145  * and the @pos field can only be updated by zstd.
2146  * However, it's possible to increase the @size field,
2147  * allowing scenarios where more data can be appended after compressions starts.
2148  * These conditions are checked by the compressor,
2149  * and compression will fail if they are not respected.
2150  * Also, data in the ZSTD_inBuffer within the range [src, src + pos)
2151  * MUST not be modified during compression or it will result in data corruption.
2152  *
2153  * When this flag is enabled zstd won't allocate an input window buffer,
2154  * because the user guarantees it can reference the ZSTD_inBuffer until
2155  * the frame is complete. But, it will still allocate an output buffer
2156  * large enough to fit a block (see ZSTD_c_stableOutBuffer). This will also
2157  * avoid the memcpy() from the input buffer to the input window buffer.
2158  *
2159  * NOTE: So long as the ZSTD_inBuffer always points to valid memory, using
2160  * this flag is ALWAYS memory safe, and will never access out-of-bounds
2161  * memory. However, compression WILL fail if conditions are not respected.
2162  *
2163  * WARNING: The data in the ZSTD_inBuffer in the range [src, src + pos) MUST
2164  * not be modified during compression or it will result in data corruption.
2165  * This is because zstd needs to reference data in the ZSTD_inBuffer to find
2166  * matches. Normally zstd maintains its own window buffer for this purpose,
2167  * but passing this flag tells zstd to rely on user provided buffer instead.
2168  */
2169 #define ZSTD_c_stableInBuffer ZSTD_c_experimentalParam9
2170 
2171 /* ZSTD_c_stableOutBuffer
2172  * Experimental parameter.
2173  * Default is 0 == disabled. Set to 1 to enable.
2174  *
2175  * Tells he compressor that the ZSTD_outBuffer will not be resized between
2176  * calls. Specifically: (out.size - out.pos) will never grow. This gives the
2177  * compressor the freedom to say: If the compressed data doesn't fit in the
2178  * output buffer then return ZSTD_error_dstSizeTooSmall. This allows us to
2179  * always decompress directly into the output buffer, instead of decompressing
2180  * into an internal buffer and copying to the output buffer.
2181  *
2182  * When this flag is enabled zstd won't allocate an output buffer, because
2183  * it can write directly to the ZSTD_outBuffer. It will still allocate the
2184  * input window buffer (see ZSTD_c_stableInBuffer).
2185  *
2186  * Zstd will check that (out.size - out.pos) never grows and return an error
2187  * if it does. While not strictly necessary, this should prevent surprises.
2188  */
2189 #define ZSTD_c_stableOutBuffer ZSTD_c_experimentalParam10
2190 
2191 /* ZSTD_c_blockDelimiters
2192  * Default is 0 == ZSTD_sf_noBlockDelimiters.
2193  *
2194  * For use with sequence compression API: ZSTD_compressSequences().
2195  *
2196  * Designates whether or not the given array of ZSTD_Sequence contains block delimiters
2197  * and last literals, which are defined as sequences with offset == 0 and matchLength == 0.
2198  * See the definition of ZSTD_Sequence for more specifics.
2199  */
2200 #define ZSTD_c_blockDelimiters ZSTD_c_experimentalParam11
2201 
2202 /* ZSTD_c_validateSequences
2203  * Default is 0 == disabled. Set to 1 to enable sequence validation.
2204  *
2205  * For use with sequence compression API: ZSTD_compressSequences*().
2206  * Designates whether or not provided sequences are validated within ZSTD_compressSequences*()
2207  * during function execution.
2208  *
2209  * When Sequence validation is disabled (default), Sequences are compressed as-is,
2210  * so they must correct, otherwise it would result in a corruption error.
2211  *
2212  * Sequence validation adds some protection, by ensuring that all values respect boundary conditions.
2213  * If a Sequence is detected invalid (see doc/zstd_compression_format.md for
2214  * specifics regarding offset/matchlength requirements) then the function will bail out and
2215  * return an error.
2216  */
2217 #define ZSTD_c_validateSequences ZSTD_c_experimentalParam12
2218 
2219 /* ZSTD_c_blockSplitterLevel
2220  * note: this parameter only influences the first splitter stage,
2221  * which is active before producing the sequences.
2222  * ZSTD_c_splitAfterSequences controls the next splitter stage,
2223  * which is active after sequence production.
2224  * Note that both can be combined.
2225  * Allowed values are between 0 and ZSTD_BLOCKSPLITTER_LEVEL_MAX included.
2226  * 0 means "auto", which will select a value depending on current ZSTD_c_strategy.
2227  * 1 means no splitting.
2228  * Then, values from 2 to 6 are sorted in increasing cpu load order.
2229  *
2230  * Note that currently the first block is never split,
2231  * to ensure expansion guarantees in presence of incompressible data.
2232  */
2233 #define ZSTD_BLOCKSPLITTER_LEVEL_MAX 6
2234 #define ZSTD_c_blockSplitterLevel ZSTD_c_experimentalParam20
2235 
2236 /* ZSTD_c_splitAfterSequences
2237  * This is a stronger splitter algorithm,
2238  * based on actual sequences previously produced by the selected parser.
2239  * It's also slower, and as a consequence, mostly used for high compression levels.
2240  * While the post-splitter does overlap with the pre-splitter,
2241  * both can nonetheless be combined,
2242  * notably with ZSTD_c_blockSplitterLevel at ZSTD_BLOCKSPLITTER_LEVEL_MAX,
2243  * resulting in higher compression ratio than just one of them.
2244  *
2245  * Default is ZSTD_ps_auto.
2246  * Set to ZSTD_ps_disable to never use block splitter.
2247  * Set to ZSTD_ps_enable to always use block splitter.
2248  *
2249  * By default, in ZSTD_ps_auto, the library will decide at runtime whether to use
2250  * block splitting based on the compression parameters.
2251  */
2252 #define ZSTD_c_splitAfterSequences ZSTD_c_experimentalParam13
2253 
2254 /* ZSTD_c_useRowMatchFinder
2255  * Controlled with ZSTD_ParamSwitch_e enum.
2256  * Default is ZSTD_ps_auto.
2257  * Set to ZSTD_ps_disable to never use row-based matchfinder.
2258  * Set to ZSTD_ps_enable to force usage of row-based matchfinder.
2259  *
2260  * By default, in ZSTD_ps_auto, the library will decide at runtime whether to use
2261  * the row-based matchfinder based on support for SIMD instructions and the window log.
2262  * Note that this only pertains to compression strategies: greedy, lazy, and lazy2
2263  */
2264 #define ZSTD_c_useRowMatchFinder ZSTD_c_experimentalParam14
2265 
2266 /* ZSTD_c_deterministicRefPrefix
2267  * Default is 0 == disabled. Set to 1 to enable.
2268  *
2269  * Zstd produces different results for prefix compression when the prefix is
2270  * directly adjacent to the data about to be compressed vs. when it isn't.
2271  * This is because zstd detects that the two buffers are contiguous and it can
2272  * use a more efficient match finding algorithm. However, this produces different
2273  * results than when the two buffers are non-contiguous. This flag forces zstd
2274  * to always load the prefix in non-contiguous mode, even if it happens to be
2275  * adjacent to the data, to guarantee determinism.
2276  *
2277  * If you really care about determinism when using a dictionary or prefix,
2278  * like when doing delta compression, you should select this option. It comes
2279  * at a speed penalty of about ~2.5% if the dictionary and data happened to be
2280  * contiguous, and is free if they weren't contiguous. We don't expect that
2281  * intentionally making the dictionary and data contiguous will be worth the
2282  * cost to memcpy() the data.
2283  */
2284 #define ZSTD_c_deterministicRefPrefix ZSTD_c_experimentalParam15
2285 
2286 /* ZSTD_c_prefetchCDictTables
2287  * Controlled with ZSTD_ParamSwitch_e enum. Default is ZSTD_ps_auto.
2288  *
2289  * In some situations, zstd uses CDict tables in-place rather than copying them
2290  * into the working context. (See docs on ZSTD_dictAttachPref_e above for details).
2291  * In such situations, compression speed is seriously impacted when CDict tables are
2292  * "cold" (outside CPU cache). This parameter instructs zstd to prefetch CDict tables
2293  * when they are used in-place.
2294  *
2295  * For sufficiently small inputs, the cost of the prefetch will outweigh the benefit.
2296  * For sufficiently large inputs, zstd will by default memcpy() CDict tables
2297  * into the working context, so there is no need to prefetch. This parameter is
2298  * targeted at a middle range of input sizes, where a prefetch is cheap enough to be
2299  * useful but memcpy() is too expensive. The exact range of input sizes where this
2300  * makes sense is best determined by careful experimentation.
2301  *
2302  * Note: for this parameter, ZSTD_ps_auto is currently equivalent to ZSTD_ps_disable,
2303  * but in the future zstd may conditionally enable this feature via an auto-detection
2304  * heuristic for cold CDicts.
2305  * Use ZSTD_ps_disable to opt out of prefetching under any circumstances.
2306  */
2307 #define ZSTD_c_prefetchCDictTables ZSTD_c_experimentalParam16
2308 
2309 /* ZSTD_c_enableSeqProducerFallback
2310  * Allowed values are 0 (disable) and 1 (enable). The default setting is 0.
2311  *
2312  * Controls whether zstd will fall back to an internal sequence producer if an
2313  * external sequence producer is registered and returns an error code. This fallback
2314  * is block-by-block: the internal sequence producer will only be called for blocks
2315  * where the external sequence producer returns an error code. Fallback parsing will
2316  * follow any other cParam settings, such as compression level, the same as in a
2317  * normal (fully-internal) compression operation.
2318  *
2319  * The user is strongly encouraged to read the full Block-Level Sequence Producer API
2320  * documentation (below) before setting this parameter. */
2321 #define ZSTD_c_enableSeqProducerFallback ZSTD_c_experimentalParam17
2322 
2323 /* ZSTD_c_maxBlockSize
2324  * Allowed values are between 1KB and ZSTD_BLOCKSIZE_MAX (128KB).
2325  * The default is ZSTD_BLOCKSIZE_MAX, and setting to 0 will set to the default.
2326  *
2327  * This parameter can be used to set an upper bound on the blocksize
2328  * that overrides the default ZSTD_BLOCKSIZE_MAX. It cannot be used to set upper
2329  * bounds greater than ZSTD_BLOCKSIZE_MAX or bounds lower than 1KB (will make
2330  * compressBound() inaccurate). Only currently meant to be used for testing.
2331  */
2332 #define ZSTD_c_maxBlockSize ZSTD_c_experimentalParam18
2333 
2334 /* ZSTD_c_repcodeResolution
2335  * This parameter only has an effect if ZSTD_c_blockDelimiters is
2336  * set to ZSTD_sf_explicitBlockDelimiters (may change in the future).
2337  *
2338  * This parameter affects how zstd parses external sequences,
2339  * provided via the ZSTD_compressSequences*() API
2340  * or from an external block-level sequence producer.
2341  *
2342  * If set to ZSTD_ps_enable, the library will check for repeated offsets within
2343  * external sequences, even if those repcodes are not explicitly indicated in
2344  * the "rep" field. Note that this is the only way to exploit repcode matches
2345  * while using compressSequences*() or an external sequence producer, since zstd
2346  * currently ignores the "rep" field of external sequences.
2347  *
2348  * If set to ZSTD_ps_disable, the library will not exploit repeated offsets in
2349  * external sequences, regardless of whether the "rep" field has been set. This
2350  * reduces sequence compression overhead by about 25% while sacrificing some
2351  * compression ratio.
2352  *
2353  * The default value is ZSTD_ps_auto, for which the library will enable/disable
2354  * based on compression level (currently: level<10 disables, level>=10 enables).
2355  */
2356 #define ZSTD_c_repcodeResolution ZSTD_c_experimentalParam19
2357 #define ZSTD_c_searchForExternalRepcodes ZSTD_c_experimentalParam19 /* older name */
2358 
2359 
2365 ZSTDLIB_STATIC_API size_t ZSTD_CCtx_getParameter(const ZSTD_CCtx* cctx, ZSTD_cParameter param, int* value);
2366 
2367 
2385 ZSTDLIB_STATIC_API ZSTD_CCtx_params* ZSTD_createCCtxParams(void);
2386 ZSTDLIB_STATIC_API size_t ZSTD_freeCCtxParams(ZSTD_CCtx_params* params); /* accept NULL pointer */
2387 
2391 ZSTDLIB_STATIC_API size_t ZSTD_CCtxParams_reset(ZSTD_CCtx_params* params);
2392 
2397 ZSTDLIB_STATIC_API size_t ZSTD_CCtxParams_init(ZSTD_CCtx_params* cctxParams, int compressionLevel);
2398 
2403 ZSTDLIB_STATIC_API size_t ZSTD_CCtxParams_init_advanced(ZSTD_CCtx_params* cctxParams, ZSTD_parameters params);
2404 
2413 ZSTDLIB_STATIC_API size_t ZSTD_CCtxParams_setParameter(ZSTD_CCtx_params* params, ZSTD_cParameter param, int value);
2414 
2420 ZSTDLIB_STATIC_API size_t ZSTD_CCtxParams_getParameter(const ZSTD_CCtx_params* params, ZSTD_cParameter param, int* value);
2421 
2429 ZSTDLIB_STATIC_API size_t ZSTD_CCtx_setParametersUsingCCtxParams(
2430  ZSTD_CCtx* cctx, const ZSTD_CCtx_params* params);
2431 
2438 ZSTDLIB_STATIC_API size_t ZSTD_compressStream2_simpleArgs (
2439  ZSTD_CCtx* cctx,
2440  void* dst, size_t dstCapacity, size_t* dstPos,
2441  const void* src, size_t srcSize, size_t* srcPos,
2442  ZSTD_EndDirective endOp);
2443 
2444 
2445 /***************************************
2446 * Advanced decompression functions
2447 ***************************************/
2448 
2454 ZSTDLIB_STATIC_API unsigned ZSTD_isFrame(const void* buffer, size_t size);
2455 
2461 ZSTDLIB_STATIC_API ZSTD_DDict* ZSTD_createDDict_byReference(const void* dictBuffer, size_t dictSize);
2462 
2468 ZSTDLIB_STATIC_API size_t ZSTD_DCtx_loadDictionary_byReference(ZSTD_DCtx* dctx, const void* dict, size_t dictSize);
2469 
2475 ZSTDLIB_STATIC_API size_t ZSTD_DCtx_loadDictionary_advanced(ZSTD_DCtx* dctx, const void* dict, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictContentType_e dictContentType);
2476 
2480 ZSTDLIB_STATIC_API size_t ZSTD_DCtx_refPrefix_advanced(ZSTD_DCtx* dctx, const void* prefix, size_t prefixSize, ZSTD_dictContentType_e dictContentType);
2481 
2489 ZSTDLIB_STATIC_API size_t ZSTD_DCtx_setMaxWindowSize(ZSTD_DCtx* dctx, size_t maxWindowSize);
2490 
2496 ZSTDLIB_STATIC_API size_t ZSTD_DCtx_getParameter(ZSTD_DCtx* dctx, ZSTD_dParameter param, int* value);
2497 
2498 /* ZSTD_d_format
2499  * experimental parameter,
2500  * allowing selection between ZSTD_format_e input compression formats
2501  */
2502 #define ZSTD_d_format ZSTD_d_experimentalParam1
2503 /* ZSTD_d_stableOutBuffer
2504  * Experimental parameter.
2505  * Default is 0 == disabled. Set to 1 to enable.
2506  *
2507  * Tells the decompressor that the ZSTD_outBuffer will ALWAYS be the same
2508  * between calls, except for the modifications that zstd makes to pos (the
2509  * caller must not modify pos). This is checked by the decompressor, and
2510  * decompression will fail if it ever changes. Therefore the ZSTD_outBuffer
2511  * MUST be large enough to fit the entire decompressed frame. This will be
2512  * checked when the frame content size is known. The data in the ZSTD_outBuffer
2513  * in the range [dst, dst + pos) MUST not be modified during decompression
2514  * or you will get data corruption.
2515  *
2516  * When this flag is enabled zstd won't allocate an output buffer, because
2517  * it can write directly to the ZSTD_outBuffer, but it will still allocate
2518  * an input buffer large enough to fit any compressed block. This will also
2519  * avoid the memcpy() from the internal output buffer to the ZSTD_outBuffer.
2520  * If you need to avoid the input buffer allocation use the buffer-less
2521  * streaming API.
2522  *
2523  * NOTE: So long as the ZSTD_outBuffer always points to valid memory, using
2524  * this flag is ALWAYS memory safe, and will never access out-of-bounds
2525  * memory. However, decompression WILL fail if you violate the preconditions.
2526  *
2527  * WARNING: The data in the ZSTD_outBuffer in the range [dst, dst + pos) MUST
2528  * not be modified during decompression or you will get data corruption. This
2529  * is because zstd needs to reference data in the ZSTD_outBuffer to regenerate
2530  * matches. Normally zstd maintains its own buffer for this purpose, but passing
2531  * this flag tells zstd to use the user provided buffer.
2532  */
2533 #define ZSTD_d_stableOutBuffer ZSTD_d_experimentalParam2
2534 
2535 /* ZSTD_d_forceIgnoreChecksum
2536  * Experimental parameter.
2537  * Default is 0 == disabled. Set to 1 to enable
2538  *
2539  * Tells the decompressor to skip checksum validation during decompression, regardless
2540  * of whether checksumming was specified during compression. This offers some
2541  * slight performance benefits, and may be useful for debugging.
2542  * Param has values of type ZSTD_forceIgnoreChecksum_e
2543  */
2544 #define ZSTD_d_forceIgnoreChecksum ZSTD_d_experimentalParam3
2545 
2546 /* ZSTD_d_refMultipleDDicts
2547  * Experimental parameter.
2548  * Default is 0 == disabled. Set to 1 to enable
2549  *
2550  * If enabled and dctx is allocated on the heap, then additional memory will be allocated
2551  * to store references to multiple ZSTD_DDict. That is, multiple calls of ZSTD_refDDict()
2552  * using a given ZSTD_DCtx, rather than overwriting the previous DDict reference, will instead
2553  * store all references. At decompression time, the appropriate dictID is selected
2554  * from the set of DDicts based on the dictID in the frame.
2555  *
2556  * Usage is simply calling ZSTD_refDDict() on multiple dict buffers.
2557  *
2558  * Param has values of byte ZSTD_refMultipleDDicts_e
2559  *
2560  * WARNING: Enabling this parameter and calling ZSTD_DCtx_refDDict(), will trigger memory
2561  * allocation for the hash table. ZSTD_freeDCtx() also frees this memory.
2562  * Memory is allocated as per ZSTD_DCtx::customMem.
2563  *
2564  * Although this function allocates memory for the table, the user is still responsible for
2565  * memory management of the underlying ZSTD_DDict* themselves.
2566  */
2567 #define ZSTD_d_refMultipleDDicts ZSTD_d_experimentalParam4
2568 
2569 /* ZSTD_d_disableHuffmanAssembly
2570  * Set to 1 to disable the Huffman assembly implementation.
2571  * The default value is 0, which allows zstd to use the Huffman assembly
2572  * implementation if available.
2573  *
2574  * This parameter can be used to disable Huffman assembly at runtime.
2575  * If you want to disable it at compile time you can define the macro
2576  * ZSTD_DISABLE_ASM.
2577  */
2578 #define ZSTD_d_disableHuffmanAssembly ZSTD_d_experimentalParam5
2579 
2580 /* ZSTD_d_maxBlockSize
2581  * Allowed values are between 1KB and ZSTD_BLOCKSIZE_MAX (128KB).
2582  * The default is ZSTD_BLOCKSIZE_MAX, and setting to 0 will set to the default.
2583  *
2584  * Forces the decompressor to reject blocks whose content size is
2585  * larger than the configured maxBlockSize. When maxBlockSize is
2586  * larger than the windowSize, the windowSize is used instead.
2587  * This saves memory on the decoder when you know all blocks are small.
2588  *
2589  * This option is typically used in conjunction with ZSTD_c_maxBlockSize.
2590  *
2591  * WARNING: This causes the decoder to reject otherwise valid frames
2592  * that have block sizes larger than the configured maxBlockSize.
2593  */
2594 #define ZSTD_d_maxBlockSize ZSTD_d_experimentalParam6
2595 
2596 
2603 ZSTD_DEPRECATED("use ZSTD_DCtx_setParameter() instead")
2604 ZSTDLIB_STATIC_API
2605 size_t ZSTD_DCtx_setFormat(ZSTD_DCtx* dctx, ZSTD_format_e format);
2606 
2613 ZSTDLIB_STATIC_API size_t ZSTD_decompressStream_simpleArgs (
2614  ZSTD_DCtx* dctx,
2615  void* dst, size_t dstCapacity, size_t* dstPos,
2616  const void* src, size_t srcSize, size_t* srcPos);
2617 
2618 
2619 /********************************************************************
2620 * Advanced streaming functions
2621 * Warning : most of these functions are now redundant with the Advanced API.
2622 * Once Advanced API reaches "stable" status,
2623 * redundant functions will be deprecated, and then at some point removed.
2624 ********************************************************************/
2625 
2626 /*===== Advanced Streaming compression functions =====*/
2627 
2640 ZSTD_DEPRECATED("use ZSTD_CCtx_reset, see zstd.h for detailed instructions")
2641 ZSTDLIB_STATIC_API
2643  int compressionLevel,
2644  unsigned long long pledgedSrcSize);
2645 
2658 ZSTD_DEPRECATED("use ZSTD_CCtx_reset, see zstd.h for detailed instructions")
2659 ZSTDLIB_STATIC_API
2661  const void* dict, size_t dictSize,
2662  int compressionLevel);
2663 
2676 ZSTD_DEPRECATED("use ZSTD_CCtx_reset, see zstd.h for detailed instructions")
2677 ZSTDLIB_STATIC_API
2679  const void* dict, size_t dictSize,
2680  ZSTD_parameters params,
2681  unsigned long long pledgedSrcSize);
2682 
2691 ZSTD_DEPRECATED("use ZSTD_CCtx_reset and ZSTD_CCtx_refCDict, see zstd.h for detailed instructions")
2692 ZSTDLIB_STATIC_API
2693 size_t ZSTD_initCStream_usingCDict(ZSTD_CStream* zcs, const ZSTD_CDict* cdict);
2694 
2707 ZSTD_DEPRECATED("use ZSTD_CCtx_reset and ZSTD_CCtx_refCDict, see zstd.h for detailed instructions")
2708 ZSTDLIB_STATIC_API
2710  const ZSTD_CDict* cdict,
2711  ZSTD_frameParameters fParams,
2712  unsigned long long pledgedSrcSize);
2713 
2732 ZSTD_DEPRECATED("use ZSTD_CCtx_reset, see zstd.h for detailed instructions")
2733 ZSTDLIB_STATIC_API
2734 size_t ZSTD_resetCStream(ZSTD_CStream* zcs, unsigned long long pledgedSrcSize);
2735 
2736 
2737 typedef struct {
2738  unsigned long long ingested; /* nb input bytes read and buffered */
2739  unsigned long long consumed; /* nb input bytes actually compressed */
2740  unsigned long long produced; /* nb of compressed bytes generated and buffered */
2741  unsigned long long flushed; /* nb of compressed bytes flushed : not provided; can be tracked from caller side */
2742  unsigned currentJobID; /* MT only : latest started job nb */
2743  unsigned nbActiveWorkers; /* MT only : nb of workers actively compressing at probe time */
2745 
2746 /* ZSTD_getFrameProgression() :
2747  * tells how much data has been ingested (read from input)
2748  * consumed (input actually compressed) and produced (output) for current frame.
2749  * Note : (ingested - consumed) is amount of input data buffered internally, not yet compressed.
2750  * Aggregates progression inside active worker threads.
2751  */
2752 ZSTDLIB_STATIC_API ZSTD_frameProgression ZSTD_getFrameProgression(const ZSTD_CCtx* cctx);
2753 
2767 ZSTDLIB_STATIC_API size_t ZSTD_toFlushNow(ZSTD_CCtx* cctx);
2768 
2769 
2770 /*===== Advanced Streaming decompression functions =====*/
2771 
2780 ZSTD_DEPRECATED("use ZSTD_DCtx_reset + ZSTD_DCtx_loadDictionary, see zstd.h for detailed instructions")
2781 ZSTDLIB_STATIC_API size_t ZSTD_initDStream_usingDict(ZSTD_DStream* zds, const void* dict, size_t dictSize);
2782 
2791 ZSTD_DEPRECATED("use ZSTD_DCtx_reset + ZSTD_DCtx_refDDict, see zstd.h for detailed instructions")
2792 ZSTDLIB_STATIC_API size_t ZSTD_initDStream_usingDDict(ZSTD_DStream* zds, const ZSTD_DDict* ddict);
2793 
2801 ZSTD_DEPRECATED("use ZSTD_DCtx_reset, see zstd.h for detailed instructions")
2802 ZSTDLIB_STATIC_API size_t ZSTD_resetDStream(ZSTD_DStream* zds);
2803 
2804 
2805 /* ********************* BLOCK-LEVEL SEQUENCE PRODUCER API *********************
2806  *
2807  * *** OVERVIEW ***
2808  * The Block-Level Sequence Producer API allows users to provide their own custom
2809  * sequence producer which libzstd invokes to process each block. The produced list
2810  * of sequences (literals and matches) is then post-processed by libzstd to produce
2811  * valid compressed blocks.
2812  *
2813  * This block-level offload API is a more granular complement of the existing
2814  * frame-level offload API compressSequences() (introduced in v1.5.1). It offers
2815  * an easier migration story for applications already integrated with libzstd: the
2816  * user application continues to invoke the same compression functions
2817  * ZSTD_compress2() or ZSTD_compressStream2() as usual, and transparently benefits
2818  * from the specific advantages of the external sequence producer. For example,
2819  * the sequence producer could be tuned to take advantage of known characteristics
2820  * of the input, to offer better speed / ratio, or could leverage hardware
2821  * acceleration not available within libzstd itself.
2822  *
2823  * See contrib/externalSequenceProducer for an example program employing the
2824  * Block-Level Sequence Producer API.
2825  *
2826  * *** USAGE ***
2827  * The user is responsible for implementing a function of type
2828  * ZSTD_sequenceProducer_F. For each block, zstd will pass the following
2829  * arguments to the user-provided function:
2830  *
2831  * - sequenceProducerState: a pointer to a user-managed state for the sequence
2832  * producer.
2833  *
2834  * - outSeqs, outSeqsCapacity: an output buffer for the sequence producer.
2835  * outSeqsCapacity is guaranteed >= ZSTD_sequenceBound(srcSize). The memory
2836  * backing outSeqs is managed by the CCtx.
2837  *
2838  * - src, srcSize: an input buffer for the sequence producer to parse.
2839  * srcSize is guaranteed to be <= ZSTD_BLOCKSIZE_MAX.
2840  *
2841  * - dict, dictSize: a history buffer, which may be empty, which the sequence
2842  * producer may reference as it parses the src buffer. Currently, zstd will
2843  * always pass dictSize == 0 into external sequence producers, but this will
2844  * change in the future.
2845  *
2846  * - compressionLevel: a signed integer representing the zstd compression level
2847  * set by the user for the current operation. The sequence producer may choose
2848  * to use this information to change its compression strategy and speed/ratio
2849  * tradeoff. Note: the compression level does not reflect zstd parameters set
2850  * through the advanced API.
2851  *
2852  * - windowSize: a size_t representing the maximum allowed offset for external
2853  * sequences. Note that sequence offsets are sometimes allowed to exceed the
2854  * windowSize if a dictionary is present, see doc/zstd_compression_format.md
2855  * for details.
2856  *
2857  * The user-provided function shall return a size_t representing the number of
2858  * sequences written to outSeqs. This return value will be treated as an error
2859  * code if it is greater than outSeqsCapacity. The return value must be non-zero
2860  * if srcSize is non-zero. The ZSTD_SEQUENCE_PRODUCER_ERROR macro is provided
2861  * for convenience, but any value greater than outSeqsCapacity will be treated as
2862  * an error code.
2863  *
2864  * If the user-provided function does not return an error code, the sequences
2865  * written to outSeqs must be a valid parse of the src buffer. Data corruption may
2866  * occur if the parse is not valid. A parse is defined to be valid if the
2867  * following conditions hold:
2868  * - The sum of matchLengths and literalLengths must equal srcSize.
2869  * - All sequences in the parse, except for the final sequence, must have
2870  * matchLength >= ZSTD_MINMATCH_MIN. The final sequence must have
2871  * matchLength >= ZSTD_MINMATCH_MIN or matchLength == 0.
2872  * - All offsets must respect the windowSize parameter as specified in
2873  * doc/zstd_compression_format.md.
2874  * - If the final sequence has matchLength == 0, it must also have offset == 0.
2875  *
2876  * zstd will only validate these conditions (and fail compression if they do not
2877  * hold) if the ZSTD_c_validateSequences cParam is enabled. Note that sequence
2878  * validation has a performance cost.
2879  *
2880  * If the user-provided function returns an error, zstd will either fall back
2881  * to an internal sequence producer or fail the compression operation. The user can
2882  * choose between the two behaviors by setting the ZSTD_c_enableSeqProducerFallback
2883  * cParam. Fallback compression will follow any other cParam settings, such as
2884  * compression level, the same as in a normal compression operation.
2885  *
2886  * The user shall instruct zstd to use a particular ZSTD_sequenceProducer_F
2887  * function by calling
2888  * ZSTD_registerSequenceProducer(cctx,
2889  * sequenceProducerState,
2890  * sequenceProducer)
2891  * This setting will persist until the next parameter reset of the CCtx.
2892  *
2893  * The sequenceProducerState must be initialized by the user before calling
2894  * ZSTD_registerSequenceProducer(). The user is responsible for destroying the
2895  * sequenceProducerState.
2896  *
2897  * *** LIMITATIONS ***
2898  * This API is compatible with all zstd compression APIs which respect advanced parameters.
2899  * However, there are three limitations:
2900  *
2901  * First, the ZSTD_c_enableLongDistanceMatching cParam is not currently supported.
2902  * COMPRESSION WILL FAIL if it is enabled and the user tries to compress with a block-level
2903  * external sequence producer.
2904  * - Note that ZSTD_c_enableLongDistanceMatching is auto-enabled by default in some
2905  * cases (see its documentation for details). Users must explicitly set
2906  * ZSTD_c_enableLongDistanceMatching to ZSTD_ps_disable in such cases if an external
2907  * sequence producer is registered.
2908  * - As of this writing, ZSTD_c_enableLongDistanceMatching is disabled by default
2909  * whenever ZSTD_c_windowLog < 128MB, but that's subject to change. Users should
2910  * check the docs on ZSTD_c_enableLongDistanceMatching whenever the Block-Level Sequence
2911  * Producer API is used in conjunction with advanced settings (like ZSTD_c_windowLog).
2912  *
2913  * Second, history buffers are not currently supported. Concretely, zstd will always pass
2914  * dictSize == 0 to the external sequence producer (for now). This has two implications:
2915  * - Dictionaries are not currently supported. Compression will *not* fail if the user
2916  * references a dictionary, but the dictionary won't have any effect.
2917  * - Stream history is not currently supported. All advanced compression APIs, including
2918  * streaming APIs, work with external sequence producers, but each block is treated as
2919  * an independent chunk without history from previous blocks.
2920  *
2921  * Third, multi-threading within a single compression is not currently supported. In other words,
2922  * COMPRESSION WILL FAIL if ZSTD_c_nbWorkers > 0 and an external sequence producer is registered.
2923  * Multi-threading across compressions is fine: simply create one CCtx per thread.
2924  *
2925  * Long-term, we plan to overcome all three limitations. There is no technical blocker to
2926  * overcoming them. It is purely a question of engineering effort.
2927  */
2928 
2929 #define ZSTD_SEQUENCE_PRODUCER_ERROR ((size_t)(-1))
2930 
2931 typedef size_t (*ZSTD_sequenceProducer_F) (
2932  void* sequenceProducerState,
2933  ZSTD_Sequence* outSeqs, size_t outSeqsCapacity,
2934  const void* src, size_t srcSize,
2935  const void* dict, size_t dictSize,
2936  int compressionLevel,
2937  size_t windowSize
2938 );
2939 
2959 ZSTDLIB_STATIC_API void
2961  ZSTD_CCtx* cctx,
2962  void* sequenceProducerState,
2963  ZSTD_sequenceProducer_F sequenceProducer
2964 );
2965 
2975 ZSTDLIB_STATIC_API void
2977  ZSTD_CCtx_params* params,
2978  void* sequenceProducerState,
2979  ZSTD_sequenceProducer_F sequenceProducer
2980 );
2981 
2982 
2983 /*********************************************************************
2984 * Buffer-less and synchronous inner streaming functions (DEPRECATED)
2985 *
2986 * This API is deprecated, and will be removed in a future version.
2987 * It allows streaming (de)compression with user allocated buffers.
2988 * However, it is hard to use, and not as well tested as the rest of
2989 * our API.
2990 *
2991 * Please use the normal streaming API instead: ZSTD_compressStream2,
2992 * and ZSTD_decompressStream.
2993 * If there is functionality that you need, but it doesn't provide,
2994 * please open an issue on our GitHub.
2995 ********************************************************************* */
2996 
3026 /*===== Buffer-less streaming compression functions =====*/
3027 ZSTD_DEPRECATED("The buffer-less API is deprecated in favor of the normal streaming API. See docs.")
3028 ZSTDLIB_STATIC_API size_t ZSTD_compressBegin(ZSTD_CCtx* cctx, int compressionLevel);
3029 ZSTD_DEPRECATED("The buffer-less API is deprecated in favor of the normal streaming API. See docs.")
3030 ZSTDLIB_STATIC_API size_t ZSTD_compressBegin_usingDict(ZSTD_CCtx* cctx, const void* dict, size_t dictSize, int compressionLevel);
3031 ZSTD_DEPRECATED("The buffer-less API is deprecated in favor of the normal streaming API. See docs.")
3032 ZSTDLIB_STATIC_API size_t ZSTD_compressBegin_usingCDict(ZSTD_CCtx* cctx, const ZSTD_CDict* cdict);
3034 ZSTD_DEPRECATED("This function will likely be removed in a future release. It is misleading and has very limited utility.")
3035 ZSTDLIB_STATIC_API
3036 size_t ZSTD_copyCCtx(ZSTD_CCtx* cctx, const ZSTD_CCtx* preparedCCtx, unsigned long long pledgedSrcSize);
3038 ZSTD_DEPRECATED("The buffer-less API is deprecated in favor of the normal streaming API. See docs.")
3039 ZSTDLIB_STATIC_API size_t ZSTD_compressContinue(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize);
3040 ZSTD_DEPRECATED("The buffer-less API is deprecated in favor of the normal streaming API. See docs.")
3041 ZSTDLIB_STATIC_API size_t ZSTD_compressEnd(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize);
3042 
3043 /* The ZSTD_compressBegin_advanced() and ZSTD_compressBegin_usingCDict_advanced() are now DEPRECATED and will generate a compiler warning */
3044 ZSTD_DEPRECATED("use advanced API to access custom parameters")
3045 ZSTDLIB_STATIC_API
3046 size_t ZSTD_compressBegin_advanced(ZSTD_CCtx* cctx, const void* dict, size_t dictSize, ZSTD_parameters params, unsigned long long pledgedSrcSize);
3047 ZSTD_DEPRECATED("use advanced API to access custom parameters")
3048 ZSTDLIB_STATIC_API
3049 size_t ZSTD_compressBegin_usingCDict_advanced(ZSTD_CCtx* const cctx, const ZSTD_CDict* const cdict, ZSTD_frameParameters const fParams, unsigned long long const pledgedSrcSize); /* compression parameters are already set within cdict. pledgedSrcSize must be correct. If srcSize is not known, use macro ZSTD_CONTENTSIZE_UNKNOWN */
3123 /*===== Buffer-less streaming decompression functions =====*/
3124 
3125 ZSTDLIB_STATIC_API size_t ZSTD_decodingBufferSize_min(unsigned long long windowSize, unsigned long long frameContentSize);
3127 ZSTDLIB_STATIC_API size_t ZSTD_decompressBegin(ZSTD_DCtx* dctx);
3128 ZSTDLIB_STATIC_API size_t ZSTD_decompressBegin_usingDict(ZSTD_DCtx* dctx, const void* dict, size_t dictSize);
3129 ZSTDLIB_STATIC_API size_t ZSTD_decompressBegin_usingDDict(ZSTD_DCtx* dctx, const ZSTD_DDict* ddict);
3130 
3131 ZSTDLIB_STATIC_API size_t ZSTD_nextSrcSizeToDecompress(ZSTD_DCtx* dctx);
3132 ZSTDLIB_STATIC_API size_t ZSTD_decompressContinue(ZSTD_DCtx* dctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize);
3133 
3134 /* misc */
3135 ZSTD_DEPRECATED("This function will likely be removed in the next minor release. It is misleading and has very limited utility.")
3136 ZSTDLIB_STATIC_API void ZSTD_copyDCtx(ZSTD_DCtx* dctx, const ZSTD_DCtx* preparedDCtx);
3137 typedef enum { ZSTDnit_frameHeader, ZSTDnit_blockHeader, ZSTDnit_block, ZSTDnit_lastBlock, ZSTDnit_checksum, ZSTDnit_skippableFrame } ZSTD_nextInputType_e;
3138 ZSTDLIB_STATIC_API ZSTD_nextInputType_e ZSTD_nextInputType(ZSTD_DCtx* dctx);
3139 
3140 
3141 
3152 ZSTDLIB_API int ZSTD_isDeterministicBuild(void);
3153 
3154 
3155 /* ========================================= */
3157 /* ========================================= */
3158 
3197 /*===== Raw zstd block functions =====*/
3198 ZSTD_DEPRECATED("The block API is deprecated in favor of the normal compression API. See docs.")
3199 ZSTDLIB_STATIC_API size_t ZSTD_getBlockSize (const ZSTD_CCtx* cctx);
3200 ZSTD_DEPRECATED("The block API is deprecated in favor of the normal compression API. See docs.")
3201 ZSTDLIB_STATIC_API size_t ZSTD_compressBlock (ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize);
3202 ZSTD_DEPRECATED("The block API is deprecated in favor of the normal compression API. See docs.")
3203 ZSTDLIB_STATIC_API size_t ZSTD_decompressBlock(ZSTD_DCtx* dctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize);
3204 ZSTD_DEPRECATED("The block API is deprecated in favor of the normal compression API. See docs.")
3205 ZSTDLIB_STATIC_API size_t ZSTD_insertBlock (ZSTD_DCtx* dctx, const void* blockStart, size_t blockSize);
3207 #if defined (__cplusplus)
3208 }
3209 #endif
3210 
3211 #endif /* ZSTD_H_ZSTD_STATIC_LINKING_ONLY */
Definition: zstd.c:7663
Definition: zstd.c:19546
Definition: zstd.c:19656
Definition: zstd.c:23064
Definition: zstd.c:41402
Definition: zstd.c:41573
Definition: zstd.c:5825
Definition: zstd.c:5628
Definition: zstd.c:4861
Definition: zstd.c:5665
Definition: zstd.c:6183
Definition: zstd.c:5675
Definition: zstd.c:7048
Definition: zstd.c:5018
const void * src
Definition: zstd.c:5019
size_t size
Definition: zstd.c:5020
size_t pos
Definition: zstd.c:5021
Definition: zstd.c:5024
void * dst
Definition: zstd.c:5025
size_t size
Definition: zstd.c:5026
size_t pos
Definition: zstd.c:5027
Definition: zstd.c:5681
ZSTDLIB_API size_t ZSTD_CCtx_setParameter(ZSTD_CCtx *cctx, ZSTD_cParameter param, int value)
Definition: zstd.c:23700
ZSTDLIB_API size_t ZSTD_compressBound(size_t srcSize)
Definition: zstd.c:23054
ZSTDLIB_API size_t ZSTD_compressStream(ZSTD_CStream *zcs, ZSTD_outBuffer *output, ZSTD_inBuffer *input)
Definition: zstd.c:29293
ZSTDLIB_STATIC_API 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)
Definition: zstd.c:29538
ZSTDLIB_STATIC_API size_t ZSTD_initCStream_usingCDict(ZSTD_CStream *zcs, const ZSTD_CDict *cdict)
Definition: zstd.c:29014
ZSTDLIB_API size_t ZSTD_sizeof_CCtx(const ZSTD_CCtx *cctx)
Definition: zstd.c:23190
ZSTDLIB_STATIC_API size_t ZSTD_DCtx_loadDictionary_advanced(ZSTD_DCtx *dctx, const void *dict, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictContentType_e dictContentType)
Definition: zstd.c:43552
ZSTDLIB_STATIC_API size_t ZSTD_decodingBufferSize_min(unsigned long long windowSize, unsigned long long frameContentSize)
Definition: zstd.c:43841
ZSTDLIB_STATIC_API size_t ZSTD_DCtx_getParameter(ZSTD_DCtx *dctx, ZSTD_dParameter param, int *value)
Definition: zstd.c:43730
ZSTDLIB_API ZSTD_bounds ZSTD_dParam_getBounds(ZSTD_dParameter dParam)
Definition: zstd.c:43674
ZSTDLIB_API size_t ZSTD_endStream(ZSTD_CStream *zcs, ZSTD_outBuffer *output)
Definition: zstd.c:30646
ZSTDLIB_STATIC_API size_t ZSTD_getBlockSize(const ZSTD_CCtx *cctx)
Definition: zstd.c:27869
ZSTDLIB_STATIC_API size_t ZSTD_writeSkippableFrame(void *dst, size_t dstCapacity, const void *src, size_t srcSize, unsigned magicVariant)
Definition: zstd.c:27743
ZSTDLIB_API size_t ZSTD_freeCDict(ZSTD_CDict *CDict)
Definition: zstd.c:28724
ZSTDLIB_STATIC_API ZSTD_CDict * ZSTD_createCDict_byReference(const void *dictBuffer, size_t dictSize, int compressionLevel)
Definition: zstd.c:28713
ZSTDLIB_API size_t ZSTD_compressCCtx(ZSTD_CCtx *cctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, int compressionLevel)
Definition: zstd.c:28479
ZSTDLIB_API size_t ZSTD_CCtx_refPrefix(ZSTD_CCtx *cctx, const void *prefix, size_t prefixSize)
Definition: zstd.c:24338
ZSTDLIB_STATIC_API size_t ZSTD_CCtxParams_setParameter(ZSTD_CCtx_params *params, ZSTD_cParameter param, int value)
Definition: zstd.c:23762
ZSTDLIB_API unsigned ZSTD_getDictID_fromDDict(const ZSTD_DDict *ddict)
Definition: zstd.c:41777
ZSTDLIB_STATIC_API size_t ZSTD_compressBegin(ZSTD_CCtx *cctx, int compressionLevel)
Definition: zstd.c:28327
ZSTDLIB_STATIC_API size_t ZSTD_DCtx_loadDictionary_byReference(ZSTD_DCtx *dctx, const void *dict, size_t dictSize)
Definition: zstd.c:43568
ZSTDLIB_STATIC_API size_t ZSTD_compressBegin_usingCDict(ZSTD_CCtx *cctx, const ZSTD_CDict *cdict)
Definition: zstd.c:28871
ZSTDLIB_STATIC_API size_t ZSTD_resetCStream(ZSTD_CStream *zcs, unsigned long long pledgedSrcSize)
Definition: zstd.c:28961
ZSTDLIB_STATIC_API size_t ZSTD_CCtx_setFParams(ZSTD_CCtx *cctx, ZSTD_frameParameters fparams)
Definition: zstd.c:24200
ZSTDLIB_STATIC_API ZSTD_CStream * ZSTD_initStaticCStream(void *workspace, size_t workspaceSize)
Definition: zstd.c:28925
ZSTDLIB_API size_t ZSTD_DCtx_loadDictionary(ZSTD_DCtx *dctx, const void *dict, size_t dictSize)
Definition: zstd.c:43573
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)
Definition: zstd.c:28904
ZSTDLIB_STATIC_API size_t ZSTD_mergeBlockDelimiters(ZSTD_Sequence *sequences, size_t seqsSize)
Definition: zstd.c:26547
ZSTDLIB_STATIC_API size_t ZSTD_initDStream_usingDDict(ZSTD_DStream *zds, const ZSTD_DDict *ddict)
Definition: zstd.c:43614
ZSTDLIB_STATIC_API size_t ZSTD_compressSequences(ZSTD_CCtx *cctx, void *dst, size_t dstCapacity, const ZSTD_Sequence *inSeqs, size_t inSeqsSize, const void *src, size_t srcSize)
Definition: zstd.c:30055
ZSTDLIB_API size_t ZSTD_DCtx_refPrefix(ZSTD_DCtx *dctx, const void *prefix, size_t prefixSize)
Definition: zstd.c:43585
ZSTDLIB_API size_t ZSTD_compress2(ZSTD_CCtx *cctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize)
Definition: zstd.c:29560
ZSTDLIB_API size_t ZSTD_DCtx_setParameter(ZSTD_DCtx *dctx, ZSTD_dParameter param, int value)
Definition: zstd.c:43759
ZSTDLIB_STATIC_API size_t ZSTD_checkCParams(ZSTD_compressionParameters params)
Definition: zstd.c:24380
ZSTDLIB_API size_t ZSTD_decompressStream(ZSTD_DStream *zds, ZSTD_outBuffer *output, ZSTD_inBuffer *input)
Definition: zstd.c:43939
ZSTDLIB_API ZSTD_DDict * ZSTD_createDDict(const void *dictBuffer, size_t dictSize)
Definition: zstd.c:41707
ZSTDLIB_API size_t ZSTD_flushStream(ZSTD_CStream *zcs, ZSTD_outBuffer *output)
Definition: zstd.c:30639
ZSTDLIB_STATIC_API ZSTD_CCtx * ZSTD_initStaticCCtx(void *workspace, size_t workspaceSize)
Definition: zstd.c:23110
ZSTDLIB_STATIC_API size_t ZSTD_estimateDDictSize(size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod)
Definition: zstd.c:41762
ZSTDLIB_STATIC_API size_t ZSTD_initCStream_usingCDict_advanced(ZSTD_CStream *zcs, const ZSTD_CDict *cdict, ZSTD_frameParameters fParams, unsigned long long pledgedSrcSize)
Definition: zstd.c:29000
ZSTD_literalCompressionMode_e
Definition: zstd.c:5755
@ ZSTD_lcm_huffman
Definition: zstd.c:5759
@ ZSTD_lcm_uncompressed
Definition: zstd.c:5761
@ ZSTD_lcm_auto
Definition: zstd.c:5756
ZSTDLIB_STATIC_API size_t ZSTD_estimateCDictSize_advanced(size_t dictSize, ZSTD_compressionParameters cParams, ZSTD_dictLoadMethod_e dictLoadMethod)
Definition: zstd.c:28513
ZSTDLIB_STATIC_API size_t ZSTD_resetDStream(ZSTD_DStream *zds)
Definition: zstd.c:43625
ZSTDLIB_API int ZSTD_defaultCLevel(void)
Definition: zstd.c:30802
ZSTDLIB_STATIC_API size_t ZSTD_CCtxParams_init(ZSTD_CCtx_params *cctxParams, int compressionLevel)
Definition: zstd.c:23350
ZSTDLIB_API size_t ZSTD_compressStream2(ZSTD_CCtx *cctx, ZSTD_outBuffer *output, ZSTD_inBuffer *input, ZSTD_EndDirective endOp)
Definition: zstd.c:29439
ZSTDLIB_STATIC_API ZSTD_CCtx_params * ZSTD_createCCtxParams(void)
Definition: zstd.c:23333
ZSTDLIB_API size_t ZSTD_DCtx_reset(ZSTD_DCtx *dctx, ZSTD_ResetDirective reset)
Definition: zstd.c:43800
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)
Definition: zstd.c:43024
ZSTDLIB_STATIC_API size_t ZSTD_CCtx_loadDictionary_byReference(ZSTD_CCtx *cctx, const void *dict, size_t dictSize)
Definition: zstd.c:24306
ZSTDLIB_API unsigned long long ZSTD_getDecompressedSize(const void *src, size_t srcSize)
Definition: zstd.c:42543
ZSTDLIB_API size_t ZSTD_CCtx_reset(ZSTD_CCtx *cctx, ZSTD_ResetDirective reset)
Definition: zstd.c:24359
ZSTDLIB_API size_t ZSTD_freeDDict(ZSTD_DDict *ddict)
Definition: zstd.c:41749
ZSTDLIB_STATIC_API size_t ZSTD_sequenceBound(size_t srcSize)
Definition: zstd.c:26506
ZSTDLIB_STATIC_API size_t ZSTD_toFlushNow(ZSTD_CCtx *cctx)
Definition: zstd.c:24885
ZSTDLIB_API size_t ZSTD_initDStream(ZSTD_DStream *zds)
Definition: zstd.c:43603
ZSTDLIB_API size_t ZSTD_CCtx_refCDict(ZSTD_CCtx *cctx, const ZSTD_CDict *cdict)
Definition: zstd.c:24320
ZSTDLIB_API size_t ZSTD_initCStream(ZSTD_CStream *zcs, int compressionLevel)
Definition: zstd.c:29069
ZSTDLIB_API size_t ZSTD_CStreamInSize(void)
Definition: zstd.c:28944
ZSTDLIB_API unsigned ZSTD_getDictID_fromCDict(const ZSTD_CDict *cdict)
Definition: zstd.c:28806
ZSTDLIB_STATIC_API ZSTD_DStream * ZSTD_initStaticDStream(void *workspace, size_t workspaceSize)
Definition: zstd.c:43531
ZSTDLIB_STATIC_API size_t ZSTD_generateSequences(ZSTD_CCtx *zc, ZSTD_Sequence *outSeqs, size_t outSeqsCapacity, const void *src, size_t srcSize)
Definition: zstd.c:26512
ZSTDLIB_STATIC_API ZSTD_parameters ZSTD_getParams(int compressionLevel, unsigned long long estimatedSrcSize, size_t dictSize)
Definition: zstd.c:30940
ZSTDLIB_STATIC_API size_t ZSTD_estimateCStreamSize(int maxCompressionLevel)
Definition: zstd.c:24846
ZSTD_CCtx ZSTD_CStream
Definition: zstd.c:5093
ZSTDLIB_STATIC_API ZSTD_compressionParameters ZSTD_adjustCParams(ZSTD_compressionParameters cPar, unsigned long long srcSize, size_t dictSize)
Definition: zstd.c:24604
ZSTDLIB_STATIC_API size_t ZSTD_getFrameHeader_advanced(ZSTD_FrameHeader *zfhPtr, const void *src, size_t srcSize, ZSTD_format_e format)
Definition: zstd.c:42300
ZSTDLIB_API const char * ZSTD_getErrorName(size_t result)
Definition: zstd.c:15869
ZSTDLIB_STATIC_API size_t ZSTD_DCtx_refPrefix_advanced(ZSTD_DCtx *dctx, const void *prefix, size_t prefixSize, ZSTD_dictContentType_e dictContentType)
Definition: zstd.c:43578
ZSTDLIB_STATIC_API void ZSTD_registerSequenceProducer(ZSTD_CCtx *cctx, void *sequenceProducerState, ZSTD_sequenceProducer_F sequenceProducer)
Definition: zstd.c:30946
ZSTDLIB_API unsigned ZSTD_getDictID_fromFrame(const void *src, size_t srcSize)
Definition: zstd.c:43497
ZSTDLIB_API const char * ZSTD_versionString(void)
Definition: zstd.c:15855
ZSTDLIB_STATIC_API size_t ZSTD_copyCCtx(ZSTD_CCtx *cctx, const ZSTD_CCtx *preparedCCtx, unsigned long long pledgedSrcSize)
Definition: zstd.c:25583
ZSTDLIB_STATIC_API unsigned ZSTD_isSkippableFrame(const void *buffer, size_t size)
Definition: zstd.c:42255
ZSTDLIB_STATIC_API void ZSTD_CCtxParams_registerSequenceProducer(ZSTD_CCtx_params *params, void *sequenceProducerState, ZSTD_sequenceProducer_F sequenceProducer)
Definition: zstd.c:30957
ZSTDLIB_STATIC_API ZSTD_DDict * ZSTD_createDDict_byReference(const void *dictBuffer, size_t dictSize)
Definition: zstd.c:41717
ZSTDLIB_API size_t ZSTD_CCtx_setPledgedSrcSize(ZSTD_CCtx *cctx, unsigned long long pledgedSrcSize)
Definition: zstd.c:24222
ZSTDLIB_API unsigned ZSTD_versionNumber(void)
Definition: zstd.c:15853
ZSTDLIB_STATIC_API size_t ZSTD_DCtx_setFormat(ZSTD_DCtx *dctx, ZSTD_format_e format)
Definition: zstd.c:43669
ZSTDLIB_API int ZSTD_maxCLevel(void)
Definition: zstd.c:30800
ZSTDLIB_API size_t ZSTD_DStreamOutSize(void)
Definition: zstd.c:43550
ZSTDLIB_API int ZSTD_isDeterministicBuild(void)
Definition: zstd.c:15879
ZSTDLIB_STATIC_API size_t ZSTD_initCStream_srcSize(ZSTD_CStream *zcs, int compressionLevel, unsigned long long pledgedSrcSize)
Definition: zstd.c:29054
ZSTDLIB_STATIC_API size_t ZSTD_initCStream_usingDict(ZSTD_CStream *zcs, const void *dict, size_t dictSize, int compressionLevel)
Definition: zstd.c:29045
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)
Definition: zstd.c:28464
ZSTDLIB_STATIC_API size_t ZSTD_compressBegin_advanced(ZSTD_CCtx *cctx, const void *dict, size_t dictSize, ZSTD_parameters params, unsigned long long pledgedSrcSize)
Definition: zstd.c:28297
ZSTDLIB_STATIC_API size_t ZSTD_frameHeaderSize(const void *src, size_t srcSize)
Definition: zstd.c:42288
ZSTDLIB_API unsigned long long ZSTD_getFrameContentSize(const void *src, size_t srcSize)
Definition: zstd.c:42422
ZSTDLIB_API unsigned ZSTD_getDictID_fromDict(const void *dict, size_t dictSize)
Definition: zstd.c:43477
ZSTDLIB_API size_t ZSTD_CCtx_loadDictionary(ZSTD_CCtx *cctx, const void *dict, size_t dictSize)
Definition: zstd.c:24313
ZSTDLIB_STATIC_API size_t ZSTD_CCtx_setParametersUsingCCtxParams(ZSTD_CCtx *cctx, const ZSTD_CCtx_params *params)
Definition: zstd.c:24170
ZSTDLIB_API size_t ZSTD_DCtx_refDDict(ZSTD_DCtx *dctx, const ZSTD_DDict *ddict)
Definition: zstd.c:43633
ZSTDLIB_STATIC_API size_t ZSTD_estimateCCtxSize(int maxCompressionLevel)
Definition: zstd.c:24791
ZSTDLIB_STATIC_API size_t ZSTD_CCtx_setParams(ZSTD_CCtx *cctx, ZSTD_parameters params)
Definition: zstd.c:24210
ZSTDLIB_STATIC_API size_t ZSTD_initCStream_advanced(ZSTD_CStream *zcs, const void *dict, size_t dictSize, ZSTD_parameters params, unsigned long long pledgedSrcSize)
Definition: zstd.c:29027
ZSTDLIB_API ZSTD_CDict * ZSTD_createCDict(const void *dictBuffer, size_t dictSize, int compressionLevel)
Definition: zstd.c:28702
ZSTDLIB_STATIC_API unsigned long long ZSTD_findDecompressedSize(const void *src, size_t srcSize)
Definition: zstd.c:42496
ZSTDLIB_API size_t ZSTD_CStreamOutSize(void)
Definition: zstd.c:28946
ZSTDLIB_API size_t ZSTD_DStreamInSize(void)
Definition: zstd.c:43549
ZSTDLIB_STATIC_API size_t ZSTD_CCtx_getParameter(const ZSTD_CCtx *cctx, ZSTD_cParameter param, int *value)
Definition: zstd.c:24015
ZSTDLIB_STATIC_API size_t ZSTD_compressSequencesAndLiterals(ZSTD_CCtx *cctx, void *dst, size_t dstCapacity, const ZSTD_Sequence *inSeqs, size_t nbSequences, const void *literals, size_t litSize, size_t litBufCapacity, size_t decompressedSize)
Definition: zstd.c:30577
ZSTDLIB_STATIC_API size_t ZSTD_compress_advanced(ZSTD_CCtx *cctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, const void *dict, size_t dictSize, ZSTD_parameters params)
Definition: zstd.c:28433
ZSTDLIB_API unsigned ZSTD_isError(size_t result)
Definition: zstd.c:15865
ZSTD_DCtx ZSTD_DStream
Definition: zstd.c:5225
ZSTDLIB_API size_t ZSTD_findFrameCompressedSize(const void *src, size_t srcSize)
Definition: zstd.c:42662
ZSTDLIB_STATIC_API size_t ZSTD_decompressionMargin(const void *src, size_t srcSize)
Definition: zstd.c:42691
ZSTDLIB_API size_t ZSTD_compress(void *dst, size_t dstCapacity, const void *src, size_t srcSize, int compressionLevel)
Definition: zstd.c:28489
ZSTDLIB_API int ZSTD_minCLevel(void)
Definition: zstd.c:30801
ZSTDLIB_STATIC_API size_t ZSTD_initDStream_usingDict(ZSTD_DStream *zds, const void *dict, size_t dictSize)
Definition: zstd.c:43594
ZSTDLIB_STATIC_API unsigned ZSTD_isFrame(const void *buffer, size_t size)
Definition: zstd.c:42238
ZSTDLIB_STATIC_API size_t ZSTD_decompressStream_simpleArgs(ZSTD_DCtx *dctx, void *dst, size_t dstCapacity, size_t *dstPos, const void *src, size_t srcSize, size_t *srcPos)
Definition: zstd.c:44245
ZSTDLIB_API size_t ZSTD_decompress(void *dst, size_t dstCapacity, const void *src, size_t compressedSize)
Definition: zstd.c:43056
ZSTDLIB_STATIC_API size_t ZSTD_insertBlock(ZSTD_DCtx *dctx, const void *blockStart, size_t blockSize)
Definition: zstd.c:42740
ZSTDLIB_STATIC_API size_t ZSTD_CCtxParams_getParameter(const ZSTD_CCtx_params *params, ZSTD_cParameter param, int *value)
Definition: zstd.c:24020
ZSTDLIB_API size_t ZSTD_decompressDCtx(ZSTD_DCtx *dctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize)
Definition: zstd.c:43050
ZSTDLIB_STATIC_API unsigned long long ZSTD_decompressBound(const void *src, size_t srcSize)
Definition: zstd.c:42673
void *(* ZSTD_allocFunction)(void *opaque, size_t size)
Definition: zstd.c:6181
ZSTDLIB_STATIC_API size_t ZSTD_CCtxParams_reset(ZSTD_CCtx_params *params)
Definition: zstd.c:23345
ZSTDLIB_STATIC_API ZSTD_compressionParameters ZSTD_getCParams(int compressionLevel, unsigned long long estimatedSrcSize, size_t dictSize)
Definition: zstd.c:30914
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)
Definition: zstd.c:43509
ZSTDLIB_STATIC_API size_t ZSTD_DCtx_setMaxWindowSize(ZSTD_DCtx *dctx, size_t maxWindowSize)
Definition: zstd.c:43657
ZSTDLIB_STATIC_API size_t ZSTD_CCtx_loadDictionary_advanced(ZSTD_CCtx *cctx, const void *dict, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictContentType_e dictContentType)
Definition: zstd.c:24275
ZSTDLIB_STATIC_API size_t ZSTD_CCtx_refPrefix_advanced(ZSTD_CCtx *cctx, const void *prefix, size_t prefixSize, ZSTD_dictContentType_e dictContentType)
Definition: zstd.c:24343
ZSTDLIB_STATIC_API size_t ZSTD_decompressContinue(ZSTD_DCtx *dctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize)
Definition: zstd.c:43128
ZSTDLIB_API ZSTD_ErrorCode ZSTD_getErrorCode(size_t functionResult)
Definition: zstd.c:15873
ZSTDLIB_STATIC_API size_t ZSTD_CCtx_setCParams(ZSTD_CCtx *cctx, ZSTD_compressionParameters cparams)
Definition: zstd.c:24184
ZSTDLIB_API ZSTD_bounds ZSTD_cParam_getBounds(ZSTD_cParameter cParam)
Definition: zstd.c:23411
ZSTDLIB_STATIC_API const ZSTD_CDict * ZSTD_initStaticCDict(void *workspace, size_t workspaceSize, const void *dict, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictContentType_e dictContentType, ZSTD_compressionParameters cParams)
Definition: zstd.c:28750
ZSTDLIB_STATIC_API size_t ZSTD_estimateCDictSize(size_t dictSize, int compressionLevel)
Definition: zstd.c:28528
ZSTDLIB_STATIC_API 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)
Definition: zstd.c:28891
ZSTDLIB_STATIC_API size_t ZSTD_readSkippableFrame(void *dst, size_t dstCapacity, unsigned *magicVariant, const void *src, size_t srcSize)
Definition: zstd.c:42467
ZSTD_dictLoadMethod_e
Definition: zstd.c:5692
@ ZSTD_dlm_byCopy
Definition: zstd.c:5693
@ ZSTD_dlm_byRef
Definition: zstd.c:5694
ZSTDLIB_STATIC_API size_t ZSTD_CCtxParams_init_advanced(ZSTD_CCtx_params *cctxParams, ZSTD_parameters params)
Definition: zstd.c:23387
ZSTDLIB_STATIC_API size_t ZSTD_getFrameHeader(ZSTD_FrameHeader *zfhPtr, const void *src, size_t srcSize)
Definition: zstd.c:42412