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 
147 #define ZSTD_BLOCKSIZELOG_MAX 17
148 #define ZSTD_BLOCKSIZE_MAX (1<<ZSTD_BLOCKSIZELOG_MAX)
149 
150 
151 /***************************************
152 * Simple Core API
153 ***************************************/
160 ZSTDLIB_API size_t ZSTD_compress( void* dst, size_t dstCapacity,
161  const void* src, size_t srcSize,
162  int compressionLevel);
163 
173 ZSTDLIB_API size_t ZSTD_decompress( void* dst, size_t dstCapacity,
174  const void* src, size_t compressedSize);
175 
176 
177 /*====== Decompression helper functions ======*/
178 
203 #define ZSTD_CONTENTSIZE_UNKNOWN (0ULL - 1)
204 #define ZSTD_CONTENTSIZE_ERROR (0ULL - 2)
205 ZSTDLIB_API unsigned long long ZSTD_getFrameContentSize(const void *src, size_t srcSize);
206 
213 ZSTD_DEPRECATED("Replaced by ZSTD_getFrameContentSize")
214 ZSTDLIB_API unsigned long long ZSTD_getDecompressedSize(const void* src, size_t srcSize);
215 
227 ZSTDLIB_API size_t ZSTD_findFrameCompressedSize(const void* src, size_t srcSize);
228 
229 
230 /*====== Compression helper functions ======*/
231 
248 #define ZSTD_MAX_INPUT_SIZE ((sizeof(size_t)==8) ? 0xFF00FF00FF00FF00ULL : 0xFF00FF00U)
249 #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 */
250 ZSTDLIB_API size_t ZSTD_compressBound(size_t srcSize);
253 /*====== Error helper functions ======*/
254 /* ZSTD_isError() :
255  * Most ZSTD_* functions returning a size_t value can be tested for error,
256  * using ZSTD_isError().
257  * @return 1 if error, 0 otherwise
258  */
259 ZSTDLIB_API unsigned ZSTD_isError(size_t result);
260 ZSTDLIB_API ZSTD_ErrorCode ZSTD_getErrorCode(size_t functionResult); /* convert a result into an error code, which can be compared to error enum list */
261 ZSTDLIB_API const char* ZSTD_getErrorName(size_t result);
262 ZSTDLIB_API int ZSTD_minCLevel(void);
263 ZSTDLIB_API int ZSTD_maxCLevel(void);
264 ZSTDLIB_API int ZSTD_defaultCLevel(void);
267 /***************************************
268 * Explicit context
269 ***************************************/
270 /*= Compression context
271  * When compressing many times,
272  * it is recommended to allocate a compression context just once,
273  * and reuse it for each successive compression operation.
274  * This will make the workload easier for system's memory.
275  * Note : re-using context is just a speed / resource optimization.
276  * It doesn't change the compression ratio, which remains identical.
277  * Note 2: For parallel execution in multi-threaded environments,
278  * use one different context per thread .
279  */
280 typedef struct ZSTD_CCtx_s ZSTD_CCtx;
281 ZSTDLIB_API ZSTD_CCtx* ZSTD_createCCtx(void);
282 ZSTDLIB_API size_t ZSTD_freeCCtx(ZSTD_CCtx* cctx); /* compatible with NULL pointer */
283 
292 ZSTDLIB_API size_t ZSTD_compressCCtx(ZSTD_CCtx* cctx,
293  void* dst, size_t dstCapacity,
294  const void* src, size_t srcSize,
295  int compressionLevel);
296 
297 /*= Decompression context
298  * When decompressing many times,
299  * it is recommended to allocate a context only once,
300  * and reuse it for each successive compression operation.
301  * This will make workload friendlier for system's memory.
302  * Use one context per thread for parallel execution. */
303 typedef struct ZSTD_DCtx_s ZSTD_DCtx;
304 ZSTDLIB_API ZSTD_DCtx* ZSTD_createDCtx(void);
305 ZSTDLIB_API size_t ZSTD_freeDCtx(ZSTD_DCtx* dctx); /* accept NULL pointer */
306 
312 ZSTDLIB_API size_t ZSTD_decompressDCtx(ZSTD_DCtx* dctx,
313  void* dst, size_t dstCapacity,
314  const void* src, size_t srcSize);
315 
316 
317 /*********************************************
318 * Advanced compression API (Requires v1.4.0+)
319 **********************************************/
320 
321 /* API design :
322  * Parameters are pushed one by one into an existing context,
323  * using ZSTD_CCtx_set*() functions.
324  * Pushed parameters are sticky : they are valid for next compressed frame, and any subsequent frame.
325  * "sticky" parameters are applicable to `ZSTD_compress2()` and `ZSTD_compressStream*()` !
326  * __They do not apply to one-shot variants such as ZSTD_compressCCtx()__ .
327  *
328  * It's possible to reset all parameters to "default" using ZSTD_CCtx_reset().
329  *
330  * This API supersedes all other "advanced" API entry points in the experimental section.
331  * In the future, we expect to remove API entry points from experimental which are redundant with this API.
332  */
333 
334 
335 /* Compression strategies, listed from fastest to strongest */
336 typedef enum { ZSTD_fast=1,
337  ZSTD_dfast=2,
338  ZSTD_greedy=3,
339  ZSTD_lazy=4,
340  ZSTD_lazy2=5,
341  ZSTD_btlazy2=6,
342  ZSTD_btopt=7,
343  ZSTD_btultra=8,
344  ZSTD_btultra2=9
345  /* note : new strategies _might_ be added in the future.
346  Only the order (from fast to strong) is guaranteed */
347 } ZSTD_strategy;
348 
349 typedef enum {
350 
351  /* compression parameters
352  * Note: When compressing with a ZSTD_CDict these parameters are superseded
353  * by the parameters used to construct the ZSTD_CDict.
354  * See ZSTD_CCtx_refCDict() for more info (superseded-by-cdict). */
355  ZSTD_c_compressionLevel=100, /* Set compression parameters according to pre-defined cLevel table.
356  * Note that exact compression parameters are dynamically determined,
357  * depending on both compression level and srcSize (when known).
358  * Default level is ZSTD_CLEVEL_DEFAULT==3.
359  * Special: value 0 means default, which is controlled by ZSTD_CLEVEL_DEFAULT.
360  * Note 1 : it's possible to pass a negative compression level.
361  * Note 2 : setting a level does not automatically set all other compression parameters
362  * to default. Setting this will however eventually dynamically impact the compression
363  * parameters which have not been manually set. The manually set
364  * ones will 'stick'. */
365  /* Advanced compression parameters :
366  * It's possible to pin down compression parameters to some specific values.
367  * In which case, these values are no longer dynamically selected by the compressor */
368  ZSTD_c_windowLog=101, /* Maximum allowed back-reference distance, expressed as power of 2.
369  * This will set a memory budget for streaming decompression,
370  * with larger values requiring more memory
371  * and typically compressing more.
372  * Must be clamped between ZSTD_WINDOWLOG_MIN and ZSTD_WINDOWLOG_MAX.
373  * Special: value 0 means "use default windowLog".
374  * Note: Using a windowLog greater than ZSTD_WINDOWLOG_LIMIT_DEFAULT
375  * requires explicitly allowing such size at streaming decompression stage. */
376  ZSTD_c_hashLog=102, /* Size of the initial probe table, as a power of 2.
377  * Resulting memory usage is (1 << (hashLog+2)).
378  * Must be clamped between ZSTD_HASHLOG_MIN and ZSTD_HASHLOG_MAX.
379  * Larger tables improve compression ratio of strategies <= dFast,
380  * and improve speed of strategies > dFast.
381  * Special: value 0 means "use default hashLog". */
382  ZSTD_c_chainLog=103, /* Size of the multi-probe search table, as a power of 2.
383  * Resulting memory usage is (1 << (chainLog+2)).
384  * Must be clamped between ZSTD_CHAINLOG_MIN and ZSTD_CHAINLOG_MAX.
385  * Larger tables result in better and slower compression.
386  * This parameter is useless for "fast" strategy.
387  * It's still useful when using "dfast" strategy,
388  * in which case it defines a secondary probe table.
389  * Special: value 0 means "use default chainLog". */
390  ZSTD_c_searchLog=104, /* Number of search attempts, as a power of 2.
391  * More attempts result in better and slower compression.
392  * This parameter is useless for "fast" and "dFast" strategies.
393  * Special: value 0 means "use default searchLog". */
394  ZSTD_c_minMatch=105, /* Minimum size of searched matches.
395  * Note that Zstandard can still find matches of smaller size,
396  * it just tweaks its search algorithm to look for this size and larger.
397  * Larger values increase compression and decompression speed, but decrease ratio.
398  * Must be clamped between ZSTD_MINMATCH_MIN and ZSTD_MINMATCH_MAX.
399  * Note that currently, for all strategies < btopt, effective minimum is 4.
400  * , for all strategies > fast, effective maximum is 6.
401  * Special: value 0 means "use default minMatchLength". */
402  ZSTD_c_targetLength=106, /* Impact of this field depends on strategy.
403  * For strategies btopt, btultra & btultra2:
404  * Length of Match considered "good enough" to stop search.
405  * Larger values make compression stronger, and slower.
406  * For strategy fast:
407  * Distance between match sampling.
408  * Larger values make compression faster, and weaker.
409  * Special: value 0 means "use default targetLength". */
410  ZSTD_c_strategy=107, /* See ZSTD_strategy enum definition.
411  * The higher the value of selected strategy, the more complex it is,
412  * resulting in stronger and slower compression.
413  * Special: value 0 means "use default strategy". */
414 
415  ZSTD_c_targetCBlockSize=130, /* v1.5.6+
416  * Attempts to fit compressed block size into approximately targetCBlockSize.
417  * Bound by ZSTD_TARGETCBLOCKSIZE_MIN and ZSTD_TARGETCBLOCKSIZE_MAX.
418  * Note that it's not a guarantee, just a convergence target (default:0).
419  * No target when targetCBlockSize == 0.
420  * This is helpful in low bandwidth streaming environments to improve end-to-end latency,
421  * when a client can make use of partial documents (a prominent example being Chrome).
422  * Note: this parameter is stable since v1.5.6.
423  * It was present as an experimental parameter in earlier versions,
424  * but it's not recommended using it with earlier library versions
425  * due to massive performance regressions.
426  */
427  /* LDM mode parameters */
428  ZSTD_c_enableLongDistanceMatching=160, /* Enable long distance matching.
429  * This parameter is designed to improve compression ratio
430  * for large inputs, by finding large matches at long distance.
431  * It increases memory usage and window size.
432  * Note: enabling this parameter increases default ZSTD_c_windowLog to 128 MB
433  * except when expressly set to a different value.
434  * Note: will be enabled by default if ZSTD_c_windowLog >= 128 MB and
435  * compression strategy >= ZSTD_btopt (== compression level 16+) */
436  ZSTD_c_ldmHashLog=161, /* Size of the table for long distance matching, as a power of 2.
437  * Larger values increase memory usage and compression ratio,
438  * but decrease compression speed.
439  * Must be clamped between ZSTD_HASHLOG_MIN and ZSTD_HASHLOG_MAX
440  * default: windowlog - 7.
441  * Special: value 0 means "automatically determine hashlog". */
442  ZSTD_c_ldmMinMatch=162, /* Minimum match size for long distance matcher.
443  * Larger/too small values usually decrease compression ratio.
444  * Must be clamped between ZSTD_LDM_MINMATCH_MIN and ZSTD_LDM_MINMATCH_MAX.
445  * Special: value 0 means "use default value" (default: 64). */
446  ZSTD_c_ldmBucketSizeLog=163, /* Log size of each bucket in the LDM hash table for collision resolution.
447  * Larger values improve collision resolution but decrease compression speed.
448  * The maximum value is ZSTD_LDM_BUCKETSIZELOG_MAX.
449  * Special: value 0 means "use default value" (default: 3). */
450  ZSTD_c_ldmHashRateLog=164, /* Frequency of inserting/looking up entries into the LDM hash table.
451  * Must be clamped between 0 and (ZSTD_WINDOWLOG_MAX - ZSTD_HASHLOG_MIN).
452  * Default is MAX(0, (windowLog - ldmHashLog)), optimizing hash table usage.
453  * Larger values improve compression speed.
454  * Deviating far from default value will likely result in a compression ratio decrease.
455  * Special: value 0 means "automatically determine hashRateLog". */
456 
457  /* frame parameters */
458  ZSTD_c_contentSizeFlag=200, /* Content size will be written into frame header _whenever known_ (default:1)
459  * Content size must be known at the beginning of compression.
460  * This is automatically the case when using ZSTD_compress2(),
461  * For streaming scenarios, content size must be provided with ZSTD_CCtx_setPledgedSrcSize() */
462  ZSTD_c_checksumFlag=201, /* A 32-bits checksum of content is written at end of frame (default:0) */
463  ZSTD_c_dictIDFlag=202, /* When applicable, dictionary's ID is written into frame header (default:1) */
464 
465  /* multi-threading parameters */
466  /* These parameters are only active if multi-threading is enabled (compiled with build macro ZSTD_MULTITHREAD).
467  * Otherwise, trying to set any other value than default (0) will be a no-op and return an error.
468  * In a situation where it's unknown if the linked library supports multi-threading or not,
469  * setting ZSTD_c_nbWorkers to any value >= 1 and consulting the return value provides a quick way to check this property.
470  */
471  ZSTD_c_nbWorkers=400, /* Select how many threads will be spawned to compress in parallel.
472  * When nbWorkers >= 1, triggers asynchronous mode when invoking ZSTD_compressStream*() :
473  * ZSTD_compressStream*() consumes input and flush output if possible, but immediately gives back control to caller,
474  * while compression is performed in parallel, within worker thread(s).
475  * (note : a strong exception to this rule is when first invocation of ZSTD_compressStream2() sets ZSTD_e_end :
476  * in which case, ZSTD_compressStream2() delegates to ZSTD_compress2(), which is always a blocking call).
477  * More workers improve speed, but also increase memory usage.
478  * Default value is `0`, aka "single-threaded mode" : no worker is spawned,
479  * compression is performed inside Caller's thread, and all invocations are blocking */
480  ZSTD_c_jobSize=401, /* Size of a compression job. This value is enforced only when nbWorkers >= 1.
481  * Each compression job is completed in parallel, so this value can indirectly impact the nb of active threads.
482  * 0 means default, which is dynamically determined based on compression parameters.
483  * Job size must be a minimum of overlap size, or ZSTDMT_JOBSIZE_MIN (= 512 KB), whichever is largest.
484  * The minimum size is automatically and transparently enforced. */
485  ZSTD_c_overlapLog=402, /* Control the overlap size, as a fraction of window size.
486  * The overlap size is an amount of data reloaded from previous job at the beginning of a new job.
487  * It helps preserve compression ratio, while each job is compressed in parallel.
488  * This value is enforced only when nbWorkers >= 1.
489  * Larger values increase compression ratio, but decrease speed.
490  * Possible values range from 0 to 9 :
491  * - 0 means "default" : value will be determined by the library, depending on strategy
492  * - 1 means "no overlap"
493  * - 9 means "full overlap", using a full window size.
494  * Each intermediate rank increases/decreases load size by a factor 2 :
495  * 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
496  * default value varies between 6 and 9, depending on strategy */
497 
498  /* note : additional experimental parameters are also available
499  * within the experimental section of the API.
500  * At the time of this writing, they include :
501  * ZSTD_c_rsyncable
502  * ZSTD_c_format
503  * ZSTD_c_forceMaxWindow
504  * ZSTD_c_forceAttachDict
505  * ZSTD_c_literalCompressionMode
506  * ZSTD_c_srcSizeHint
507  * ZSTD_c_enableDedicatedDictSearch
508  * ZSTD_c_stableInBuffer
509  * ZSTD_c_stableOutBuffer
510  * ZSTD_c_blockDelimiters
511  * ZSTD_c_validateSequences
512  * ZSTD_c_blockSplitterLevel
513  * ZSTD_c_splitAfterSequences
514  * ZSTD_c_useRowMatchFinder
515  * ZSTD_c_prefetchCDictTables
516  * ZSTD_c_enableSeqProducerFallback
517  * ZSTD_c_maxBlockSize
518  * Because they are not stable, it's necessary to define ZSTD_STATIC_LINKING_ONLY to access them.
519  * note : never ever use experimentalParam? names directly;
520  * also, the enums values themselves are unstable and can still change.
521  */
522  ZSTD_c_experimentalParam1=500,
523  ZSTD_c_experimentalParam2=10,
524  ZSTD_c_experimentalParam3=1000,
525  ZSTD_c_experimentalParam4=1001,
526  ZSTD_c_experimentalParam5=1002,
527  /* was ZSTD_c_experimentalParam6=1003; is now ZSTD_c_targetCBlockSize */
528  ZSTD_c_experimentalParam7=1004,
529  ZSTD_c_experimentalParam8=1005,
530  ZSTD_c_experimentalParam9=1006,
531  ZSTD_c_experimentalParam10=1007,
532  ZSTD_c_experimentalParam11=1008,
533  ZSTD_c_experimentalParam12=1009,
534  ZSTD_c_experimentalParam13=1010,
535  ZSTD_c_experimentalParam14=1011,
536  ZSTD_c_experimentalParam15=1012,
537  ZSTD_c_experimentalParam16=1013,
538  ZSTD_c_experimentalParam17=1014,
539  ZSTD_c_experimentalParam18=1015,
540  ZSTD_c_experimentalParam19=1016,
541  ZSTD_c_experimentalParam20=1017
542 } ZSTD_cParameter;
543 
544 typedef struct {
545  size_t error;
546  int lowerBound;
547  int upperBound;
548 } ZSTD_bounds;
549 
557 ZSTDLIB_API ZSTD_bounds ZSTD_cParam_getBounds(ZSTD_cParameter cParam);
558 
570 ZSTDLIB_API size_t ZSTD_CCtx_setParameter(ZSTD_CCtx* cctx, ZSTD_cParameter param, int value);
571 
587 ZSTDLIB_API size_t ZSTD_CCtx_setPledgedSrcSize(ZSTD_CCtx* cctx, unsigned long long pledgedSrcSize);
588 
589 typedef enum {
590  ZSTD_reset_session_only = 1,
591  ZSTD_reset_parameters = 2,
592  ZSTD_reset_session_and_parameters = 3
593 } ZSTD_ResetDirective;
594 
609 ZSTDLIB_API size_t ZSTD_CCtx_reset(ZSTD_CCtx* cctx, ZSTD_ResetDirective reset);
610 
623 ZSTDLIB_API size_t ZSTD_compress2( ZSTD_CCtx* cctx,
624  void* dst, size_t dstCapacity,
625  const void* src, size_t srcSize);
626 
627 
628 /***********************************************
629 * Advanced decompression API (Requires v1.4.0+)
630 ************************************************/
631 
632 /* The advanced API pushes parameters one by one into an existing DCtx context.
633  * Parameters are sticky, and remain valid for all following frames
634  * using the same DCtx context.
635  * It's possible to reset parameters to default values using ZSTD_DCtx_reset().
636  * Note : This API is compatible with existing ZSTD_decompressDCtx() and ZSTD_decompressStream().
637  * Therefore, no new decompression function is necessary.
638  */
639 
640 typedef enum {
641 
642  ZSTD_d_windowLogMax=100, /* Select a size limit (in power of 2) beyond which
643  * the streaming API will refuse to allocate memory buffer
644  * in order to protect the host from unreasonable memory requirements.
645  * This parameter is only useful in streaming mode, since no internal buffer is allocated in single-pass mode.
646  * By default, a decompression context accepts window sizes <= (1 << ZSTD_WINDOWLOG_LIMIT_DEFAULT).
647  * Special: value 0 means "use default maximum windowLog". */
648 
649  /* note : additional experimental parameters are also available
650  * within the experimental section of the API.
651  * At the time of this writing, they include :
652  * ZSTD_d_format
653  * ZSTD_d_stableOutBuffer
654  * ZSTD_d_forceIgnoreChecksum
655  * ZSTD_d_refMultipleDDicts
656  * ZSTD_d_disableHuffmanAssembly
657  * ZSTD_d_maxBlockSize
658  * Because they are not stable, it's necessary to define ZSTD_STATIC_LINKING_ONLY to access them.
659  * note : never ever use experimentalParam? names directly
660  */
661  ZSTD_d_experimentalParam1=1000,
662  ZSTD_d_experimentalParam2=1001,
663  ZSTD_d_experimentalParam3=1002,
664  ZSTD_d_experimentalParam4=1003,
665  ZSTD_d_experimentalParam5=1004,
666  ZSTD_d_experimentalParam6=1005
667 
668 } ZSTD_dParameter;
669 
677 ZSTDLIB_API ZSTD_bounds ZSTD_dParam_getBounds(ZSTD_dParameter dParam);
678 
686 ZSTDLIB_API size_t ZSTD_DCtx_setParameter(ZSTD_DCtx* dctx, ZSTD_dParameter param, int value);
687 
694 ZSTDLIB_API size_t ZSTD_DCtx_reset(ZSTD_DCtx* dctx, ZSTD_ResetDirective reset);
695 
696 
697 /****************************
698 * Streaming
699 ****************************/
700 
701 typedef struct ZSTD_inBuffer_s {
702  const void* src;
703  size_t size;
704  size_t pos;
705 } ZSTD_inBuffer;
706 
707 typedef struct ZSTD_outBuffer_s {
708  void* dst;
709  size_t size;
710  size_t pos;
712 
713 
714 
715 /*-***********************************************************************
716 * Streaming compression - HowTo
717 *
718 * A ZSTD_CStream object is required to track streaming operation.
719 * Use ZSTD_createCStream() and ZSTD_freeCStream() to create/release resources.
720 * ZSTD_CStream objects can be reused multiple times on consecutive compression operations.
721 * It is recommended to reuse ZSTD_CStream since it will play nicer with system's memory, by re-using already allocated memory.
722 *
723 * For parallel execution, use one separate ZSTD_CStream per thread.
724 *
725 * note : since v1.3.0, ZSTD_CStream and ZSTD_CCtx are the same thing.
726 *
727 * Parameters are sticky : when starting a new compression on the same context,
728 * it will reuse the same sticky parameters as previous compression session.
729 * When in doubt, it's recommended to fully initialize the context before usage.
730 * Use ZSTD_CCtx_reset() to reset the context and ZSTD_CCtx_setParameter(),
731 * ZSTD_CCtx_setPledgedSrcSize(), or ZSTD_CCtx_loadDictionary() and friends to
732 * set more specific parameters, the pledged source size, or load a dictionary.
733 *
734 * Use ZSTD_compressStream2() with ZSTD_e_continue as many times as necessary to
735 * consume input stream. The function will automatically update both `pos`
736 * fields within `input` and `output`.
737 * Note that the function may not consume the entire input, for example, because
738 * the output buffer is already full, in which case `input.pos < input.size`.
739 * The caller must check if input has been entirely consumed.
740 * If not, the caller must make some room to receive more compressed data,
741 * and then present again remaining input data.
742 * note: ZSTD_e_continue is guaranteed to make some forward progress when called,
743 * but doesn't guarantee maximal forward progress. This is especially relevant
744 * when compressing with multiple threads. The call won't block if it can
745 * consume some input, but if it can't it will wait for some, but not all,
746 * output to be flushed.
747 * @return : provides a minimum amount of data remaining to be flushed from internal buffers
748 * or an error code, which can be tested using ZSTD_isError().
749 *
750 * At any moment, it's possible to flush whatever data might remain stuck within internal buffer,
751 * using ZSTD_compressStream2() with ZSTD_e_flush. `output->pos` will be updated.
752 * Note that, if `output->size` is too small, a single invocation with ZSTD_e_flush might not be enough (return code > 0).
753 * In which case, make some room to receive more compressed data, and call again ZSTD_compressStream2() with ZSTD_e_flush.
754 * You must continue calling ZSTD_compressStream2() with ZSTD_e_flush until it returns 0, at which point you can change the
755 * operation.
756 * note: ZSTD_e_flush will flush as much output as possible, meaning when compressing with multiple threads, it will
757 * block until the flush is complete or the output buffer is full.
758 * @return : 0 if internal buffers are entirely flushed,
759 * >0 if some data still present within internal buffer (the value is minimal estimation of remaining size),
760 * or an error code, which can be tested using ZSTD_isError().
761 *
762 * Calling ZSTD_compressStream2() with ZSTD_e_end instructs to finish a frame.
763 * It will perform a flush and write frame epilogue.
764 * The epilogue is required for decoders to consider a frame completed.
765 * flush operation is the same, and follows same rules as calling ZSTD_compressStream2() with ZSTD_e_flush.
766 * You must continue calling ZSTD_compressStream2() with ZSTD_e_end until it returns 0, at which point you are free to
767 * start a new frame.
768 * note: ZSTD_e_end will flush as much output as possible, meaning when compressing with multiple threads, it will
769 * block until the flush is complete or the output buffer is full.
770 * @return : 0 if frame fully completed and fully flushed,
771 * >0 if some data still present within internal buffer (the value is minimal estimation of remaining size),
772 * or an error code, which can be tested using ZSTD_isError().
773 *
774 * *******************************************************************/
775 
776 typedef ZSTD_CCtx ZSTD_CStream;
777  /* Continue to distinguish them for compatibility with older versions <= v1.2.0 */
778 /*===== ZSTD_CStream management functions =====*/
779 ZSTDLIB_API ZSTD_CStream* ZSTD_createCStream(void);
780 ZSTDLIB_API size_t ZSTD_freeCStream(ZSTD_CStream* zcs); /* accept NULL pointer */
781 
782 /*===== Streaming compression functions =====*/
783 typedef enum {
784  ZSTD_e_continue=0, /* collect more data, encoder decides when to output compressed result, for optimal compression ratio */
785  ZSTD_e_flush=1, /* flush any data provided so far,
786  * it creates (at least) one new block, that can be decoded immediately on reception;
787  * frame will continue: any future data can still reference previously compressed data, improving compression.
788  * note : multithreaded compression will block to flush as much output as possible. */
789  ZSTD_e_end=2 /* flush any remaining data _and_ close current frame.
790  * note that frame is only closed after compressed data is fully flushed (return value == 0).
791  * After that point, any additional data starts a new frame.
792  * note : each frame is independent (does not reference any content from previous frame).
793  : note : multithreaded compression will block to flush as much output as possible. */
794 } ZSTD_EndDirective;
795 
823 ZSTDLIB_API size_t ZSTD_compressStream2( ZSTD_CCtx* cctx,
824  ZSTD_outBuffer* output,
825  ZSTD_inBuffer* input,
826  ZSTD_EndDirective endOp);
827 
828 
829 /* These buffer sizes are softly recommended.
830  * They are not required : ZSTD_compressStream*() happily accepts any buffer size, for both input and output.
831  * Respecting the recommended size just makes it a bit easier for ZSTD_compressStream*(),
832  * reducing the amount of memory shuffling and buffering, resulting in minor performance savings.
833  *
834  * However, note that these recommendations are from the perspective of a C caller program.
835  * If the streaming interface is invoked from some other language,
836  * especially managed ones such as Java or Go, through a foreign function interface such as jni or cgo,
837  * a major performance rule is to reduce crossing such interface to an absolute minimum.
838  * It's not rare that performance ends being spent more into the interface, rather than compression itself.
839  * In which cases, prefer using large buffers, as large as practical,
840  * for both input and output, to reduce the nb of roundtrips.
841  */
842 ZSTDLIB_API size_t ZSTD_CStreamInSize(void);
843 ZSTDLIB_API size_t ZSTD_CStreamOutSize(void);
846 /* *****************************************************************************
847  * This following is a legacy streaming API, available since v1.0+ .
848  * It can be replaced by ZSTD_CCtx_reset() and ZSTD_compressStream2().
849  * It is redundant, but remains fully supported.
850  ******************************************************************************/
851 
862 ZSTDLIB_API size_t ZSTD_initCStream(ZSTD_CStream* zcs, int compressionLevel);
869 ZSTDLIB_API size_t ZSTD_compressStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output, ZSTD_inBuffer* input);
871 ZSTDLIB_API size_t ZSTD_flushStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output);
873 ZSTDLIB_API size_t ZSTD_endStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output);
874 
875 
876 /*-***************************************************************************
877 * Streaming decompression - HowTo
878 *
879 * A ZSTD_DStream object is required to track streaming operations.
880 * Use ZSTD_createDStream() and ZSTD_freeDStream() to create/release resources.
881 * ZSTD_DStream objects can be re-employed multiple times.
882 *
883 * Use ZSTD_initDStream() to start a new decompression operation.
884 * @return : recommended first input size
885 * Alternatively, use advanced API to set specific properties.
886 *
887 * Use ZSTD_decompressStream() repetitively to consume your input.
888 * The function will update both `pos` fields.
889 * If `input.pos < input.size`, some input has not been consumed.
890 * It's up to the caller to present again remaining data.
891 *
892 * The function tries to flush all data decoded immediately, respecting output buffer size.
893 * If `output.pos < output.size`, decoder has flushed everything it could.
894 *
895 * However, when `output.pos == output.size`, it's more difficult to know.
896 * If @return > 0, the frame is not complete, meaning
897 * either there is still some data left to flush within internal buffers,
898 * or there is more input to read to complete the frame (or both).
899 * In which case, call ZSTD_decompressStream() again to flush whatever remains in the buffer.
900 * Note : with no additional input provided, amount of data flushed is necessarily <= ZSTD_BLOCKSIZE_MAX.
901 * @return : 0 when a frame is completely decoded and fully flushed,
902 * or an error code, which can be tested using ZSTD_isError(),
903 * or any other value > 0, which means there is still some decoding or flushing to do to complete current frame :
904 * the return value is a suggested next input size (just a hint for better latency)
905 * that will never request more than the remaining content of the compressed frame.
906 * *******************************************************************************/
907 
908 typedef ZSTD_DCtx ZSTD_DStream;
909  /* For compatibility with versions <= v1.2.0, prefer differentiating them. */
910 /*===== ZSTD_DStream management functions =====*/
911 ZSTDLIB_API ZSTD_DStream* ZSTD_createDStream(void);
912 ZSTDLIB_API size_t ZSTD_freeDStream(ZSTD_DStream* zds); /* accept NULL pointer */
913 
914 /*===== Streaming decompression functions =====*/
915 
924 ZSTDLIB_API size_t ZSTD_initDStream(ZSTD_DStream* zds);
925 
948 ZSTDLIB_API size_t ZSTD_decompressStream(ZSTD_DStream* zds, ZSTD_outBuffer* output, ZSTD_inBuffer* input);
949 
950 ZSTDLIB_API size_t ZSTD_DStreamInSize(void);
951 ZSTDLIB_API size_t ZSTD_DStreamOutSize(void);
954 /**************************
955 * Simple dictionary API
956 ***************************/
964 ZSTDLIB_API size_t ZSTD_compress_usingDict(ZSTD_CCtx* ctx,
965  void* dst, size_t dstCapacity,
966  const void* src, size_t srcSize,
967  const void* dict,size_t dictSize,
968  int compressionLevel);
969 
976 ZSTDLIB_API size_t ZSTD_decompress_usingDict(ZSTD_DCtx* dctx,
977  void* dst, size_t dstCapacity,
978  const void* src, size_t srcSize,
979  const void* dict,size_t dictSize);
980 
981 
982 /***********************************
983  * Bulk processing dictionary API
984  **********************************/
985 typedef struct ZSTD_CDict_s ZSTD_CDict;
986 
999 ZSTDLIB_API ZSTD_CDict* ZSTD_createCDict(const void* dictBuffer, size_t dictSize,
1000  int compressionLevel);
1001 
1005 ZSTDLIB_API size_t ZSTD_freeCDict(ZSTD_CDict* CDict);
1006 
1012 ZSTDLIB_API size_t ZSTD_compress_usingCDict(ZSTD_CCtx* cctx,
1013  void* dst, size_t dstCapacity,
1014  const void* src, size_t srcSize,
1015  const ZSTD_CDict* cdict);
1016 
1017 
1018 typedef struct ZSTD_DDict_s ZSTD_DDict;
1019 
1023 ZSTDLIB_API ZSTD_DDict* ZSTD_createDDict(const void* dictBuffer, size_t dictSize);
1024 
1028 ZSTDLIB_API size_t ZSTD_freeDDict(ZSTD_DDict* ddict);
1029 
1033 ZSTDLIB_API size_t ZSTD_decompress_usingDDict(ZSTD_DCtx* dctx,
1034  void* dst, size_t dstCapacity,
1035  const void* src, size_t srcSize,
1036  const ZSTD_DDict* ddict);
1037 
1038 
1039 /********************************
1040  * Dictionary helper functions
1041  *******************************/
1042 
1047 ZSTDLIB_API unsigned ZSTD_getDictID_fromDict(const void* dict, size_t dictSize);
1048 
1053 ZSTDLIB_API unsigned ZSTD_getDictID_fromCDict(const ZSTD_CDict* cdict);
1054 
1059 ZSTDLIB_API unsigned ZSTD_getDictID_fromDDict(const ZSTD_DDict* ddict);
1060 
1071 ZSTDLIB_API unsigned ZSTD_getDictID_fromFrame(const void* src, size_t srcSize);
1072 
1073 
1074 /*******************************************************************************
1075  * Advanced dictionary and prefix API (Requires v1.4.0+)
1076  *
1077  * This API allows dictionaries to be used with ZSTD_compress2(),
1078  * ZSTD_compressStream2(), and ZSTD_decompressDCtx().
1079  * Dictionaries are sticky, they remain valid when same context is reused,
1080  * they only reset when the context is reset
1081  * with ZSTD_reset_parameters or ZSTD_reset_session_and_parameters.
1082  * In contrast, Prefixes are single-use.
1083  ******************************************************************************/
1084 
1085 
1108 ZSTDLIB_API size_t ZSTD_CCtx_loadDictionary(ZSTD_CCtx* cctx, const void* dict, size_t dictSize);
1109 
1122 ZSTDLIB_API size_t ZSTD_CCtx_refCDict(ZSTD_CCtx* cctx, const ZSTD_CDict* cdict);
1123 
1143 ZSTDLIB_API size_t ZSTD_CCtx_refPrefix(ZSTD_CCtx* cctx,
1144  const void* prefix, size_t prefixSize);
1145 
1161 ZSTDLIB_API size_t ZSTD_DCtx_loadDictionary(ZSTD_DCtx* dctx, const void* dict, size_t dictSize);
1162 
1180 ZSTDLIB_API size_t ZSTD_DCtx_refDDict(ZSTD_DCtx* dctx, const ZSTD_DDict* ddict);
1181 
1198 ZSTDLIB_API size_t ZSTD_DCtx_refPrefix(ZSTD_DCtx* dctx,
1199  const void* prefix, size_t prefixSize);
1200 
1201 /* === Memory management === */
1202 
1206 ZSTDLIB_API size_t ZSTD_sizeof_CCtx(const ZSTD_CCtx* cctx);
1207 ZSTDLIB_API size_t ZSTD_sizeof_DCtx(const ZSTD_DCtx* dctx);
1208 ZSTDLIB_API size_t ZSTD_sizeof_CStream(const ZSTD_CStream* zcs);
1209 ZSTDLIB_API size_t ZSTD_sizeof_DStream(const ZSTD_DStream* zds);
1210 ZSTDLIB_API size_t ZSTD_sizeof_CDict(const ZSTD_CDict* cdict);
1211 ZSTDLIB_API size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict);
1212 
1213 #if defined (__cplusplus)
1214 }
1215 #endif
1216 
1217 #endif /* ZSTD_H_235446 */
1218 
1219 
1220 /* **************************************************************************************
1221  * ADVANCED AND EXPERIMENTAL FUNCTIONS
1222  ****************************************************************************************
1223  * The definitions in the following section are considered experimental.
1224  * They are provided for advanced scenarios.
1225  * They should never be used with a dynamic library, as prototypes may change in the future.
1226  * Use them only in association with static linking.
1227  * ***************************************************************************************/
1228 
1229 #if defined(ZSTD_STATIC_LINKING_ONLY) && !defined(ZSTD_H_ZSTD_STATIC_LINKING_ONLY)
1230 #define ZSTD_H_ZSTD_STATIC_LINKING_ONLY
1231 
1232 #if defined (__cplusplus)
1233 extern "C" {
1234 #endif
1235 
1236 /* This can be overridden externally to hide static symbols. */
1237 #ifndef ZSTDLIB_STATIC_API
1238 # if defined(ZSTD_DLL_EXPORT) && (ZSTD_DLL_EXPORT==1)
1239 # define ZSTDLIB_STATIC_API __declspec(dllexport) ZSTDLIB_VISIBLE
1240 # elif defined(ZSTD_DLL_IMPORT) && (ZSTD_DLL_IMPORT==1)
1241 # define ZSTDLIB_STATIC_API __declspec(dllimport) ZSTDLIB_VISIBLE
1242 # else
1243 # define ZSTDLIB_STATIC_API ZSTDLIB_VISIBLE
1244 # endif
1245 #endif
1246 
1247 /****************************************************************************************
1248  * experimental API (static linking only)
1249  ****************************************************************************************
1250  * The following symbols and constants
1251  * are not planned to join "stable API" status in the near future.
1252  * They can still change in future versions.
1253  * Some of them are planned to remain in the static_only section indefinitely.
1254  * Some of them might be removed in the future (especially when redundant with existing stable functions)
1255  * ***************************************************************************************/
1256 
1257 #define ZSTD_FRAMEHEADERSIZE_PREFIX(format) ((format) == ZSTD_f_zstd1 ? 5 : 1) /* minimum input size required to query frame header size */
1258 #define ZSTD_FRAMEHEADERSIZE_MIN(format) ((format) == ZSTD_f_zstd1 ? 6 : 2)
1259 #define ZSTD_FRAMEHEADERSIZE_MAX 18 /* can be useful for static allocation */
1260 #define ZSTD_SKIPPABLEHEADERSIZE 8
1261 
1262 /* compression parameter bounds */
1263 #define ZSTD_WINDOWLOG_MAX_32 30
1264 #define ZSTD_WINDOWLOG_MAX_64 31
1265 #define ZSTD_WINDOWLOG_MAX ((int)(sizeof(size_t) == 4 ? ZSTD_WINDOWLOG_MAX_32 : ZSTD_WINDOWLOG_MAX_64))
1266 #define ZSTD_WINDOWLOG_MIN 10
1267 #define ZSTD_HASHLOG_MAX ((ZSTD_WINDOWLOG_MAX < 30) ? ZSTD_WINDOWLOG_MAX : 30)
1268 #define ZSTD_HASHLOG_MIN 6
1269 #define ZSTD_CHAINLOG_MAX_32 29
1270 #define ZSTD_CHAINLOG_MAX_64 30
1271 #define ZSTD_CHAINLOG_MAX ((int)(sizeof(size_t) == 4 ? ZSTD_CHAINLOG_MAX_32 : ZSTD_CHAINLOG_MAX_64))
1272 #define ZSTD_CHAINLOG_MIN ZSTD_HASHLOG_MIN
1273 #define ZSTD_SEARCHLOG_MAX (ZSTD_WINDOWLOG_MAX-1)
1274 #define ZSTD_SEARCHLOG_MIN 1
1275 #define ZSTD_MINMATCH_MAX 7 /* only for ZSTD_fast, other strategies are limited to 6 */
1276 #define ZSTD_MINMATCH_MIN 3 /* only for ZSTD_btopt+, faster strategies are limited to 4 */
1277 #define ZSTD_TARGETLENGTH_MAX ZSTD_BLOCKSIZE_MAX
1278 #define ZSTD_TARGETLENGTH_MIN 0 /* note : comparing this constant to an unsigned results in a tautological test */
1279 #define ZSTD_STRATEGY_MIN ZSTD_fast
1280 #define ZSTD_STRATEGY_MAX ZSTD_btultra2
1281 #define ZSTD_BLOCKSIZE_MAX_MIN (1 << 10) /* The minimum valid max blocksize. Maximum blocksizes smaller than this make compressBound() inaccurate. */
1282 
1283 
1284 #define ZSTD_OVERLAPLOG_MIN 0
1285 #define ZSTD_OVERLAPLOG_MAX 9
1286 
1287 #define ZSTD_WINDOWLOG_LIMIT_DEFAULT 27 /* by default, the streaming decoder will refuse any frame
1288  * requiring larger than (1<<ZSTD_WINDOWLOG_LIMIT_DEFAULT) window size,
1289  * to preserve host's memory from unreasonable requirements.
1290  * This limit can be overridden using ZSTD_DCtx_setParameter(,ZSTD_d_windowLogMax,).
1291  * The limit does not apply for one-pass decoders (such as ZSTD_decompress()), since no additional memory is allocated */
1292 
1293 
1294 /* LDM parameter bounds */
1295 #define ZSTD_LDM_HASHLOG_MIN ZSTD_HASHLOG_MIN
1296 #define ZSTD_LDM_HASHLOG_MAX ZSTD_HASHLOG_MAX
1297 #define ZSTD_LDM_MINMATCH_MIN 4
1298 #define ZSTD_LDM_MINMATCH_MAX 4096
1299 #define ZSTD_LDM_BUCKETSIZELOG_MIN 1
1300 #define ZSTD_LDM_BUCKETSIZELOG_MAX 8
1301 #define ZSTD_LDM_HASHRATELOG_MIN 0
1302 #define ZSTD_LDM_HASHRATELOG_MAX (ZSTD_WINDOWLOG_MAX - ZSTD_HASHLOG_MIN)
1303 
1304 /* Advanced parameter bounds */
1305 #define ZSTD_TARGETCBLOCKSIZE_MIN 1340 /* suitable to fit into an ethernet / wifi / 4G transport frame */
1306 #define ZSTD_TARGETCBLOCKSIZE_MAX ZSTD_BLOCKSIZE_MAX
1307 #define ZSTD_SRCSIZEHINT_MIN 0
1308 #define ZSTD_SRCSIZEHINT_MAX INT_MAX
1309 
1310 
1311 /* --- Advanced types --- */
1312 
1313 typedef struct ZSTD_CCtx_params_s ZSTD_CCtx_params;
1314 
1315 typedef struct {
1316  unsigned int offset; /* The offset of the match. (NOT the same as the offset code)
1317  * If offset == 0 and matchLength == 0, this sequence represents the last
1318  * literals in the block of litLength size.
1319  */
1320 
1321  unsigned int litLength; /* Literal length of the sequence. */
1322  unsigned int matchLength; /* Match length of the sequence. */
1323 
1324  /* Note: Users of this API may provide a sequence with matchLength == litLength == offset == 0.
1325  * In this case, we will treat the sequence as a marker for a block boundary.
1326  */
1327 
1328  unsigned int rep; /* Represents which repeat offset is represented by the field 'offset'.
1329  * Ranges from [0, 3].
1330  *
1331  * Repeat offsets are essentially previous offsets from previous sequences sorted in
1332  * recency order. For more detail, see doc/zstd_compression_format.md
1333  *
1334  * If rep == 0, then 'offset' does not contain a repeat offset.
1335  * If rep > 0:
1336  * If litLength != 0:
1337  * rep == 1 --> offset == repeat_offset_1
1338  * rep == 2 --> offset == repeat_offset_2
1339  * rep == 3 --> offset == repeat_offset_3
1340  * If litLength == 0:
1341  * rep == 1 --> offset == repeat_offset_2
1342  * rep == 2 --> offset == repeat_offset_3
1343  * rep == 3 --> offset == repeat_offset_1 - 1
1344  *
1345  * Note: This field is optional. ZSTD_generateSequences() will calculate the value of
1346  * 'rep', but repeat offsets do not necessarily need to be calculated from an external
1347  * sequence provider perspective. For example, ZSTD_compressSequences() does not
1348  * use this 'rep' field at all (as of now).
1349  */
1350 } ZSTD_Sequence;
1351 
1352 typedef struct {
1353  unsigned windowLog;
1354  unsigned chainLog;
1355  unsigned hashLog;
1356  unsigned searchLog;
1357  unsigned minMatch;
1358  unsigned targetLength;
1359  ZSTD_strategy strategy;
1361 
1362 typedef struct {
1363  int contentSizeFlag;
1364  int checksumFlag;
1365  int noDictIDFlag;
1367 
1368 typedef struct {
1370  ZSTD_frameParameters fParams;
1371 } ZSTD_parameters;
1372 
1373 typedef enum {
1374  ZSTD_dct_auto = 0, /* dictionary is "full" when starting with ZSTD_MAGIC_DICTIONARY, otherwise it is "rawContent" */
1375  ZSTD_dct_rawContent = 1, /* ensures dictionary is always loaded as rawContent, even if it starts with ZSTD_MAGIC_DICTIONARY */
1376  ZSTD_dct_fullDict = 2 /* refuses to load a dictionary if it does not respect Zstandard's specification, starting with ZSTD_MAGIC_DICTIONARY */
1377 } ZSTD_dictContentType_e;
1378 
1379 typedef enum {
1380  ZSTD_dlm_byCopy = 0,
1381  ZSTD_dlm_byRef = 1
1383 
1384 typedef enum {
1385  ZSTD_f_zstd1 = 0, /* zstd frame format, specified in zstd_compression_format.md (default) */
1386  ZSTD_f_zstd1_magicless = 1 /* Variant of zstd frame format, without initial 4-bytes magic number.
1387  * Useful to save 4 bytes per generated frame.
1388  * Decoder cannot recognise automatically this format, requiring this instruction. */
1389 } ZSTD_format_e;
1390 
1391 typedef enum {
1392  /* Note: this enum controls ZSTD_d_forceIgnoreChecksum */
1393  ZSTD_d_validateChecksum = 0,
1394  ZSTD_d_ignoreChecksum = 1
1395 } ZSTD_forceIgnoreChecksum_e;
1396 
1397 typedef enum {
1398  /* Note: this enum controls ZSTD_d_refMultipleDDicts */
1399  ZSTD_rmd_refSingleDDict = 0,
1400  ZSTD_rmd_refMultipleDDicts = 1
1401 } ZSTD_refMultipleDDicts_e;
1402 
1403 typedef enum {
1404  /* Note: this enum and the behavior it controls are effectively internal
1405  * implementation details of the compressor. They are expected to continue
1406  * to evolve and should be considered only in the context of extremely
1407  * advanced performance tuning.
1408  *
1409  * Zstd currently supports the use of a CDict in three ways:
1410  *
1411  * - The contents of the CDict can be copied into the working context. This
1412  * means that the compression can search both the dictionary and input
1413  * while operating on a single set of internal tables. This makes
1414  * the compression faster per-byte of input. However, the initial copy of
1415  * the CDict's tables incurs a fixed cost at the beginning of the
1416  * compression. For small compressions (< 8 KB), that copy can dominate
1417  * the cost of the compression.
1418  *
1419  * - The CDict's tables can be used in-place. In this model, compression is
1420  * slower per input byte, because the compressor has to search two sets of
1421  * tables. However, this model incurs no start-up cost (as long as the
1422  * working context's tables can be reused). For small inputs, this can be
1423  * faster than copying the CDict's tables.
1424  *
1425  * - The CDict's tables are not used at all, and instead we use the working
1426  * context alone to reload the dictionary and use params based on the source
1427  * size. See ZSTD_compress_insertDictionary() and ZSTD_compress_usingDict().
1428  * This method is effective when the dictionary sizes are very small relative
1429  * to the input size, and the input size is fairly large to begin with.
1430  *
1431  * Zstd has a simple internal heuristic that selects which strategy to use
1432  * at the beginning of a compression. However, if experimentation shows that
1433  * Zstd is making poor choices, it is possible to override that choice with
1434  * this enum.
1435  */
1436  ZSTD_dictDefaultAttach = 0, /* Use the default heuristic. */
1437  ZSTD_dictForceAttach = 1, /* Never copy the dictionary. */
1438  ZSTD_dictForceCopy = 2, /* Always copy the dictionary. */
1439  ZSTD_dictForceLoad = 3 /* Always reload the dictionary */
1440 } ZSTD_dictAttachPref_e;
1441 
1442 typedef enum {
1443  ZSTD_lcm_auto = 0,
1446  ZSTD_lcm_huffman = 1,
1450 
1451 typedef enum {
1452  /* Note: This enum controls features which are conditionally beneficial.
1453  * Zstd can take a decision on whether or not to enable the feature (ZSTD_ps_auto),
1454  * but setting the switch to ZSTD_ps_enable or ZSTD_ps_disable force enable/disable the feature.
1455  */
1456  ZSTD_ps_auto = 0, /* Let the library automatically determine whether the feature shall be enabled */
1457  ZSTD_ps_enable = 1, /* Force-enable the feature */
1458  ZSTD_ps_disable = 2 /* Do not use the feature */
1459 } ZSTD_ParamSwitch_e;
1460 #define ZSTD_paramSwitch_e ZSTD_ParamSwitch_e /* old name */
1461 
1462 /***************************************
1463 * Frame header and size functions
1464 ***************************************/
1465 
1487 ZSTDLIB_STATIC_API unsigned long long ZSTD_findDecompressedSize(const void* src, size_t srcSize);
1488 
1502 ZSTDLIB_STATIC_API unsigned long long ZSTD_decompressBound(const void* src, size_t srcSize);
1503 
1508 ZSTDLIB_STATIC_API size_t ZSTD_frameHeaderSize(const void* src, size_t srcSize);
1509 
1510 typedef enum { ZSTD_frame, ZSTD_skippableFrame } ZSTD_FrameType_e;
1511 #define ZSTD_frameType_e ZSTD_FrameType_e /* old name */
1512 typedef struct {
1513  unsigned long long frameContentSize; /* if == ZSTD_CONTENTSIZE_UNKNOWN, it means this field is not available. 0 means "empty" */
1514  unsigned long long windowSize; /* can be very large, up to <= frameContentSize */
1515  unsigned blockSizeMax;
1516  ZSTD_FrameType_e frameType; /* if == ZSTD_skippableFrame, frameContentSize is the size of skippable content */
1517  unsigned headerSize;
1518  unsigned dictID; /* for ZSTD_skippableFrame, contains the skippable magic variant [0-15] */
1519  unsigned checksumFlag;
1520  unsigned _reserved1;
1521  unsigned _reserved2;
1523 #define ZSTD_frameHeader ZSTD_FrameHeader /* old name */
1524 
1530 ZSTDLIB_STATIC_API size_t ZSTD_getFrameHeader(ZSTD_FrameHeader* zfhPtr, const void* src, size_t srcSize);
1534 ZSTDLIB_STATIC_API size_t ZSTD_getFrameHeader_advanced(ZSTD_FrameHeader* zfhPtr, const void* src, size_t srcSize, ZSTD_format_e format);
1535 
1559 ZSTDLIB_STATIC_API size_t ZSTD_decompressionMargin(const void* src, size_t srcSize);
1560 
1574 #define ZSTD_DECOMPRESSION_MARGIN(originalSize, blockSize) ((size_t)( \
1575  ZSTD_FRAMEHEADERSIZE_MAX /* Frame header */ + \
1576  4 /* checksum */ + \
1577  ((originalSize) == 0 ? 0 : 3 * (((originalSize) + (blockSize) - 1) / blockSize)) /* 3 bytes per block */ + \
1578  (blockSize) /* One block of margin */ \
1579  ))
1580 
1581 typedef enum {
1582  ZSTD_sf_noBlockDelimiters = 0, /* ZSTD_Sequence[] has no block delimiters, just sequences */
1583  ZSTD_sf_explicitBlockDelimiters = 1 /* ZSTD_Sequence[] contains explicit block delimiters */
1584 } ZSTD_SequenceFormat_e;
1585 #define ZSTD_sequenceFormat_e ZSTD_SequenceFormat_e /* old name */
1586 
1594 ZSTDLIB_STATIC_API size_t ZSTD_sequenceBound(size_t srcSize);
1595 
1624 ZSTD_DEPRECATED("For debugging only, will be replaced by ZSTD_extractSequences()")
1625 ZSTDLIB_STATIC_API size_t
1627  ZSTD_Sequence* outSeqs, size_t outSeqsCapacity,
1628  const void* src, size_t srcSize);
1629 
1641 ZSTDLIB_STATIC_API size_t ZSTD_mergeBlockDelimiters(ZSTD_Sequence* sequences, size_t seqsSize);
1642 
1679 ZSTDLIB_STATIC_API size_t
1681  void* dst, size_t dstCapacity,
1682  const ZSTD_Sequence* inSeqs, size_t inSeqsSize,
1683  const void* src, size_t srcSize);
1684 
1685 
1704 ZSTDLIB_STATIC_API size_t
1706  void* dst, size_t dstCapacity,
1707  const ZSTD_Sequence* inSeqs, size_t nbSequences,
1708  const void* literals, size_t litSize, size_t litBufCapacity,
1709  size_t decompressedSize);
1710 
1711 
1725 ZSTDLIB_STATIC_API size_t ZSTD_writeSkippableFrame(void* dst, size_t dstCapacity,
1726  const void* src, size_t srcSize,
1727  unsigned magicVariant);
1728 
1740 ZSTDLIB_STATIC_API size_t ZSTD_readSkippableFrame(void* dst, size_t dstCapacity,
1741  unsigned* magicVariant,
1742  const void* src, size_t srcSize);
1743 
1747 ZSTDLIB_STATIC_API unsigned ZSTD_isSkippableFrame(const void* buffer, size_t size);
1748 
1749 
1750 
1751 /***************************************
1752 * Memory management
1753 ***************************************/
1754 
1782 ZSTDLIB_STATIC_API size_t ZSTD_estimateCCtxSize(int maxCompressionLevel);
1783 ZSTDLIB_STATIC_API size_t ZSTD_estimateCCtxSize_usingCParams(ZSTD_compressionParameters cParams);
1784 ZSTDLIB_STATIC_API size_t ZSTD_estimateCCtxSize_usingCCtxParams(const ZSTD_CCtx_params* params);
1785 ZSTDLIB_STATIC_API size_t ZSTD_estimateDCtxSize(void);
1786 
1807 ZSTDLIB_STATIC_API size_t ZSTD_estimateCStreamSize(int maxCompressionLevel);
1808 ZSTDLIB_STATIC_API size_t ZSTD_estimateCStreamSize_usingCParams(ZSTD_compressionParameters cParams);
1809 ZSTDLIB_STATIC_API size_t ZSTD_estimateCStreamSize_usingCCtxParams(const ZSTD_CCtx_params* params);
1810 ZSTDLIB_STATIC_API size_t ZSTD_estimateDStreamSize(size_t maxWindowSize);
1811 ZSTDLIB_STATIC_API size_t ZSTD_estimateDStreamSize_fromFrame(const void* src, size_t srcSize);
1812 
1818 ZSTDLIB_STATIC_API size_t ZSTD_estimateCDictSize(size_t dictSize, int compressionLevel);
1819 ZSTDLIB_STATIC_API size_t ZSTD_estimateCDictSize_advanced(size_t dictSize, ZSTD_compressionParameters cParams, ZSTD_dictLoadMethod_e dictLoadMethod);
1820 ZSTDLIB_STATIC_API size_t ZSTD_estimateDDictSize(size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod);
1821 
1843 ZSTDLIB_STATIC_API ZSTD_CCtx* ZSTD_initStaticCCtx(void* workspace, size_t workspaceSize);
1844 ZSTDLIB_STATIC_API ZSTD_CStream* ZSTD_initStaticCStream(void* workspace, size_t workspaceSize);
1846 ZSTDLIB_STATIC_API ZSTD_DCtx* ZSTD_initStaticDCtx(void* workspace, size_t workspaceSize);
1847 ZSTDLIB_STATIC_API ZSTD_DStream* ZSTD_initStaticDStream(void* workspace, size_t workspaceSize);
1849 ZSTDLIB_STATIC_API const ZSTD_CDict* ZSTD_initStaticCDict(
1850  void* workspace, size_t workspaceSize,
1851  const void* dict, size_t dictSize,
1852  ZSTD_dictLoadMethod_e dictLoadMethod,
1853  ZSTD_dictContentType_e dictContentType,
1854  ZSTD_compressionParameters cParams);
1855 
1856 ZSTDLIB_STATIC_API const ZSTD_DDict* ZSTD_initStaticDDict(
1857  void* workspace, size_t workspaceSize,
1858  const void* dict, size_t dictSize,
1859  ZSTD_dictLoadMethod_e dictLoadMethod,
1860  ZSTD_dictContentType_e dictContentType);
1861 
1862 
1868 typedef void* (*ZSTD_allocFunction) (void* opaque, size_t size);
1869 typedef void (*ZSTD_freeFunction) (void* opaque, void* address);
1870 typedef struct { ZSTD_allocFunction customAlloc; ZSTD_freeFunction customFree; void* opaque; } ZSTD_customMem;
1871 #if defined(__clang__) && __clang_major__ >= 5
1872 #pragma clang diagnostic push
1873 #pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant"
1874 #endif
1875 static
1876 #ifdef __GNUC__
1877 __attribute__((__unused__))
1878 #endif
1879 ZSTD_customMem const ZSTD_defaultCMem = { NULL, NULL, NULL };
1880 #if defined(__clang__) && __clang_major__ >= 5
1881 #pragma clang diagnostic pop
1882 #endif
1883 
1884 ZSTDLIB_STATIC_API ZSTD_CCtx* ZSTD_createCCtx_advanced(ZSTD_customMem customMem);
1885 ZSTDLIB_STATIC_API ZSTD_CStream* ZSTD_createCStream_advanced(ZSTD_customMem customMem);
1886 ZSTDLIB_STATIC_API ZSTD_DCtx* ZSTD_createDCtx_advanced(ZSTD_customMem customMem);
1887 ZSTDLIB_STATIC_API ZSTD_DStream* ZSTD_createDStream_advanced(ZSTD_customMem customMem);
1888 
1889 ZSTDLIB_STATIC_API ZSTD_CDict* ZSTD_createCDict_advanced(const void* dict, size_t dictSize,
1890  ZSTD_dictLoadMethod_e dictLoadMethod,
1891  ZSTD_dictContentType_e dictContentType,
1893  ZSTD_customMem customMem);
1894 
1905 typedef struct POOL_ctx_s ZSTD_threadPool;
1906 ZSTDLIB_STATIC_API ZSTD_threadPool* ZSTD_createThreadPool(size_t numThreads);
1907 ZSTDLIB_STATIC_API void ZSTD_freeThreadPool (ZSTD_threadPool* pool); /* accept NULL pointer */
1908 ZSTDLIB_STATIC_API size_t ZSTD_CCtx_refThreadPool(ZSTD_CCtx* cctx, ZSTD_threadPool* pool);
1909 
1910 
1911 /*
1912  * This API is temporary and is expected to change or disappear in the future!
1913  */
1914 ZSTDLIB_STATIC_API ZSTD_CDict* ZSTD_createCDict_advanced2(
1915  const void* dict, size_t dictSize,
1916  ZSTD_dictLoadMethod_e dictLoadMethod,
1917  ZSTD_dictContentType_e dictContentType,
1918  const ZSTD_CCtx_params* cctxParams,
1919  ZSTD_customMem customMem);
1920 
1921 ZSTDLIB_STATIC_API ZSTD_DDict* ZSTD_createDDict_advanced(
1922  const void* dict, size_t dictSize,
1923  ZSTD_dictLoadMethod_e dictLoadMethod,
1924  ZSTD_dictContentType_e dictContentType,
1925  ZSTD_customMem customMem);
1926 
1927 
1928 /***************************************
1929 * Advanced compression functions
1930 ***************************************/
1931 
1938 ZSTDLIB_STATIC_API ZSTD_CDict* ZSTD_createCDict_byReference(const void* dictBuffer, size_t dictSize, int compressionLevel);
1939 
1943 ZSTDLIB_STATIC_API ZSTD_compressionParameters ZSTD_getCParams(int compressionLevel, unsigned long long estimatedSrcSize, size_t dictSize);
1944 
1948 ZSTDLIB_STATIC_API ZSTD_parameters ZSTD_getParams(int compressionLevel, unsigned long long estimatedSrcSize, size_t dictSize);
1949 
1953 ZSTDLIB_STATIC_API size_t ZSTD_checkCParams(ZSTD_compressionParameters params);
1954 
1961 ZSTDLIB_STATIC_API ZSTD_compressionParameters ZSTD_adjustCParams(ZSTD_compressionParameters cPar, unsigned long long srcSize, size_t dictSize);
1962 
1970 ZSTDLIB_STATIC_API size_t ZSTD_CCtx_setCParams(ZSTD_CCtx* cctx, ZSTD_compressionParameters cparams);
1971 
1976 ZSTDLIB_STATIC_API size_t ZSTD_CCtx_setFParams(ZSTD_CCtx* cctx, ZSTD_frameParameters fparams);
1977 
1982 ZSTDLIB_STATIC_API size_t ZSTD_CCtx_setParams(ZSTD_CCtx* cctx, ZSTD_parameters params);
1983 
1988 ZSTD_DEPRECATED("use ZSTD_compress2")
1989 ZSTDLIB_STATIC_API
1990 size_t ZSTD_compress_advanced(ZSTD_CCtx* cctx,
1991  void* dst, size_t dstCapacity,
1992  const void* src, size_t srcSize,
1993  const void* dict,size_t dictSize,
1994  ZSTD_parameters params);
1995 
2000 ZSTD_DEPRECATED("use ZSTD_compress2 with ZSTD_CCtx_loadDictionary")
2001 ZSTDLIB_STATIC_API
2003  void* dst, size_t dstCapacity,
2004  const void* src, size_t srcSize,
2005  const ZSTD_CDict* cdict,
2006  ZSTD_frameParameters fParams);
2007 
2008 
2012 ZSTDLIB_STATIC_API size_t ZSTD_CCtx_loadDictionary_byReference(ZSTD_CCtx* cctx, const void* dict, size_t dictSize);
2013 
2018 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);
2019 
2023 ZSTDLIB_STATIC_API size_t ZSTD_CCtx_refPrefix_advanced(ZSTD_CCtx* cctx, const void* prefix, size_t prefixSize, ZSTD_dictContentType_e dictContentType);
2024 
2025 /* === experimental parameters === */
2026 /* these parameters can be used with ZSTD_setParameter()
2027  * they are not guaranteed to remain supported in the future */
2028 
2029  /* Enables rsyncable mode,
2030  * which makes compressed files more rsync friendly
2031  * by adding periodic synchronization points to the compressed data.
2032  * The target average block size is ZSTD_c_jobSize / 2.
2033  * It's possible to modify the job size to increase or decrease
2034  * the granularity of the synchronization point.
2035  * Once the jobSize is smaller than the window size,
2036  * it will result in compression ratio degradation.
2037  * NOTE 1: rsyncable mode only works when multithreading is enabled.
2038  * NOTE 2: rsyncable performs poorly in combination with long range mode,
2039  * since it will decrease the effectiveness of synchronization points,
2040  * though mileage may vary.
2041  * NOTE 3: Rsyncable mode limits maximum compression speed to ~400 MB/s.
2042  * If the selected compression level is already running significantly slower,
2043  * the overall speed won't be significantly impacted.
2044  */
2045  #define ZSTD_c_rsyncable ZSTD_c_experimentalParam1
2046 
2047 /* Select a compression format.
2048  * The value must be of type ZSTD_format_e.
2049  * See ZSTD_format_e enum definition for details */
2050 #define ZSTD_c_format ZSTD_c_experimentalParam2
2051 
2052 /* Force back-reference distances to remain < windowSize,
2053  * even when referencing into Dictionary content (default:0) */
2054 #define ZSTD_c_forceMaxWindow ZSTD_c_experimentalParam3
2055 
2056 /* Controls whether the contents of a CDict
2057  * are used in place, or copied into the working context.
2058  * Accepts values from the ZSTD_dictAttachPref_e enum.
2059  * See the comments on that enum for an explanation of the feature. */
2060 #define ZSTD_c_forceAttachDict ZSTD_c_experimentalParam4
2061 
2062 /* Controlled with ZSTD_ParamSwitch_e enum.
2063  * Default is ZSTD_ps_auto.
2064  * Set to ZSTD_ps_disable to never compress literals.
2065  * Set to ZSTD_ps_enable to always compress literals. (Note: uncompressed literals
2066  * may still be emitted if huffman is not beneficial to use.)
2067  *
2068  * By default, in ZSTD_ps_auto, the library will decide at runtime whether to use
2069  * literals compression based on the compression parameters - specifically,
2070  * negative compression levels do not use literal compression.
2071  */
2072 #define ZSTD_c_literalCompressionMode ZSTD_c_experimentalParam5
2073 
2074 /* User's best guess of source size.
2075  * Hint is not valid when srcSizeHint == 0.
2076  * There is no guarantee that hint is close to actual source size,
2077  * but compression ratio may regress significantly if guess considerably underestimates */
2078 #define ZSTD_c_srcSizeHint ZSTD_c_experimentalParam7
2079 
2080 /* Controls whether the new and experimental "dedicated dictionary search
2081  * structure" can be used. This feature is still rough around the edges, be
2082  * prepared for surprising behavior!
2083  *
2084  * How to use it:
2085  *
2086  * When using a CDict, whether to use this feature or not is controlled at
2087  * CDict creation, and it must be set in a CCtxParams set passed into that
2088  * construction (via ZSTD_createCDict_advanced2()). A compression will then
2089  * use the feature or not based on how the CDict was constructed; the value of
2090  * this param, set in the CCtx, will have no effect.
2091  *
2092  * However, when a dictionary buffer is passed into a CCtx, such as via
2093  * ZSTD_CCtx_loadDictionary(), this param can be set on the CCtx to control
2094  * whether the CDict that is created internally can use the feature or not.
2095  *
2096  * What it does:
2097  *
2098  * Normally, the internal data structures of the CDict are analogous to what
2099  * would be stored in a CCtx after compressing the contents of a dictionary.
2100  * To an approximation, a compression using a dictionary can then use those
2101  * data structures to simply continue what is effectively a streaming
2102  * compression where the simulated compression of the dictionary left off.
2103  * Which is to say, the search structures in the CDict are normally the same
2104  * format as in the CCtx.
2105  *
2106  * It is possible to do better, since the CDict is not like a CCtx: the search
2107  * structures are written once during CDict creation, and then are only read
2108  * after that, while the search structures in the CCtx are both read and
2109  * written as the compression goes along. This means we can choose a search
2110  * structure for the dictionary that is read-optimized.
2111  *
2112  * This feature enables the use of that different structure.
2113  *
2114  * Note that some of the members of the ZSTD_compressionParameters struct have
2115  * different semantics and constraints in the dedicated search structure. It is
2116  * highly recommended that you simply set a compression level in the CCtxParams
2117  * you pass into the CDict creation call, and avoid messing with the cParams
2118  * directly.
2119  *
2120  * Effects:
2121  *
2122  * This will only have any effect when the selected ZSTD_strategy
2123  * implementation supports this feature. Currently, that's limited to
2124  * ZSTD_greedy, ZSTD_lazy, and ZSTD_lazy2.
2125  *
2126  * Note that this means that the CDict tables can no longer be copied into the
2127  * CCtx, so the dict attachment mode ZSTD_dictForceCopy will no longer be
2128  * usable. The dictionary can only be attached or reloaded.
2129  *
2130  * In general, you should expect compression to be faster--sometimes very much
2131  * so--and CDict creation to be slightly slower. Eventually, we will probably
2132  * make this mode the default.
2133  */
2134 #define ZSTD_c_enableDedicatedDictSearch ZSTD_c_experimentalParam8
2135 
2136 /* ZSTD_c_stableInBuffer
2137  * Experimental parameter.
2138  * Default is 0 == disabled. Set to 1 to enable.
2139  *
2140  * Tells the compressor that input data presented with ZSTD_inBuffer
2141  * will ALWAYS be the same between calls.
2142  * Technically, the @src pointer must never be changed,
2143  * and the @pos field can only be updated by zstd.
2144  * However, it's possible to increase the @size field,
2145  * allowing scenarios where more data can be appended after compressions starts.
2146  * These conditions are checked by the compressor,
2147  * and compression will fail if they are not respected.
2148  * Also, data in the ZSTD_inBuffer within the range [src, src + pos)
2149  * MUST not be modified during compression or it will result in data corruption.
2150  *
2151  * When this flag is enabled zstd won't allocate an input window buffer,
2152  * because the user guarantees it can reference the ZSTD_inBuffer until
2153  * the frame is complete. But, it will still allocate an output buffer
2154  * large enough to fit a block (see ZSTD_c_stableOutBuffer). This will also
2155  * avoid the memcpy() from the input buffer to the input window buffer.
2156  *
2157  * NOTE: So long as the ZSTD_inBuffer always points to valid memory, using
2158  * this flag is ALWAYS memory safe, and will never access out-of-bounds
2159  * memory. However, compression WILL fail if conditions are not respected.
2160  *
2161  * WARNING: The data in the ZSTD_inBuffer in the range [src, src + pos) MUST
2162  * not be modified during compression or it will result in data corruption.
2163  * This is because zstd needs to reference data in the ZSTD_inBuffer to find
2164  * matches. Normally zstd maintains its own window buffer for this purpose,
2165  * but passing this flag tells zstd to rely on user provided buffer instead.
2166  */
2167 #define ZSTD_c_stableInBuffer ZSTD_c_experimentalParam9
2168 
2169 /* ZSTD_c_stableOutBuffer
2170  * Experimental parameter.
2171  * Default is 0 == disabled. Set to 1 to enable.
2172  *
2173  * Tells he compressor that the ZSTD_outBuffer will not be resized between
2174  * calls. Specifically: (out.size - out.pos) will never grow. This gives the
2175  * compressor the freedom to say: If the compressed data doesn't fit in the
2176  * output buffer then return ZSTD_error_dstSizeTooSmall. This allows us to
2177  * always decompress directly into the output buffer, instead of decompressing
2178  * into an internal buffer and copying to the output buffer.
2179  *
2180  * When this flag is enabled zstd won't allocate an output buffer, because
2181  * it can write directly to the ZSTD_outBuffer. It will still allocate the
2182  * input window buffer (see ZSTD_c_stableInBuffer).
2183  *
2184  * Zstd will check that (out.size - out.pos) never grows and return an error
2185  * if it does. While not strictly necessary, this should prevent surprises.
2186  */
2187 #define ZSTD_c_stableOutBuffer ZSTD_c_experimentalParam10
2188 
2189 /* ZSTD_c_blockDelimiters
2190  * Default is 0 == ZSTD_sf_noBlockDelimiters.
2191  *
2192  * For use with sequence compression API: ZSTD_compressSequences().
2193  *
2194  * Designates whether or not the given array of ZSTD_Sequence contains block delimiters
2195  * and last literals, which are defined as sequences with offset == 0 and matchLength == 0.
2196  * See the definition of ZSTD_Sequence for more specifics.
2197  */
2198 #define ZSTD_c_blockDelimiters ZSTD_c_experimentalParam11
2199 
2200 /* ZSTD_c_validateSequences
2201  * Default is 0 == disabled. Set to 1 to enable sequence validation.
2202  *
2203  * For use with sequence compression API: ZSTD_compressSequences*().
2204  * Designates whether or not provided sequences are validated within ZSTD_compressSequences*()
2205  * during function execution.
2206  *
2207  * When Sequence validation is disabled (default), Sequences are compressed as-is,
2208  * so they must correct, otherwise it would result in a corruption error.
2209  *
2210  * Sequence validation adds some protection, by ensuring that all values respect boundary conditions.
2211  * If a Sequence is detected invalid (see doc/zstd_compression_format.md for
2212  * specifics regarding offset/matchlength requirements) then the function will bail out and
2213  * return an error.
2214  */
2215 #define ZSTD_c_validateSequences ZSTD_c_experimentalParam12
2216 
2217 /* ZSTD_c_blockSplitterLevel
2218  * note: this parameter only influences the first splitter stage,
2219  * which is active before producing the sequences.
2220  * ZSTD_c_splitAfterSequences controls the next splitter stage,
2221  * which is active after sequence production.
2222  * Note that both can be combined.
2223  * Allowed values are between 0 and ZSTD_BLOCKSPLITTER_LEVEL_MAX included.
2224  * 0 means "auto", which will select a value depending on current ZSTD_c_strategy.
2225  * 1 means no splitting.
2226  * Then, values from 2 to 6 are sorted in increasing cpu load order.
2227  *
2228  * Note that currently the first block is never split,
2229  * to ensure expansion guarantees in presence of incompressible data.
2230  */
2231 #define ZSTD_BLOCKSPLITTER_LEVEL_MAX 6
2232 #define ZSTD_c_blockSplitterLevel ZSTD_c_experimentalParam20
2233 
2234 /* ZSTD_c_splitAfterSequences
2235  * This is a stronger splitter algorithm,
2236  * based on actual sequences previously produced by the selected parser.
2237  * It's also slower, and as a consequence, mostly used for high compression levels.
2238  * While the post-splitter does overlap with the pre-splitter,
2239  * both can nonetheless be combined,
2240  * notably with ZSTD_c_blockSplitterLevel at ZSTD_BLOCKSPLITTER_LEVEL_MAX,
2241  * resulting in higher compression ratio than just one of them.
2242  *
2243  * Default is ZSTD_ps_auto.
2244  * Set to ZSTD_ps_disable to never use block splitter.
2245  * Set to ZSTD_ps_enable to always use block splitter.
2246  *
2247  * By default, in ZSTD_ps_auto, the library will decide at runtime whether to use
2248  * block splitting based on the compression parameters.
2249  */
2250 #define ZSTD_c_splitAfterSequences ZSTD_c_experimentalParam13
2251 
2252 /* ZSTD_c_useRowMatchFinder
2253  * Controlled with ZSTD_ParamSwitch_e enum.
2254  * Default is ZSTD_ps_auto.
2255  * Set to ZSTD_ps_disable to never use row-based matchfinder.
2256  * Set to ZSTD_ps_enable to force usage of row-based matchfinder.
2257  *
2258  * By default, in ZSTD_ps_auto, the library will decide at runtime whether to use
2259  * the row-based matchfinder based on support for SIMD instructions and the window log.
2260  * Note that this only pertains to compression strategies: greedy, lazy, and lazy2
2261  */
2262 #define ZSTD_c_useRowMatchFinder ZSTD_c_experimentalParam14
2263 
2264 /* ZSTD_c_deterministicRefPrefix
2265  * Default is 0 == disabled. Set to 1 to enable.
2266  *
2267  * Zstd produces different results for prefix compression when the prefix is
2268  * directly adjacent to the data about to be compressed vs. when it isn't.
2269  * This is because zstd detects that the two buffers are contiguous and it can
2270  * use a more efficient match finding algorithm. However, this produces different
2271  * results than when the two buffers are non-contiguous. This flag forces zstd
2272  * to always load the prefix in non-contiguous mode, even if it happens to be
2273  * adjacent to the data, to guarantee determinism.
2274  *
2275  * If you really care about determinism when using a dictionary or prefix,
2276  * like when doing delta compression, you should select this option. It comes
2277  * at a speed penalty of about ~2.5% if the dictionary and data happened to be
2278  * contiguous, and is free if they weren't contiguous. We don't expect that
2279  * intentionally making the dictionary and data contiguous will be worth the
2280  * cost to memcpy() the data.
2281  */
2282 #define ZSTD_c_deterministicRefPrefix ZSTD_c_experimentalParam15
2283 
2284 /* ZSTD_c_prefetchCDictTables
2285  * Controlled with ZSTD_ParamSwitch_e enum. Default is ZSTD_ps_auto.
2286  *
2287  * In some situations, zstd uses CDict tables in-place rather than copying them
2288  * into the working context. (See docs on ZSTD_dictAttachPref_e above for details).
2289  * In such situations, compression speed is seriously impacted when CDict tables are
2290  * "cold" (outside CPU cache). This parameter instructs zstd to prefetch CDict tables
2291  * when they are used in-place.
2292  *
2293  * For sufficiently small inputs, the cost of the prefetch will outweigh the benefit.
2294  * For sufficiently large inputs, zstd will by default memcpy() CDict tables
2295  * into the working context, so there is no need to prefetch. This parameter is
2296  * targeted at a middle range of input sizes, where a prefetch is cheap enough to be
2297  * useful but memcpy() is too expensive. The exact range of input sizes where this
2298  * makes sense is best determined by careful experimentation.
2299  *
2300  * Note: for this parameter, ZSTD_ps_auto is currently equivalent to ZSTD_ps_disable,
2301  * but in the future zstd may conditionally enable this feature via an auto-detection
2302  * heuristic for cold CDicts.
2303  * Use ZSTD_ps_disable to opt out of prefetching under any circumstances.
2304  */
2305 #define ZSTD_c_prefetchCDictTables ZSTD_c_experimentalParam16
2306 
2307 /* ZSTD_c_enableSeqProducerFallback
2308  * Allowed values are 0 (disable) and 1 (enable). The default setting is 0.
2309  *
2310  * Controls whether zstd will fall back to an internal sequence producer if an
2311  * external sequence producer is registered and returns an error code. This fallback
2312  * is block-by-block: the internal sequence producer will only be called for blocks
2313  * where the external sequence producer returns an error code. Fallback parsing will
2314  * follow any other cParam settings, such as compression level, the same as in a
2315  * normal (fully-internal) compression operation.
2316  *
2317  * The user is strongly encouraged to read the full Block-Level Sequence Producer API
2318  * documentation (below) before setting this parameter. */
2319 #define ZSTD_c_enableSeqProducerFallback ZSTD_c_experimentalParam17
2320 
2321 /* ZSTD_c_maxBlockSize
2322  * Allowed values are between 1KB and ZSTD_BLOCKSIZE_MAX (128KB).
2323  * The default is ZSTD_BLOCKSIZE_MAX, and setting to 0 will set to the default.
2324  *
2325  * This parameter can be used to set an upper bound on the blocksize
2326  * that overrides the default ZSTD_BLOCKSIZE_MAX. It cannot be used to set upper
2327  * bounds greater than ZSTD_BLOCKSIZE_MAX or bounds lower than 1KB (will make
2328  * compressBound() inaccurate). Only currently meant to be used for testing.
2329  */
2330 #define ZSTD_c_maxBlockSize ZSTD_c_experimentalParam18
2331 
2332 /* ZSTD_c_repcodeResolution
2333  * This parameter only has an effect if ZSTD_c_blockDelimiters is
2334  * set to ZSTD_sf_explicitBlockDelimiters (may change in the future).
2335  *
2336  * This parameter affects how zstd parses external sequences,
2337  * provided via the ZSTD_compressSequences*() API
2338  * or from an external block-level sequence producer.
2339  *
2340  * If set to ZSTD_ps_enable, the library will check for repeated offsets within
2341  * external sequences, even if those repcodes are not explicitly indicated in
2342  * the "rep" field. Note that this is the only way to exploit repcode matches
2343  * while using compressSequences*() or an external sequence producer, since zstd
2344  * currently ignores the "rep" field of external sequences.
2345  *
2346  * If set to ZSTD_ps_disable, the library will not exploit repeated offsets in
2347  * external sequences, regardless of whether the "rep" field has been set. This
2348  * reduces sequence compression overhead by about 25% while sacrificing some
2349  * compression ratio.
2350  *
2351  * The default value is ZSTD_ps_auto, for which the library will enable/disable
2352  * based on compression level (currently: level<10 disables, level>=10 enables).
2353  */
2354 #define ZSTD_c_repcodeResolution ZSTD_c_experimentalParam19
2355 #define ZSTD_c_searchForExternalRepcodes ZSTD_c_experimentalParam19 /* older name */
2356 
2357 
2363 ZSTDLIB_STATIC_API size_t ZSTD_CCtx_getParameter(const ZSTD_CCtx* cctx, ZSTD_cParameter param, int* value);
2364 
2365 
2383 ZSTDLIB_STATIC_API ZSTD_CCtx_params* ZSTD_createCCtxParams(void);
2384 ZSTDLIB_STATIC_API size_t ZSTD_freeCCtxParams(ZSTD_CCtx_params* params); /* accept NULL pointer */
2385 
2389 ZSTDLIB_STATIC_API size_t ZSTD_CCtxParams_reset(ZSTD_CCtx_params* params);
2390 
2395 ZSTDLIB_STATIC_API size_t ZSTD_CCtxParams_init(ZSTD_CCtx_params* cctxParams, int compressionLevel);
2396 
2401 ZSTDLIB_STATIC_API size_t ZSTD_CCtxParams_init_advanced(ZSTD_CCtx_params* cctxParams, ZSTD_parameters params);
2402 
2411 ZSTDLIB_STATIC_API size_t ZSTD_CCtxParams_setParameter(ZSTD_CCtx_params* params, ZSTD_cParameter param, int value);
2412 
2418 ZSTDLIB_STATIC_API size_t ZSTD_CCtxParams_getParameter(const ZSTD_CCtx_params* params, ZSTD_cParameter param, int* value);
2419 
2427 ZSTDLIB_STATIC_API size_t ZSTD_CCtx_setParametersUsingCCtxParams(
2428  ZSTD_CCtx* cctx, const ZSTD_CCtx_params* params);
2429 
2436 ZSTDLIB_STATIC_API size_t ZSTD_compressStream2_simpleArgs (
2437  ZSTD_CCtx* cctx,
2438  void* dst, size_t dstCapacity, size_t* dstPos,
2439  const void* src, size_t srcSize, size_t* srcPos,
2440  ZSTD_EndDirective endOp);
2441 
2442 
2443 /***************************************
2444 * Advanced decompression functions
2445 ***************************************/
2446 
2452 ZSTDLIB_STATIC_API unsigned ZSTD_isFrame(const void* buffer, size_t size);
2453 
2459 ZSTDLIB_STATIC_API ZSTD_DDict* ZSTD_createDDict_byReference(const void* dictBuffer, size_t dictSize);
2460 
2466 ZSTDLIB_STATIC_API size_t ZSTD_DCtx_loadDictionary_byReference(ZSTD_DCtx* dctx, const void* dict, size_t dictSize);
2467 
2473 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);
2474 
2478 ZSTDLIB_STATIC_API size_t ZSTD_DCtx_refPrefix_advanced(ZSTD_DCtx* dctx, const void* prefix, size_t prefixSize, ZSTD_dictContentType_e dictContentType);
2479 
2487 ZSTDLIB_STATIC_API size_t ZSTD_DCtx_setMaxWindowSize(ZSTD_DCtx* dctx, size_t maxWindowSize);
2488 
2494 ZSTDLIB_STATIC_API size_t ZSTD_DCtx_getParameter(ZSTD_DCtx* dctx, ZSTD_dParameter param, int* value);
2495 
2496 /* ZSTD_d_format
2497  * experimental parameter,
2498  * allowing selection between ZSTD_format_e input compression formats
2499  */
2500 #define ZSTD_d_format ZSTD_d_experimentalParam1
2501 /* ZSTD_d_stableOutBuffer
2502  * Experimental parameter.
2503  * Default is 0 == disabled. Set to 1 to enable.
2504  *
2505  * Tells the decompressor that the ZSTD_outBuffer will ALWAYS be the same
2506  * between calls, except for the modifications that zstd makes to pos (the
2507  * caller must not modify pos). This is checked by the decompressor, and
2508  * decompression will fail if it ever changes. Therefore the ZSTD_outBuffer
2509  * MUST be large enough to fit the entire decompressed frame. This will be
2510  * checked when the frame content size is known. The data in the ZSTD_outBuffer
2511  * in the range [dst, dst + pos) MUST not be modified during decompression
2512  * or you will get data corruption.
2513  *
2514  * When this flag is enabled zstd won't allocate an output buffer, because
2515  * it can write directly to the ZSTD_outBuffer, but it will still allocate
2516  * an input buffer large enough to fit any compressed block. This will also
2517  * avoid the memcpy() from the internal output buffer to the ZSTD_outBuffer.
2518  * If you need to avoid the input buffer allocation use the buffer-less
2519  * streaming API.
2520  *
2521  * NOTE: So long as the ZSTD_outBuffer always points to valid memory, using
2522  * this flag is ALWAYS memory safe, and will never access out-of-bounds
2523  * memory. However, decompression WILL fail if you violate the preconditions.
2524  *
2525  * WARNING: The data in the ZSTD_outBuffer in the range [dst, dst + pos) MUST
2526  * not be modified during decompression or you will get data corruption. This
2527  * is because zstd needs to reference data in the ZSTD_outBuffer to regenerate
2528  * matches. Normally zstd maintains its own buffer for this purpose, but passing
2529  * this flag tells zstd to use the user provided buffer.
2530  */
2531 #define ZSTD_d_stableOutBuffer ZSTD_d_experimentalParam2
2532 
2533 /* ZSTD_d_forceIgnoreChecksum
2534  * Experimental parameter.
2535  * Default is 0 == disabled. Set to 1 to enable
2536  *
2537  * Tells the decompressor to skip checksum validation during decompression, regardless
2538  * of whether checksumming was specified during compression. This offers some
2539  * slight performance benefits, and may be useful for debugging.
2540  * Param has values of type ZSTD_forceIgnoreChecksum_e
2541  */
2542 #define ZSTD_d_forceIgnoreChecksum ZSTD_d_experimentalParam3
2543 
2544 /* ZSTD_d_refMultipleDDicts
2545  * Experimental parameter.
2546  * Default is 0 == disabled. Set to 1 to enable
2547  *
2548  * If enabled and dctx is allocated on the heap, then additional memory will be allocated
2549  * to store references to multiple ZSTD_DDict. That is, multiple calls of ZSTD_refDDict()
2550  * using a given ZSTD_DCtx, rather than overwriting the previous DDict reference, will instead
2551  * store all references. At decompression time, the appropriate dictID is selected
2552  * from the set of DDicts based on the dictID in the frame.
2553  *
2554  * Usage is simply calling ZSTD_refDDict() on multiple dict buffers.
2555  *
2556  * Param has values of byte ZSTD_refMultipleDDicts_e
2557  *
2558  * WARNING: Enabling this parameter and calling ZSTD_DCtx_refDDict(), will trigger memory
2559  * allocation for the hash table. ZSTD_freeDCtx() also frees this memory.
2560  * Memory is allocated as per ZSTD_DCtx::customMem.
2561  *
2562  * Although this function allocates memory for the table, the user is still responsible for
2563  * memory management of the underlying ZSTD_DDict* themselves.
2564  */
2565 #define ZSTD_d_refMultipleDDicts ZSTD_d_experimentalParam4
2566 
2567 /* ZSTD_d_disableHuffmanAssembly
2568  * Set to 1 to disable the Huffman assembly implementation.
2569  * The default value is 0, which allows zstd to use the Huffman assembly
2570  * implementation if available.
2571  *
2572  * This parameter can be used to disable Huffman assembly at runtime.
2573  * If you want to disable it at compile time you can define the macro
2574  * ZSTD_DISABLE_ASM.
2575  */
2576 #define ZSTD_d_disableHuffmanAssembly ZSTD_d_experimentalParam5
2577 
2578 /* ZSTD_d_maxBlockSize
2579  * Allowed values are between 1KB and ZSTD_BLOCKSIZE_MAX (128KB).
2580  * The default is ZSTD_BLOCKSIZE_MAX, and setting to 0 will set to the default.
2581  *
2582  * Forces the decompressor to reject blocks whose content size is
2583  * larger than the configured maxBlockSize. When maxBlockSize is
2584  * larger than the windowSize, the windowSize is used instead.
2585  * This saves memory on the decoder when you know all blocks are small.
2586  *
2587  * This option is typically used in conjunction with ZSTD_c_maxBlockSize.
2588  *
2589  * WARNING: This causes the decoder to reject otherwise valid frames
2590  * that have block sizes larger than the configured maxBlockSize.
2591  */
2592 #define ZSTD_d_maxBlockSize ZSTD_d_experimentalParam6
2593 
2594 
2601 ZSTD_DEPRECATED("use ZSTD_DCtx_setParameter() instead")
2602 ZSTDLIB_STATIC_API
2603 size_t ZSTD_DCtx_setFormat(ZSTD_DCtx* dctx, ZSTD_format_e format);
2604 
2611 ZSTDLIB_STATIC_API size_t ZSTD_decompressStream_simpleArgs (
2612  ZSTD_DCtx* dctx,
2613  void* dst, size_t dstCapacity, size_t* dstPos,
2614  const void* src, size_t srcSize, size_t* srcPos);
2615 
2616 
2617 /********************************************************************
2618 * Advanced streaming functions
2619 * Warning : most of these functions are now redundant with the Advanced API.
2620 * Once Advanced API reaches "stable" status,
2621 * redundant functions will be deprecated, and then at some point removed.
2622 ********************************************************************/
2623 
2624 /*===== Advanced Streaming compression functions =====*/
2625 
2638 ZSTD_DEPRECATED("use ZSTD_CCtx_reset, see zstd.h for detailed instructions")
2639 ZSTDLIB_STATIC_API
2641  int compressionLevel,
2642  unsigned long long pledgedSrcSize);
2643 
2656 ZSTD_DEPRECATED("use ZSTD_CCtx_reset, see zstd.h for detailed instructions")
2657 ZSTDLIB_STATIC_API
2659  const void* dict, size_t dictSize,
2660  int compressionLevel);
2661 
2674 ZSTD_DEPRECATED("use ZSTD_CCtx_reset, see zstd.h for detailed instructions")
2675 ZSTDLIB_STATIC_API
2677  const void* dict, size_t dictSize,
2678  ZSTD_parameters params,
2679  unsigned long long pledgedSrcSize);
2680 
2689 ZSTD_DEPRECATED("use ZSTD_CCtx_reset and ZSTD_CCtx_refCDict, see zstd.h for detailed instructions")
2690 ZSTDLIB_STATIC_API
2691 size_t ZSTD_initCStream_usingCDict(ZSTD_CStream* zcs, const ZSTD_CDict* cdict);
2692 
2705 ZSTD_DEPRECATED("use ZSTD_CCtx_reset and ZSTD_CCtx_refCDict, see zstd.h for detailed instructions")
2706 ZSTDLIB_STATIC_API
2708  const ZSTD_CDict* cdict,
2709  ZSTD_frameParameters fParams,
2710  unsigned long long pledgedSrcSize);
2711 
2730 ZSTD_DEPRECATED("use ZSTD_CCtx_reset, see zstd.h for detailed instructions")
2731 ZSTDLIB_STATIC_API
2732 size_t ZSTD_resetCStream(ZSTD_CStream* zcs, unsigned long long pledgedSrcSize);
2733 
2734 
2735 typedef struct {
2736  unsigned long long ingested; /* nb input bytes read and buffered */
2737  unsigned long long consumed; /* nb input bytes actually compressed */
2738  unsigned long long produced; /* nb of compressed bytes generated and buffered */
2739  unsigned long long flushed; /* nb of compressed bytes flushed : not provided; can be tracked from caller side */
2740  unsigned currentJobID; /* MT only : latest started job nb */
2741  unsigned nbActiveWorkers; /* MT only : nb of workers actively compressing at probe time */
2743 
2744 /* ZSTD_getFrameProgression() :
2745  * tells how much data has been ingested (read from input)
2746  * consumed (input actually compressed) and produced (output) for current frame.
2747  * Note : (ingested - consumed) is amount of input data buffered internally, not yet compressed.
2748  * Aggregates progression inside active worker threads.
2749  */
2750 ZSTDLIB_STATIC_API ZSTD_frameProgression ZSTD_getFrameProgression(const ZSTD_CCtx* cctx);
2751 
2765 ZSTDLIB_STATIC_API size_t ZSTD_toFlushNow(ZSTD_CCtx* cctx);
2766 
2767 
2768 /*===== Advanced Streaming decompression functions =====*/
2769 
2778 ZSTD_DEPRECATED("use ZSTD_DCtx_reset + ZSTD_DCtx_loadDictionary, see zstd.h for detailed instructions")
2779 ZSTDLIB_STATIC_API size_t ZSTD_initDStream_usingDict(ZSTD_DStream* zds, const void* dict, size_t dictSize);
2780 
2789 ZSTD_DEPRECATED("use ZSTD_DCtx_reset + ZSTD_DCtx_refDDict, see zstd.h for detailed instructions")
2790 ZSTDLIB_STATIC_API size_t ZSTD_initDStream_usingDDict(ZSTD_DStream* zds, const ZSTD_DDict* ddict);
2791 
2799 ZSTD_DEPRECATED("use ZSTD_DCtx_reset, see zstd.h for detailed instructions")
2800 ZSTDLIB_STATIC_API size_t ZSTD_resetDStream(ZSTD_DStream* zds);
2801 
2802 
2803 /* ********************* BLOCK-LEVEL SEQUENCE PRODUCER API *********************
2804  *
2805  * *** OVERVIEW ***
2806  * The Block-Level Sequence Producer API allows users to provide their own custom
2807  * sequence producer which libzstd invokes to process each block. The produced list
2808  * of sequences (literals and matches) is then post-processed by libzstd to produce
2809  * valid compressed blocks.
2810  *
2811  * This block-level offload API is a more granular complement of the existing
2812  * frame-level offload API compressSequences() (introduced in v1.5.1). It offers
2813  * an easier migration story for applications already integrated with libzstd: the
2814  * user application continues to invoke the same compression functions
2815  * ZSTD_compress2() or ZSTD_compressStream2() as usual, and transparently benefits
2816  * from the specific advantages of the external sequence producer. For example,
2817  * the sequence producer could be tuned to take advantage of known characteristics
2818  * of the input, to offer better speed / ratio, or could leverage hardware
2819  * acceleration not available within libzstd itself.
2820  *
2821  * See contrib/externalSequenceProducer for an example program employing the
2822  * Block-Level Sequence Producer API.
2823  *
2824  * *** USAGE ***
2825  * The user is responsible for implementing a function of type
2826  * ZSTD_sequenceProducer_F. For each block, zstd will pass the following
2827  * arguments to the user-provided function:
2828  *
2829  * - sequenceProducerState: a pointer to a user-managed state for the sequence
2830  * producer.
2831  *
2832  * - outSeqs, outSeqsCapacity: an output buffer for the sequence producer.
2833  * outSeqsCapacity is guaranteed >= ZSTD_sequenceBound(srcSize). The memory
2834  * backing outSeqs is managed by the CCtx.
2835  *
2836  * - src, srcSize: an input buffer for the sequence producer to parse.
2837  * srcSize is guaranteed to be <= ZSTD_BLOCKSIZE_MAX.
2838  *
2839  * - dict, dictSize: a history buffer, which may be empty, which the sequence
2840  * producer may reference as it parses the src buffer. Currently, zstd will
2841  * always pass dictSize == 0 into external sequence producers, but this will
2842  * change in the future.
2843  *
2844  * - compressionLevel: a signed integer representing the zstd compression level
2845  * set by the user for the current operation. The sequence producer may choose
2846  * to use this information to change its compression strategy and speed/ratio
2847  * tradeoff. Note: the compression level does not reflect zstd parameters set
2848  * through the advanced API.
2849  *
2850  * - windowSize: a size_t representing the maximum allowed offset for external
2851  * sequences. Note that sequence offsets are sometimes allowed to exceed the
2852  * windowSize if a dictionary is present, see doc/zstd_compression_format.md
2853  * for details.
2854  *
2855  * The user-provided function shall return a size_t representing the number of
2856  * sequences written to outSeqs. This return value will be treated as an error
2857  * code if it is greater than outSeqsCapacity. The return value must be non-zero
2858  * if srcSize is non-zero. The ZSTD_SEQUENCE_PRODUCER_ERROR macro is provided
2859  * for convenience, but any value greater than outSeqsCapacity will be treated as
2860  * an error code.
2861  *
2862  * If the user-provided function does not return an error code, the sequences
2863  * written to outSeqs must be a valid parse of the src buffer. Data corruption may
2864  * occur if the parse is not valid. A parse is defined to be valid if the
2865  * following conditions hold:
2866  * - The sum of matchLengths and literalLengths must equal srcSize.
2867  * - All sequences in the parse, except for the final sequence, must have
2868  * matchLength >= ZSTD_MINMATCH_MIN. The final sequence must have
2869  * matchLength >= ZSTD_MINMATCH_MIN or matchLength == 0.
2870  * - All offsets must respect the windowSize parameter as specified in
2871  * doc/zstd_compression_format.md.
2872  * - If the final sequence has matchLength == 0, it must also have offset == 0.
2873  *
2874  * zstd will only validate these conditions (and fail compression if they do not
2875  * hold) if the ZSTD_c_validateSequences cParam is enabled. Note that sequence
2876  * validation has a performance cost.
2877  *
2878  * If the user-provided function returns an error, zstd will either fall back
2879  * to an internal sequence producer or fail the compression operation. The user can
2880  * choose between the two behaviors by setting the ZSTD_c_enableSeqProducerFallback
2881  * cParam. Fallback compression will follow any other cParam settings, such as
2882  * compression level, the same as in a normal compression operation.
2883  *
2884  * The user shall instruct zstd to use a particular ZSTD_sequenceProducer_F
2885  * function by calling
2886  * ZSTD_registerSequenceProducer(cctx,
2887  * sequenceProducerState,
2888  * sequenceProducer)
2889  * This setting will persist until the next parameter reset of the CCtx.
2890  *
2891  * The sequenceProducerState must be initialized by the user before calling
2892  * ZSTD_registerSequenceProducer(). The user is responsible for destroying the
2893  * sequenceProducerState.
2894  *
2895  * *** LIMITATIONS ***
2896  * This API is compatible with all zstd compression APIs which respect advanced parameters.
2897  * However, there are three limitations:
2898  *
2899  * First, the ZSTD_c_enableLongDistanceMatching cParam is not currently supported.
2900  * COMPRESSION WILL FAIL if it is enabled and the user tries to compress with a block-level
2901  * external sequence producer.
2902  * - Note that ZSTD_c_enableLongDistanceMatching is auto-enabled by default in some
2903  * cases (see its documentation for details). Users must explicitly set
2904  * ZSTD_c_enableLongDistanceMatching to ZSTD_ps_disable in such cases if an external
2905  * sequence producer is registered.
2906  * - As of this writing, ZSTD_c_enableLongDistanceMatching is disabled by default
2907  * whenever ZSTD_c_windowLog < 128MB, but that's subject to change. Users should
2908  * check the docs on ZSTD_c_enableLongDistanceMatching whenever the Block-Level Sequence
2909  * Producer API is used in conjunction with advanced settings (like ZSTD_c_windowLog).
2910  *
2911  * Second, history buffers are not currently supported. Concretely, zstd will always pass
2912  * dictSize == 0 to the external sequence producer (for now). This has two implications:
2913  * - Dictionaries are not currently supported. Compression will *not* fail if the user
2914  * references a dictionary, but the dictionary won't have any effect.
2915  * - Stream history is not currently supported. All advanced compression APIs, including
2916  * streaming APIs, work with external sequence producers, but each block is treated as
2917  * an independent chunk without history from previous blocks.
2918  *
2919  * Third, multi-threading within a single compression is not currently supported. In other words,
2920  * COMPRESSION WILL FAIL if ZSTD_c_nbWorkers > 0 and an external sequence producer is registered.
2921  * Multi-threading across compressions is fine: simply create one CCtx per thread.
2922  *
2923  * Long-term, we plan to overcome all three limitations. There is no technical blocker to
2924  * overcoming them. It is purely a question of engineering effort.
2925  */
2926 
2927 #define ZSTD_SEQUENCE_PRODUCER_ERROR ((size_t)(-1))
2928 
2929 typedef size_t (*ZSTD_sequenceProducer_F) (
2930  void* sequenceProducerState,
2931  ZSTD_Sequence* outSeqs, size_t outSeqsCapacity,
2932  const void* src, size_t srcSize,
2933  const void* dict, size_t dictSize,
2934  int compressionLevel,
2935  size_t windowSize
2936 );
2937 
2957 ZSTDLIB_STATIC_API void
2959  ZSTD_CCtx* cctx,
2960  void* sequenceProducerState,
2961  ZSTD_sequenceProducer_F sequenceProducer
2962 );
2963 
2973 ZSTDLIB_STATIC_API void
2975  ZSTD_CCtx_params* params,
2976  void* sequenceProducerState,
2977  ZSTD_sequenceProducer_F sequenceProducer
2978 );
2979 
2980 
2981 /*********************************************************************
2982 * Buffer-less and synchronous inner streaming functions (DEPRECATED)
2983 *
2984 * This API is deprecated, and will be removed in a future version.
2985 * It allows streaming (de)compression with user allocated buffers.
2986 * However, it is hard to use, and not as well tested as the rest of
2987 * our API.
2988 *
2989 * Please use the normal streaming API instead: ZSTD_compressStream2,
2990 * and ZSTD_decompressStream.
2991 * If there is functionality that you need, but it doesn't provide,
2992 * please open an issue on our GitHub.
2993 ********************************************************************* */
2994 
3024 /*===== Buffer-less streaming compression functions =====*/
3025 ZSTD_DEPRECATED("The buffer-less API is deprecated in favor of the normal streaming API. See docs.")
3026 ZSTDLIB_STATIC_API size_t ZSTD_compressBegin(ZSTD_CCtx* cctx, int compressionLevel);
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_usingDict(ZSTD_CCtx* cctx, const void* dict, size_t dictSize, 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_usingCDict(ZSTD_CCtx* cctx, const ZSTD_CDict* cdict);
3032 ZSTD_DEPRECATED("This function will likely be removed in a future release. It is misleading and has very limited utility.")
3033 ZSTDLIB_STATIC_API
3034 size_t ZSTD_copyCCtx(ZSTD_CCtx* cctx, const ZSTD_CCtx* preparedCCtx, unsigned long long pledgedSrcSize);
3036 ZSTD_DEPRECATED("The buffer-less API is deprecated in favor of the normal streaming API. See docs.")
3037 ZSTDLIB_STATIC_API size_t ZSTD_compressContinue(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize);
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_compressEnd(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize);
3040 
3041 /* The ZSTD_compressBegin_advanced() and ZSTD_compressBegin_usingCDict_advanced() are now DEPRECATED and will generate a compiler warning */
3042 ZSTD_DEPRECATED("use advanced API to access custom parameters")
3043 ZSTDLIB_STATIC_API
3044 size_t ZSTD_compressBegin_advanced(ZSTD_CCtx* cctx, const void* dict, size_t dictSize, ZSTD_parameters params, unsigned long long pledgedSrcSize);
3045 ZSTD_DEPRECATED("use advanced API to access custom parameters")
3046 ZSTDLIB_STATIC_API
3047 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 */
3121 /*===== Buffer-less streaming decompression functions =====*/
3122 
3123 ZSTDLIB_STATIC_API size_t ZSTD_decodingBufferSize_min(unsigned long long windowSize, unsigned long long frameContentSize);
3125 ZSTDLIB_STATIC_API size_t ZSTD_decompressBegin(ZSTD_DCtx* dctx);
3126 ZSTDLIB_STATIC_API size_t ZSTD_decompressBegin_usingDict(ZSTD_DCtx* dctx, const void* dict, size_t dictSize);
3127 ZSTDLIB_STATIC_API size_t ZSTD_decompressBegin_usingDDict(ZSTD_DCtx* dctx, const ZSTD_DDict* ddict);
3128 
3129 ZSTDLIB_STATIC_API size_t ZSTD_nextSrcSizeToDecompress(ZSTD_DCtx* dctx);
3130 ZSTDLIB_STATIC_API size_t ZSTD_decompressContinue(ZSTD_DCtx* dctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize);
3131 
3132 /* misc */
3133 ZSTD_DEPRECATED("This function will likely be removed in the next minor release. It is misleading and has very limited utility.")
3134 ZSTDLIB_STATIC_API void ZSTD_copyDCtx(ZSTD_DCtx* dctx, const ZSTD_DCtx* preparedDCtx);
3135 typedef enum { ZSTDnit_frameHeader, ZSTDnit_blockHeader, ZSTDnit_block, ZSTDnit_lastBlock, ZSTDnit_checksum, ZSTDnit_skippableFrame } ZSTD_nextInputType_e;
3136 ZSTDLIB_STATIC_API ZSTD_nextInputType_e ZSTD_nextInputType(ZSTD_DCtx* dctx);
3137 
3138 
3139 
3150 ZSTDLIB_API int ZSTD_isDeterministicBuild(void);
3151 
3152 
3153 /* ========================================= */
3155 /* ========================================= */
3156 
3195 /*===== Raw zstd block functions =====*/
3196 ZSTD_DEPRECATED("The block API is deprecated in favor of the normal compression API. See docs.")
3197 ZSTDLIB_STATIC_API size_t ZSTD_getBlockSize (const ZSTD_CCtx* cctx);
3198 ZSTD_DEPRECATED("The block API is deprecated in favor of the normal compression API. See docs.")
3199 ZSTDLIB_STATIC_API size_t ZSTD_compressBlock (ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize);
3200 ZSTD_DEPRECATED("The block API is deprecated in favor of the normal compression API. See docs.")
3201 ZSTDLIB_STATIC_API size_t ZSTD_decompressBlock(ZSTD_DCtx* dctx, 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_insertBlock (ZSTD_DCtx* dctx, const void* blockStart, size_t blockSize);
3205 #if defined (__cplusplus)
3206 }
3207 #endif
3208 
3209 #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