zstd-ruby 1.5.2.2 → 1.5.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +15 -3
- data/ext/zstdruby/common.h +7 -0
- data/ext/zstdruby/libzstd/common/bits.h +175 -0
- data/ext/zstdruby/libzstd/common/bitstream.h +18 -59
- data/ext/zstdruby/libzstd/common/compiler.h +22 -3
- data/ext/zstdruby/libzstd/common/cpu.h +1 -1
- data/ext/zstdruby/libzstd/common/debug.c +1 -1
- data/ext/zstdruby/libzstd/common/debug.h +1 -1
- data/ext/zstdruby/libzstd/common/entropy_common.c +12 -40
- data/ext/zstdruby/libzstd/common/error_private.c +9 -2
- data/ext/zstdruby/libzstd/common/error_private.h +1 -1
- data/ext/zstdruby/libzstd/common/fse.h +5 -83
- data/ext/zstdruby/libzstd/common/fse_decompress.c +7 -99
- data/ext/zstdruby/libzstd/common/huf.h +65 -156
- data/ext/zstdruby/libzstd/common/mem.h +39 -46
- data/ext/zstdruby/libzstd/common/pool.c +26 -10
- data/ext/zstdruby/libzstd/common/pool.h +7 -1
- data/ext/zstdruby/libzstd/common/portability_macros.h +22 -3
- data/ext/zstdruby/libzstd/common/threading.c +68 -14
- data/ext/zstdruby/libzstd/common/threading.h +5 -10
- data/ext/zstdruby/libzstd/common/xxhash.c +2 -2
- data/ext/zstdruby/libzstd/common/xxhash.h +8 -8
- data/ext/zstdruby/libzstd/common/zstd_common.c +1 -1
- data/ext/zstdruby/libzstd/common/zstd_deps.h +1 -1
- data/ext/zstdruby/libzstd/common/zstd_internal.h +17 -113
- data/ext/zstdruby/libzstd/common/zstd_trace.h +3 -3
- data/ext/zstdruby/libzstd/compress/clevels.h +1 -1
- data/ext/zstdruby/libzstd/compress/fse_compress.c +7 -124
- data/ext/zstdruby/libzstd/compress/hist.c +1 -1
- data/ext/zstdruby/libzstd/compress/hist.h +1 -1
- data/ext/zstdruby/libzstd/compress/huf_compress.c +234 -169
- data/ext/zstdruby/libzstd/compress/zstd_compress.c +1055 -455
- data/ext/zstdruby/libzstd/compress/zstd_compress_internal.h +165 -145
- data/ext/zstdruby/libzstd/compress/zstd_compress_literals.c +115 -39
- data/ext/zstdruby/libzstd/compress/zstd_compress_literals.h +16 -8
- data/ext/zstdruby/libzstd/compress/zstd_compress_sequences.c +3 -3
- data/ext/zstdruby/libzstd/compress/zstd_compress_sequences.h +1 -1
- data/ext/zstdruby/libzstd/compress/zstd_compress_superblock.c +25 -21
- data/ext/zstdruby/libzstd/compress/zstd_compress_superblock.h +1 -1
- data/ext/zstdruby/libzstd/compress/zstd_cwksp.h +5 -3
- data/ext/zstdruby/libzstd/compress/zstd_double_fast.c +95 -33
- data/ext/zstdruby/libzstd/compress/zstd_double_fast.h +3 -2
- data/ext/zstdruby/libzstd/compress/zstd_fast.c +433 -148
- data/ext/zstdruby/libzstd/compress/zstd_fast.h +3 -2
- data/ext/zstdruby/libzstd/compress/zstd_lazy.c +306 -283
- data/ext/zstdruby/libzstd/compress/zstd_lazy.h +4 -2
- data/ext/zstdruby/libzstd/compress/zstd_ldm.c +5 -5
- data/ext/zstdruby/libzstd/compress/zstd_ldm.h +1 -1
- data/ext/zstdruby/libzstd/compress/zstd_ldm_geartab.h +1 -1
- data/ext/zstdruby/libzstd/compress/zstd_opt.c +104 -80
- data/ext/zstdruby/libzstd/compress/zstd_opt.h +1 -1
- data/ext/zstdruby/libzstd/compress/zstdmt_compress.c +12 -5
- data/ext/zstdruby/libzstd/compress/zstdmt_compress.h +1 -1
- data/ext/zstdruby/libzstd/decompress/huf_decompress.c +434 -441
- data/ext/zstdruby/libzstd/decompress/huf_decompress_amd64.S +30 -39
- data/ext/zstdruby/libzstd/decompress/zstd_ddict.c +3 -4
- data/ext/zstdruby/libzstd/decompress/zstd_ddict.h +1 -1
- data/ext/zstdruby/libzstd/decompress/zstd_decompress.c +164 -42
- data/ext/zstdruby/libzstd/decompress/zstd_decompress_block.c +186 -65
- data/ext/zstdruby/libzstd/decompress/zstd_decompress_block.h +1 -1
- data/ext/zstdruby/libzstd/decompress/zstd_decompress_internal.h +4 -2
- data/ext/zstdruby/libzstd/dictBuilder/cover.c +19 -15
- data/ext/zstdruby/libzstd/dictBuilder/cover.h +1 -1
- data/ext/zstdruby/libzstd/dictBuilder/fastcover.c +2 -2
- data/ext/zstdruby/libzstd/dictBuilder/zdict.c +9 -87
- data/ext/zstdruby/libzstd/zdict.h +53 -31
- data/ext/zstdruby/libzstd/zstd.h +489 -90
- data/ext/zstdruby/libzstd/zstd_errors.h +27 -8
- data/ext/zstdruby/main.c +4 -0
- data/ext/zstdruby/streaming_compress.c +1 -7
- data/ext/zstdruby/zstdruby.c +110 -26
- data/lib/zstd-ruby/version.rb +1 -1
- data/lib/zstd-ruby.rb +0 -1
- metadata +7 -6
data/ext/zstdruby/libzstd/zstd.h
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
3
|
* All rights reserved.
|
|
4
4
|
*
|
|
5
5
|
* This source code is licensed under both the BSD-style license (found in the
|
|
@@ -14,21 +14,31 @@ extern "C" {
|
|
|
14
14
|
#ifndef ZSTD_H_235446
|
|
15
15
|
#define ZSTD_H_235446
|
|
16
16
|
|
|
17
|
-
/* ======
|
|
17
|
+
/* ====== Dependencies ======*/
|
|
18
18
|
#include <limits.h> /* INT_MAX */
|
|
19
19
|
#include <stddef.h> /* size_t */
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
/* ===== ZSTDLIB_API : control library symbols visibility ===== */
|
|
23
23
|
#ifndef ZSTDLIB_VISIBLE
|
|
24
|
-
|
|
24
|
+
/* Backwards compatibility with old macro name */
|
|
25
|
+
# ifdef ZSTDLIB_VISIBILITY
|
|
26
|
+
# define ZSTDLIB_VISIBLE ZSTDLIB_VISIBILITY
|
|
27
|
+
# elif defined(__GNUC__) && (__GNUC__ >= 4) && !defined(__MINGW32__)
|
|
25
28
|
# define ZSTDLIB_VISIBLE __attribute__ ((visibility ("default")))
|
|
26
|
-
# define ZSTDLIB_HIDDEN __attribute__ ((visibility ("hidden")))
|
|
27
29
|
# else
|
|
28
30
|
# define ZSTDLIB_VISIBLE
|
|
31
|
+
# endif
|
|
32
|
+
#endif
|
|
33
|
+
|
|
34
|
+
#ifndef ZSTDLIB_HIDDEN
|
|
35
|
+
# if defined(__GNUC__) && (__GNUC__ >= 4) && !defined(__MINGW32__)
|
|
36
|
+
# define ZSTDLIB_HIDDEN __attribute__ ((visibility ("hidden")))
|
|
37
|
+
# else
|
|
29
38
|
# define ZSTDLIB_HIDDEN
|
|
30
39
|
# endif
|
|
31
40
|
#endif
|
|
41
|
+
|
|
32
42
|
#if defined(ZSTD_DLL_EXPORT) && (ZSTD_DLL_EXPORT==1)
|
|
33
43
|
# define ZSTDLIB_API __declspec(dllexport) ZSTDLIB_VISIBLE
|
|
34
44
|
#elif defined(ZSTD_DLL_IMPORT) && (ZSTD_DLL_IMPORT==1)
|
|
@@ -37,6 +47,28 @@ extern "C" {
|
|
|
37
47
|
# define ZSTDLIB_API ZSTDLIB_VISIBLE
|
|
38
48
|
#endif
|
|
39
49
|
|
|
50
|
+
/* Deprecation warnings :
|
|
51
|
+
* Should these warnings be a problem, it is generally possible to disable them,
|
|
52
|
+
* typically with -Wno-deprecated-declarations for gcc or _CRT_SECURE_NO_WARNINGS in Visual.
|
|
53
|
+
* Otherwise, it's also possible to define ZSTD_DISABLE_DEPRECATE_WARNINGS.
|
|
54
|
+
*/
|
|
55
|
+
#ifdef ZSTD_DISABLE_DEPRECATE_WARNINGS
|
|
56
|
+
# define ZSTD_DEPRECATED(message) /* disable deprecation warnings */
|
|
57
|
+
#else
|
|
58
|
+
# if defined (__cplusplus) && (__cplusplus >= 201402) /* C++14 or greater */
|
|
59
|
+
# define ZSTD_DEPRECATED(message) [[deprecated(message)]]
|
|
60
|
+
# elif (defined(GNUC) && (GNUC > 4 || (GNUC == 4 && GNUC_MINOR >= 5))) || defined(__clang__)
|
|
61
|
+
# define ZSTD_DEPRECATED(message) __attribute__((deprecated(message)))
|
|
62
|
+
# elif defined(__GNUC__) && (__GNUC__ >= 3)
|
|
63
|
+
# define ZSTD_DEPRECATED(message) __attribute__((deprecated))
|
|
64
|
+
# elif defined(_MSC_VER)
|
|
65
|
+
# define ZSTD_DEPRECATED(message) __declspec(deprecated(message))
|
|
66
|
+
# else
|
|
67
|
+
# pragma message("WARNING: You need to implement ZSTD_DEPRECATED for this compiler")
|
|
68
|
+
# define ZSTD_DEPRECATED(message)
|
|
69
|
+
# endif
|
|
70
|
+
#endif /* ZSTD_DISABLE_DEPRECATE_WARNINGS */
|
|
71
|
+
|
|
40
72
|
|
|
41
73
|
/*******************************************************************************
|
|
42
74
|
Introduction
|
|
@@ -74,7 +106,7 @@ extern "C" {
|
|
|
74
106
|
/*------ Version ------*/
|
|
75
107
|
#define ZSTD_VERSION_MAJOR 1
|
|
76
108
|
#define ZSTD_VERSION_MINOR 5
|
|
77
|
-
#define ZSTD_VERSION_RELEASE
|
|
109
|
+
#define ZSTD_VERSION_RELEASE 4
|
|
78
110
|
#define ZSTD_VERSION_NUMBER (ZSTD_VERSION_MAJOR *100*100 + ZSTD_VERSION_MINOR *100 + ZSTD_VERSION_RELEASE)
|
|
79
111
|
|
|
80
112
|
/*! ZSTD_versionNumber() :
|
|
@@ -165,7 +197,9 @@ ZSTDLIB_API unsigned long long ZSTD_getFrameContentSize(const void *src, size_t
|
|
|
165
197
|
* "empty", "unknown" and "error" results to the same return value (0),
|
|
166
198
|
* while ZSTD_getFrameContentSize() gives them separate return values.
|
|
167
199
|
* @return : decompressed size of `src` frame content _if known and not empty_, 0 otherwise. */
|
|
168
|
-
|
|
200
|
+
ZSTD_DEPRECATED("Replaced by ZSTD_getFrameContentSize")
|
|
201
|
+
ZSTDLIB_API
|
|
202
|
+
unsigned long long ZSTD_getDecompressedSize(const void* src, size_t srcSize);
|
|
169
203
|
|
|
170
204
|
/*! ZSTD_findFrameCompressedSize() : Requires v1.4.0+
|
|
171
205
|
* `src` should point to the start of a ZSTD frame or skippable frame.
|
|
@@ -177,8 +211,30 @@ ZSTDLIB_API size_t ZSTD_findFrameCompressedSize(const void* src, size_t srcSize)
|
|
|
177
211
|
|
|
178
212
|
|
|
179
213
|
/*====== Helper functions ======*/
|
|
180
|
-
|
|
181
|
-
|
|
214
|
+
/* ZSTD_compressBound() :
|
|
215
|
+
* maximum compressed size in worst case single-pass scenario.
|
|
216
|
+
* When invoking `ZSTD_compress()` or any other one-pass compression function,
|
|
217
|
+
* it's recommended to provide @dstCapacity >= ZSTD_compressBound(srcSize)
|
|
218
|
+
* as it eliminates one potential failure scenario,
|
|
219
|
+
* aka not enough room in dst buffer to write the compressed frame.
|
|
220
|
+
* Note : ZSTD_compressBound() itself can fail, if @srcSize > ZSTD_MAX_INPUT_SIZE .
|
|
221
|
+
* In which case, ZSTD_compressBound() will return an error code
|
|
222
|
+
* which can be tested using ZSTD_isError().
|
|
223
|
+
*
|
|
224
|
+
* ZSTD_COMPRESSBOUND() :
|
|
225
|
+
* same as ZSTD_compressBound(), but as a macro.
|
|
226
|
+
* It can be used to produce constants, which can be useful for static allocation,
|
|
227
|
+
* for example to size a static array on stack.
|
|
228
|
+
* Will produce constant value 0 if srcSize too large.
|
|
229
|
+
*/
|
|
230
|
+
#define ZSTD_MAX_INPUT_SIZE ((sizeof(size_t)==8) ? 0xFF00FF00FF00FF00LLU : 0xFF00FF00U)
|
|
231
|
+
#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 */
|
|
232
|
+
ZSTDLIB_API size_t ZSTD_compressBound(size_t srcSize); /*!< maximum compressed size in worst case single-pass scenario */
|
|
233
|
+
/* ZSTD_isError() :
|
|
234
|
+
* Most ZSTD_* functions returning a size_t value can be tested for error,
|
|
235
|
+
* using ZSTD_isError().
|
|
236
|
+
* @return 1 if error, 0 otherwise
|
|
237
|
+
*/
|
|
182
238
|
ZSTDLIB_API unsigned ZSTD_isError(size_t code); /*!< tells if a `size_t` function result is an error code */
|
|
183
239
|
ZSTDLIB_API const char* ZSTD_getErrorName(size_t code); /*!< provides readable string from an error code */
|
|
184
240
|
ZSTDLIB_API int ZSTD_minCLevel(void); /*!< minimum negative compression level allowed, requires v1.4.0+ */
|
|
@@ -421,6 +477,9 @@ typedef enum {
|
|
|
421
477
|
* ZSTD_c_validateSequences
|
|
422
478
|
* ZSTD_c_useBlockSplitter
|
|
423
479
|
* ZSTD_c_useRowMatchFinder
|
|
480
|
+
* ZSTD_c_prefetchCDictTables
|
|
481
|
+
* ZSTD_c_enableSeqProducerFallback
|
|
482
|
+
* ZSTD_c_maxBlockSize
|
|
424
483
|
* Because they are not stable, it's necessary to define ZSTD_STATIC_LINKING_ONLY to access them.
|
|
425
484
|
* note : never ever use experimentalParam? names directly;
|
|
426
485
|
* also, the enums values themselves are unstable and can still change.
|
|
@@ -439,7 +498,11 @@ typedef enum {
|
|
|
439
498
|
ZSTD_c_experimentalParam12=1009,
|
|
440
499
|
ZSTD_c_experimentalParam13=1010,
|
|
441
500
|
ZSTD_c_experimentalParam14=1011,
|
|
442
|
-
ZSTD_c_experimentalParam15=1012
|
|
501
|
+
ZSTD_c_experimentalParam15=1012,
|
|
502
|
+
ZSTD_c_experimentalParam16=1013,
|
|
503
|
+
ZSTD_c_experimentalParam17=1014,
|
|
504
|
+
ZSTD_c_experimentalParam18=1015,
|
|
505
|
+
ZSTD_c_experimentalParam19=1016
|
|
443
506
|
} ZSTD_cParameter;
|
|
444
507
|
|
|
445
508
|
typedef struct {
|
|
@@ -502,7 +565,7 @@ typedef enum {
|
|
|
502
565
|
* They will be used to compress next frame.
|
|
503
566
|
* Resetting session never fails.
|
|
504
567
|
* - The parameters : changes all parameters back to "default".
|
|
505
|
-
* This removes any reference to any dictionary
|
|
568
|
+
* This also removes any reference to any dictionary or external sequence producer.
|
|
506
569
|
* Parameters can only be changed between 2 sessions (i.e. no compression is currently ongoing)
|
|
507
570
|
* otherwise the reset fails, and function returns an error value (which can be tested using ZSTD_isError())
|
|
508
571
|
* - Both : similar to resetting the session, followed by resetting parameters.
|
|
@@ -552,13 +615,15 @@ typedef enum {
|
|
|
552
615
|
* ZSTD_d_stableOutBuffer
|
|
553
616
|
* ZSTD_d_forceIgnoreChecksum
|
|
554
617
|
* ZSTD_d_refMultipleDDicts
|
|
618
|
+
* ZSTD_d_disableHuffmanAssembly
|
|
555
619
|
* Because they are not stable, it's necessary to define ZSTD_STATIC_LINKING_ONLY to access them.
|
|
556
620
|
* note : never ever use experimentalParam? names directly
|
|
557
621
|
*/
|
|
558
622
|
ZSTD_d_experimentalParam1=1000,
|
|
559
623
|
ZSTD_d_experimentalParam2=1001,
|
|
560
624
|
ZSTD_d_experimentalParam3=1002,
|
|
561
|
-
ZSTD_d_experimentalParam4=1003
|
|
625
|
+
ZSTD_d_experimentalParam4=1003,
|
|
626
|
+
ZSTD_d_experimentalParam5=1004
|
|
562
627
|
|
|
563
628
|
} ZSTD_dParameter;
|
|
564
629
|
|
|
@@ -737,8 +802,6 @@ ZSTDLIB_API size_t ZSTD_CStreamOutSize(void); /**< recommended size for output
|
|
|
737
802
|
* This following is a legacy streaming API, available since v1.0+ .
|
|
738
803
|
* It can be replaced by ZSTD_CCtx_reset() and ZSTD_compressStream2().
|
|
739
804
|
* It is redundant, but remains fully supported.
|
|
740
|
-
* Streaming in combination with advanced parameters and dictionary compression
|
|
741
|
-
* can only be used through the new API.
|
|
742
805
|
******************************************************************************/
|
|
743
806
|
|
|
744
807
|
/*!
|
|
@@ -747,6 +810,9 @@ ZSTDLIB_API size_t ZSTD_CStreamOutSize(void); /**< recommended size for output
|
|
|
747
810
|
* ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
|
|
748
811
|
* ZSTD_CCtx_refCDict(zcs, NULL); // clear the dictionary (if any)
|
|
749
812
|
* ZSTD_CCtx_setParameter(zcs, ZSTD_c_compressionLevel, compressionLevel);
|
|
813
|
+
*
|
|
814
|
+
* Note that ZSTD_initCStream() clears any previously set dictionary. Use the new API
|
|
815
|
+
* to compress with a dictionary.
|
|
750
816
|
*/
|
|
751
817
|
ZSTDLIB_API size_t ZSTD_initCStream(ZSTD_CStream* zcs, int compressionLevel);
|
|
752
818
|
/*!
|
|
@@ -797,13 +863,31 @@ ZSTDLIB_API size_t ZSTD_freeDStream(ZSTD_DStream* zds); /* accept NULL pointer
|
|
|
797
863
|
|
|
798
864
|
/*===== Streaming decompression functions =====*/
|
|
799
865
|
|
|
800
|
-
|
|
866
|
+
/*! ZSTD_initDStream() :
|
|
867
|
+
* Initialize/reset DStream state for new decompression operation.
|
|
868
|
+
* Call before new decompression operation using same DStream.
|
|
801
869
|
*
|
|
870
|
+
* Note : This function is redundant with the advanced API and equivalent to:
|
|
802
871
|
* ZSTD_DCtx_reset(zds, ZSTD_reset_session_only);
|
|
803
872
|
* ZSTD_DCtx_refDDict(zds, NULL);
|
|
804
873
|
*/
|
|
805
874
|
ZSTDLIB_API size_t ZSTD_initDStream(ZSTD_DStream* zds);
|
|
806
875
|
|
|
876
|
+
/*! ZSTD_decompressStream() :
|
|
877
|
+
* Streaming decompression function.
|
|
878
|
+
* Call repetitively to consume full input updating it as necessary.
|
|
879
|
+
* Function will update both input and output `pos` fields exposing current state via these fields:
|
|
880
|
+
* - `input.pos < input.size`, some input remaining and caller should provide remaining input
|
|
881
|
+
* on the next call.
|
|
882
|
+
* - `output.pos < output.size`, decoder finished and flushed all remaining buffers.
|
|
883
|
+
* - `output.pos == output.size`, potentially uncflushed data present in the internal buffers,
|
|
884
|
+
* call ZSTD_decompressStream() again to flush remaining data to output.
|
|
885
|
+
* Note : with no additional input, amount of data flushed <= ZSTD_BLOCKSIZE_MAX.
|
|
886
|
+
*
|
|
887
|
+
* @return : 0 when a frame is completely decoded and fully flushed,
|
|
888
|
+
* or an error code, which can be tested using ZSTD_isError(),
|
|
889
|
+
* or any other value > 0, which means there is some decoding or flushing to do to complete current frame.
|
|
890
|
+
*/
|
|
807
891
|
ZSTDLIB_API size_t ZSTD_decompressStream(ZSTD_DStream* zds, ZSTD_outBuffer* output, ZSTD_inBuffer* input);
|
|
808
892
|
|
|
809
893
|
ZSTDLIB_API size_t ZSTD_DStreamInSize(void); /*!< recommended size for input buffer */
|
|
@@ -922,7 +1006,7 @@ ZSTDLIB_API unsigned ZSTD_getDictID_fromDDict(const ZSTD_DDict* ddict);
|
|
|
922
1006
|
* If @return == 0, the dictID could not be decoded.
|
|
923
1007
|
* This could for one of the following reasons :
|
|
924
1008
|
* - The frame does not require a dictionary to be decoded (most common case).
|
|
925
|
-
* - The frame was built with dictID intentionally removed. Whatever dictionary is necessary is a hidden information.
|
|
1009
|
+
* - The frame was built with dictID intentionally removed. Whatever dictionary is necessary is a hidden piece of information.
|
|
926
1010
|
* Note : this use case also happens when using a non-conformant dictionary.
|
|
927
1011
|
* - `srcSize` is too small, and as a result, the frame header could not be decoded (only possible if `srcSize < ZSTD_FRAMEHEADERSIZE_MAX`).
|
|
928
1012
|
* - This is not a Zstandard frame.
|
|
@@ -946,8 +1030,9 @@ ZSTDLIB_API unsigned ZSTD_getDictID_fromFrame(const void* src, size_t srcSize);
|
|
|
946
1030
|
* @result : 0, or an error code (which can be tested with ZSTD_isError()).
|
|
947
1031
|
* Special: Loading a NULL (or 0-size) dictionary invalidates previous dictionary,
|
|
948
1032
|
* meaning "return to no-dictionary mode".
|
|
949
|
-
* Note 1 : Dictionary is sticky, it will be used for all future compressed frames
|
|
950
|
-
*
|
|
1033
|
+
* Note 1 : Dictionary is sticky, it will be used for all future compressed frames,
|
|
1034
|
+
* until parameters are reset, a new dictionary is loaded, or the dictionary
|
|
1035
|
+
* is explicitly invalidated by loading a NULL dictionary.
|
|
951
1036
|
* Note 2 : Loading a dictionary involves building tables.
|
|
952
1037
|
* It's also a CPU consuming operation, with non-negligible impact on latency.
|
|
953
1038
|
* Tables are dependent on compression parameters, and for this reason,
|
|
@@ -960,7 +1045,7 @@ ZSTDLIB_API unsigned ZSTD_getDictID_fromFrame(const void* src, size_t srcSize);
|
|
|
960
1045
|
ZSTDLIB_API size_t ZSTD_CCtx_loadDictionary(ZSTD_CCtx* cctx, const void* dict, size_t dictSize);
|
|
961
1046
|
|
|
962
1047
|
/*! ZSTD_CCtx_refCDict() : Requires v1.4.0+
|
|
963
|
-
* Reference a prepared dictionary, to be used for all
|
|
1048
|
+
* Reference a prepared dictionary, to be used for all future compressed frames.
|
|
964
1049
|
* Note that compression parameters are enforced from within CDict,
|
|
965
1050
|
* and supersede any compression parameter previously set within CCtx.
|
|
966
1051
|
* The parameters ignored are labelled as "superseded-by-cdict" in the ZSTD_cParameter enum docs.
|
|
@@ -995,9 +1080,9 @@ ZSTDLIB_API size_t ZSTD_CCtx_refPrefix(ZSTD_CCtx* cctx,
|
|
|
995
1080
|
const void* prefix, size_t prefixSize);
|
|
996
1081
|
|
|
997
1082
|
/*! ZSTD_DCtx_loadDictionary() : Requires v1.4.0+
|
|
998
|
-
* Create an internal DDict from dict buffer,
|
|
999
|
-
*
|
|
1000
|
-
*
|
|
1083
|
+
* Create an internal DDict from dict buffer, to be used to decompress all future frames.
|
|
1084
|
+
* The dictionary remains valid for all future frames, until explicitly invalidated, or
|
|
1085
|
+
* a new dictionary is loaded.
|
|
1001
1086
|
* @result : 0, or an error code (which can be tested with ZSTD_isError()).
|
|
1002
1087
|
* Special : Adding a NULL (or 0-size) dictionary invalidates any previous dictionary,
|
|
1003
1088
|
* meaning "return to no-dictionary mode".
|
|
@@ -1021,9 +1106,10 @@ ZSTDLIB_API size_t ZSTD_DCtx_loadDictionary(ZSTD_DCtx* dctx, const void* dict, s
|
|
|
1021
1106
|
* The memory for the table is allocated on the first call to refDDict, and can be
|
|
1022
1107
|
* freed with ZSTD_freeDCtx().
|
|
1023
1108
|
*
|
|
1109
|
+
* If called with ZSTD_d_refMultipleDDicts disabled (the default), only one dictionary
|
|
1110
|
+
* will be managed, and referencing a dictionary effectively "discards" any previous one.
|
|
1111
|
+
*
|
|
1024
1112
|
* @result : 0, or an error code (which can be tested with ZSTD_isError()).
|
|
1025
|
-
* Note 1 : Currently, only one dictionary can be managed.
|
|
1026
|
-
* Referencing a new dictionary effectively "discards" any previous one.
|
|
1027
1113
|
* Special: referencing a NULL DDict means "return to no-dictionary mode".
|
|
1028
1114
|
* Note 2 : DDict is just referenced, its lifetime must outlive its usage from DCtx.
|
|
1029
1115
|
*/
|
|
@@ -1086,28 +1172,6 @@ ZSTDLIB_API size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict);
|
|
|
1086
1172
|
# endif
|
|
1087
1173
|
#endif
|
|
1088
1174
|
|
|
1089
|
-
/* Deprecation warnings :
|
|
1090
|
-
* Should these warnings be a problem, it is generally possible to disable them,
|
|
1091
|
-
* typically with -Wno-deprecated-declarations for gcc or _CRT_SECURE_NO_WARNINGS in Visual.
|
|
1092
|
-
* Otherwise, it's also possible to define ZSTD_DISABLE_DEPRECATE_WARNINGS.
|
|
1093
|
-
*/
|
|
1094
|
-
#ifdef ZSTD_DISABLE_DEPRECATE_WARNINGS
|
|
1095
|
-
# define ZSTD_DEPRECATED(message) ZSTDLIB_STATIC_API /* disable deprecation warnings */
|
|
1096
|
-
#else
|
|
1097
|
-
# if defined (__cplusplus) && (__cplusplus >= 201402) /* C++14 or greater */
|
|
1098
|
-
# define ZSTD_DEPRECATED(message) [[deprecated(message)]] ZSTDLIB_STATIC_API
|
|
1099
|
-
# elif (defined(GNUC) && (GNUC > 4 || (GNUC == 4 && GNUC_MINOR >= 5))) || defined(__clang__)
|
|
1100
|
-
# define ZSTD_DEPRECATED(message) ZSTDLIB_STATIC_API __attribute__((deprecated(message)))
|
|
1101
|
-
# elif defined(__GNUC__) && (__GNUC__ >= 3)
|
|
1102
|
-
# define ZSTD_DEPRECATED(message) ZSTDLIB_STATIC_API __attribute__((deprecated))
|
|
1103
|
-
# elif defined(_MSC_VER)
|
|
1104
|
-
# define ZSTD_DEPRECATED(message) ZSTDLIB_STATIC_API __declspec(deprecated(message))
|
|
1105
|
-
# else
|
|
1106
|
-
# pragma message("WARNING: You need to implement ZSTD_DEPRECATED for this compiler")
|
|
1107
|
-
# define ZSTD_DEPRECATED(message) ZSTDLIB_STATIC_API
|
|
1108
|
-
# endif
|
|
1109
|
-
#endif /* ZSTD_DISABLE_DEPRECATE_WARNINGS */
|
|
1110
|
-
|
|
1111
1175
|
/****************************************************************************************
|
|
1112
1176
|
* experimental API (static linking only)
|
|
1113
1177
|
****************************************************************************************
|
|
@@ -1142,6 +1206,7 @@ ZSTDLIB_API size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict);
|
|
|
1142
1206
|
#define ZSTD_TARGETLENGTH_MIN 0 /* note : comparing this constant to an unsigned results in a tautological test */
|
|
1143
1207
|
#define ZSTD_STRATEGY_MIN ZSTD_fast
|
|
1144
1208
|
#define ZSTD_STRATEGY_MAX ZSTD_btultra2
|
|
1209
|
+
#define ZSTD_BLOCKSIZE_MAX_MIN (1 << 10) /* The minimum valid max blocksize. Maximum blocksizes smaller than this make compressBound() inaccurate. */
|
|
1145
1210
|
|
|
1146
1211
|
|
|
1147
1212
|
#define ZSTD_OVERLAPLOG_MIN 0
|
|
@@ -1369,33 +1434,89 @@ ZSTDLIB_STATIC_API unsigned long long ZSTD_decompressBound(const void* src, size
|
|
|
1369
1434
|
* or an error code (if srcSize is too small) */
|
|
1370
1435
|
ZSTDLIB_STATIC_API size_t ZSTD_frameHeaderSize(const void* src, size_t srcSize);
|
|
1371
1436
|
|
|
1437
|
+
/*! ZSTD_decompressionMargin() :
|
|
1438
|
+
* Zstd supports in-place decompression, where the input and output buffers overlap.
|
|
1439
|
+
* In this case, the output buffer must be at least (Margin + Output_Size) bytes large,
|
|
1440
|
+
* and the input buffer must be at the end of the output buffer.
|
|
1441
|
+
*
|
|
1442
|
+
* _______________________ Output Buffer ________________________
|
|
1443
|
+
* | |
|
|
1444
|
+
* | ____ Input Buffer ____|
|
|
1445
|
+
* | | |
|
|
1446
|
+
* v v v
|
|
1447
|
+
* |---------------------------------------|-----------|----------|
|
|
1448
|
+
* ^ ^ ^
|
|
1449
|
+
* |___________________ Output_Size ___________________|_ Margin _|
|
|
1450
|
+
*
|
|
1451
|
+
* NOTE: See also ZSTD_DECOMPRESSION_MARGIN().
|
|
1452
|
+
* NOTE: This applies only to single-pass decompression through ZSTD_decompress() or
|
|
1453
|
+
* ZSTD_decompressDCtx().
|
|
1454
|
+
* NOTE: This function supports multi-frame input.
|
|
1455
|
+
*
|
|
1456
|
+
* @param src The compressed frame(s)
|
|
1457
|
+
* @param srcSize The size of the compressed frame(s)
|
|
1458
|
+
* @returns The decompression margin or an error that can be checked with ZSTD_isError().
|
|
1459
|
+
*/
|
|
1460
|
+
ZSTDLIB_STATIC_API size_t ZSTD_decompressionMargin(const void* src, size_t srcSize);
|
|
1461
|
+
|
|
1462
|
+
/*! ZSTD_DECOMPRESS_MARGIN() :
|
|
1463
|
+
* Similar to ZSTD_decompressionMargin(), but instead of computing the margin from
|
|
1464
|
+
* the compressed frame, compute it from the original size and the blockSizeLog.
|
|
1465
|
+
* See ZSTD_decompressionMargin() for details.
|
|
1466
|
+
*
|
|
1467
|
+
* WARNING: This macro does not support multi-frame input, the input must be a single
|
|
1468
|
+
* zstd frame. If you need that support use the function, or implement it yourself.
|
|
1469
|
+
*
|
|
1470
|
+
* @param originalSize The original uncompressed size of the data.
|
|
1471
|
+
* @param blockSize The block size == MIN(windowSize, ZSTD_BLOCKSIZE_MAX).
|
|
1472
|
+
* Unless you explicitly set the windowLog smaller than
|
|
1473
|
+
* ZSTD_BLOCKSIZELOG_MAX you can just use ZSTD_BLOCKSIZE_MAX.
|
|
1474
|
+
*/
|
|
1475
|
+
#define ZSTD_DECOMPRESSION_MARGIN(originalSize, blockSize) ((size_t)( \
|
|
1476
|
+
ZSTD_FRAMEHEADERSIZE_MAX /* Frame header */ + \
|
|
1477
|
+
4 /* checksum */ + \
|
|
1478
|
+
((originalSize) == 0 ? 0 : 3 * (((originalSize) + (blockSize) - 1) / blockSize)) /* 3 bytes per block */ + \
|
|
1479
|
+
(blockSize) /* One block of margin */ \
|
|
1480
|
+
))
|
|
1481
|
+
|
|
1372
1482
|
typedef enum {
|
|
1373
1483
|
ZSTD_sf_noBlockDelimiters = 0, /* Representation of ZSTD_Sequence has no block delimiters, sequences only */
|
|
1374
1484
|
ZSTD_sf_explicitBlockDelimiters = 1 /* Representation of ZSTD_Sequence contains explicit block delimiters */
|
|
1375
1485
|
} ZSTD_sequenceFormat_e;
|
|
1376
1486
|
|
|
1487
|
+
/*! ZSTD_sequenceBound() :
|
|
1488
|
+
* `srcSize` : size of the input buffer
|
|
1489
|
+
* @return : upper-bound for the number of sequences that can be generated
|
|
1490
|
+
* from a buffer of srcSize bytes
|
|
1491
|
+
*
|
|
1492
|
+
* note : returns number of sequences - to get bytes, multiply by sizeof(ZSTD_Sequence).
|
|
1493
|
+
*/
|
|
1494
|
+
ZSTDLIB_STATIC_API size_t ZSTD_sequenceBound(size_t srcSize);
|
|
1495
|
+
|
|
1377
1496
|
/*! ZSTD_generateSequences() :
|
|
1378
|
-
* Generate sequences using ZSTD_compress2, given a source buffer.
|
|
1497
|
+
* Generate sequences using ZSTD_compress2(), given a source buffer.
|
|
1379
1498
|
*
|
|
1380
1499
|
* Each block will end with a dummy sequence
|
|
1381
1500
|
* with offset == 0, matchLength == 0, and litLength == length of last literals.
|
|
1382
1501
|
* litLength may be == 0, and if so, then the sequence of (of: 0 ml: 0 ll: 0)
|
|
1383
1502
|
* simply acts as a block delimiter.
|
|
1384
1503
|
*
|
|
1385
|
-
* zc can be used to insert custom compression params.
|
|
1386
|
-
* This function invokes ZSTD_compress2
|
|
1504
|
+
* @zc can be used to insert custom compression params.
|
|
1505
|
+
* This function invokes ZSTD_compress2().
|
|
1387
1506
|
*
|
|
1388
1507
|
* The output of this function can be fed into ZSTD_compressSequences() with CCtx
|
|
1389
1508
|
* setting of ZSTD_c_blockDelimiters as ZSTD_sf_explicitBlockDelimiters
|
|
1390
1509
|
* @return : number of sequences generated
|
|
1391
1510
|
*/
|
|
1392
1511
|
|
|
1393
|
-
ZSTDLIB_STATIC_API size_t
|
|
1394
|
-
|
|
1512
|
+
ZSTDLIB_STATIC_API size_t
|
|
1513
|
+
ZSTD_generateSequences( ZSTD_CCtx* zc,
|
|
1514
|
+
ZSTD_Sequence* outSeqs, size_t outSeqsSize,
|
|
1515
|
+
const void* src, size_t srcSize);
|
|
1395
1516
|
|
|
1396
1517
|
/*! ZSTD_mergeBlockDelimiters() :
|
|
1397
1518
|
* Given an array of ZSTD_Sequence, remove all sequences that represent block delimiters/last literals
|
|
1398
|
-
* by merging them into
|
|
1519
|
+
* by merging them into the literals of the next sequence.
|
|
1399
1520
|
*
|
|
1400
1521
|
* As such, the final generated result has no explicit representation of block boundaries,
|
|
1401
1522
|
* and the final last literals segment is not represented in the sequences.
|
|
@@ -1407,7 +1528,9 @@ ZSTDLIB_STATIC_API size_t ZSTD_generateSequences(ZSTD_CCtx* zc, ZSTD_Sequence* o
|
|
|
1407
1528
|
ZSTDLIB_STATIC_API size_t ZSTD_mergeBlockDelimiters(ZSTD_Sequence* sequences, size_t seqsSize);
|
|
1408
1529
|
|
|
1409
1530
|
/*! ZSTD_compressSequences() :
|
|
1410
|
-
* Compress an array of ZSTD_Sequence,
|
|
1531
|
+
* Compress an array of ZSTD_Sequence, associated with @src buffer, into dst.
|
|
1532
|
+
* @src contains the entire input (not just the literals).
|
|
1533
|
+
* If @srcSize > sum(sequence.length), the remaining bytes are considered all literals
|
|
1411
1534
|
* If a dictionary is included, then the cctx should reference the dict. (see: ZSTD_CCtx_refCDict(), ZSTD_CCtx_loadDictionary(), etc.)
|
|
1412
1535
|
* The entire source is compressed into a single frame.
|
|
1413
1536
|
*
|
|
@@ -1432,17 +1555,18 @@ ZSTDLIB_STATIC_API size_t ZSTD_mergeBlockDelimiters(ZSTD_Sequence* sequences, si
|
|
|
1432
1555
|
* Note: Repcodes are, as of now, always re-calculated within this function, so ZSTD_Sequence::rep is unused.
|
|
1433
1556
|
* Note 2: Once we integrate ability to ingest repcodes, the explicit block delims mode must respect those repcodes exactly,
|
|
1434
1557
|
* and cannot emit an RLE block that disagrees with the repcode history
|
|
1435
|
-
* @return : final compressed size or a ZSTD error.
|
|
1558
|
+
* @return : final compressed size, or a ZSTD error code.
|
|
1436
1559
|
*/
|
|
1437
|
-
ZSTDLIB_STATIC_API size_t
|
|
1438
|
-
|
|
1439
|
-
|
|
1560
|
+
ZSTDLIB_STATIC_API size_t
|
|
1561
|
+
ZSTD_compressSequences( ZSTD_CCtx* cctx, void* dst, size_t dstSize,
|
|
1562
|
+
const ZSTD_Sequence* inSeqs, size_t inSeqsSize,
|
|
1563
|
+
const void* src, size_t srcSize);
|
|
1440
1564
|
|
|
1441
1565
|
|
|
1442
1566
|
/*! ZSTD_writeSkippableFrame() :
|
|
1443
1567
|
* Generates a zstd skippable frame containing data given by src, and writes it to dst buffer.
|
|
1444
1568
|
*
|
|
1445
|
-
* Skippable frames begin with a
|
|
1569
|
+
* Skippable frames begin with a 4-byte magic number. There are 16 possible choices of magic number,
|
|
1446
1570
|
* ranging from ZSTD_MAGIC_SKIPPABLE_START to ZSTD_MAGIC_SKIPPABLE_START+15.
|
|
1447
1571
|
* As such, the parameter magicVariant controls the exact skippable frame magic number variant used, so
|
|
1448
1572
|
* the magic number used will be ZSTD_MAGIC_SKIPPABLE_START + magicVariant.
|
|
@@ -1500,8 +1624,11 @@ ZSTDLIB_API unsigned ZSTD_isSkippableFrame(const void* buffer, size_t size);
|
|
|
1500
1624
|
* and ZSTD_estimateCCtxSize_usingCCtxParams(), which can be used in tandem with ZSTD_CCtxParams_setParameter().
|
|
1501
1625
|
* Both can be used to estimate memory using custom compression parameters and arbitrary srcSize limits.
|
|
1502
1626
|
*
|
|
1503
|
-
* Note
|
|
1627
|
+
* Note : only single-threaded compression is supported.
|
|
1504
1628
|
* ZSTD_estimateCCtxSize_usingCCtxParams() will return an error code if ZSTD_c_nbWorkers is >= 1.
|
|
1629
|
+
*
|
|
1630
|
+
* Note 2 : ZSTD_estimateCCtxSize* functions are not compatible with the Block-Level Sequence Producer API at this time.
|
|
1631
|
+
* Size estimates assume that no external sequence producer is registered.
|
|
1505
1632
|
*/
|
|
1506
1633
|
ZSTDLIB_STATIC_API size_t ZSTD_estimateCCtxSize(int compressionLevel);
|
|
1507
1634
|
ZSTDLIB_STATIC_API size_t ZSTD_estimateCCtxSize_usingCParams(ZSTD_compressionParameters cParams);
|
|
@@ -1520,7 +1647,12 @@ ZSTDLIB_STATIC_API size_t ZSTD_estimateDCtxSize(void);
|
|
|
1520
1647
|
* or deducted from a valid frame Header, using ZSTD_estimateDStreamSize_fromFrame();
|
|
1521
1648
|
* Note : if streaming is init with function ZSTD_init?Stream_usingDict(),
|
|
1522
1649
|
* an internal ?Dict will be created, which additional size is not estimated here.
|
|
1523
|
-
* In this case, get total size by adding ZSTD_estimate?DictSize
|
|
1650
|
+
* In this case, get total size by adding ZSTD_estimate?DictSize
|
|
1651
|
+
* Note 2 : only single-threaded compression is supported.
|
|
1652
|
+
* ZSTD_estimateCStreamSize_usingCCtxParams() will return an error code if ZSTD_c_nbWorkers is >= 1.
|
|
1653
|
+
* Note 3 : ZSTD_estimateCStreamSize* functions are not compatible with the Block-Level Sequence Producer API at this time.
|
|
1654
|
+
* Size estimates assume that no external sequence producer is registered.
|
|
1655
|
+
*/
|
|
1524
1656
|
ZSTDLIB_STATIC_API size_t ZSTD_estimateCStreamSize(int compressionLevel);
|
|
1525
1657
|
ZSTDLIB_STATIC_API size_t ZSTD_estimateCStreamSize_usingCParams(ZSTD_compressionParameters cParams);
|
|
1526
1658
|
ZSTDLIB_STATIC_API size_t ZSTD_estimateCStreamSize_usingCCtxParams(const ZSTD_CCtx_params* params);
|
|
@@ -1670,22 +1802,31 @@ ZSTDLIB_STATIC_API size_t ZSTD_checkCParams(ZSTD_compressionParameters params);
|
|
|
1670
1802
|
* This function never fails (wide contract) */
|
|
1671
1803
|
ZSTDLIB_STATIC_API ZSTD_compressionParameters ZSTD_adjustCParams(ZSTD_compressionParameters cPar, unsigned long long srcSize, size_t dictSize);
|
|
1672
1804
|
|
|
1805
|
+
/*! ZSTD_CCtx_setCParams() :
|
|
1806
|
+
* Set all parameters provided within @cparams into the working @cctx.
|
|
1807
|
+
* Note : if modifying parameters during compression (MT mode only),
|
|
1808
|
+
* note that changes to the .windowLog parameter will be ignored.
|
|
1809
|
+
* @return 0 on success, or an error code (can be checked with ZSTD_isError()) */
|
|
1810
|
+
ZSTDLIB_STATIC_API size_t ZSTD_CCtx_setCParams(ZSTD_CCtx* cctx, ZSTD_compressionParameters cparams);
|
|
1811
|
+
|
|
1673
1812
|
/*! ZSTD_compress_advanced() :
|
|
1674
1813
|
* Note : this function is now DEPRECATED.
|
|
1675
1814
|
* It can be replaced by ZSTD_compress2(), in combination with ZSTD_CCtx_setParameter() and other parameter setters.
|
|
1676
1815
|
* This prototype will generate compilation warnings. */
|
|
1677
1816
|
ZSTD_DEPRECATED("use ZSTD_compress2")
|
|
1817
|
+
ZSTDLIB_STATIC_API
|
|
1678
1818
|
size_t ZSTD_compress_advanced(ZSTD_CCtx* cctx,
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1819
|
+
void* dst, size_t dstCapacity,
|
|
1820
|
+
const void* src, size_t srcSize,
|
|
1821
|
+
const void* dict,size_t dictSize,
|
|
1822
|
+
ZSTD_parameters params);
|
|
1683
1823
|
|
|
1684
1824
|
/*! ZSTD_compress_usingCDict_advanced() :
|
|
1685
1825
|
* Note : this function is now DEPRECATED.
|
|
1686
1826
|
* It can be replaced by ZSTD_compress2(), in combination with ZSTD_CCtx_loadDictionary() and other parameter setters.
|
|
1687
1827
|
* This prototype will generate compilation warnings. */
|
|
1688
1828
|
ZSTD_DEPRECATED("use ZSTD_compress2 with ZSTD_CCtx_loadDictionary")
|
|
1829
|
+
ZSTDLIB_STATIC_API
|
|
1689
1830
|
size_t ZSTD_compress_usingCDict_advanced(ZSTD_CCtx* cctx,
|
|
1690
1831
|
void* dst, size_t dstCapacity,
|
|
1691
1832
|
const void* src, size_t srcSize,
|
|
@@ -1829,13 +1970,16 @@ ZSTDLIB_STATIC_API size_t ZSTD_CCtx_refPrefix_advanced(ZSTD_CCtx* cctx, const vo
|
|
|
1829
1970
|
* Experimental parameter.
|
|
1830
1971
|
* Default is 0 == disabled. Set to 1 to enable.
|
|
1831
1972
|
*
|
|
1832
|
-
* Tells the compressor that
|
|
1833
|
-
*
|
|
1834
|
-
*
|
|
1835
|
-
*
|
|
1836
|
-
*
|
|
1837
|
-
*
|
|
1838
|
-
*
|
|
1973
|
+
* Tells the compressor that input data presented with ZSTD_inBuffer
|
|
1974
|
+
* will ALWAYS be the same between calls.
|
|
1975
|
+
* Technically, the @src pointer must never be changed,
|
|
1976
|
+
* and the @pos field can only be updated by zstd.
|
|
1977
|
+
* However, it's possible to increase the @size field,
|
|
1978
|
+
* allowing scenarios where more data can be appended after compressions starts.
|
|
1979
|
+
* These conditions are checked by the compressor,
|
|
1980
|
+
* and compression will fail if they are not respected.
|
|
1981
|
+
* Also, data in the ZSTD_inBuffer within the range [src, src + pos)
|
|
1982
|
+
* MUST not be modified during compression or it will result in data corruption.
|
|
1839
1983
|
*
|
|
1840
1984
|
* When this flag is enabled zstd won't allocate an input window buffer,
|
|
1841
1985
|
* because the user guarantees it can reference the ZSTD_inBuffer until
|
|
@@ -1843,18 +1987,15 @@ ZSTDLIB_STATIC_API size_t ZSTD_CCtx_refPrefix_advanced(ZSTD_CCtx* cctx, const vo
|
|
|
1843
1987
|
* large enough to fit a block (see ZSTD_c_stableOutBuffer). This will also
|
|
1844
1988
|
* avoid the memcpy() from the input buffer to the input window buffer.
|
|
1845
1989
|
*
|
|
1846
|
-
* NOTE: ZSTD_compressStream2() will error if ZSTD_e_end is not used.
|
|
1847
|
-
* That means this flag cannot be used with ZSTD_compressStream().
|
|
1848
|
-
*
|
|
1849
1990
|
* NOTE: So long as the ZSTD_inBuffer always points to valid memory, using
|
|
1850
1991
|
* this flag is ALWAYS memory safe, and will never access out-of-bounds
|
|
1851
|
-
* memory. However, compression WILL fail if
|
|
1992
|
+
* memory. However, compression WILL fail if conditions are not respected.
|
|
1852
1993
|
*
|
|
1853
|
-
* WARNING: The data in the ZSTD_inBuffer in the range [
|
|
1854
|
-
* not be modified during compression or
|
|
1855
|
-
* is because zstd needs to reference data in the ZSTD_inBuffer to find
|
|
1994
|
+
* WARNING: The data in the ZSTD_inBuffer in the range [src, src + pos) MUST
|
|
1995
|
+
* not be modified during compression or it will result in data corruption.
|
|
1996
|
+
* This is because zstd needs to reference data in the ZSTD_inBuffer to find
|
|
1856
1997
|
* matches. Normally zstd maintains its own window buffer for this purpose,
|
|
1857
|
-
* but passing this flag tells zstd to
|
|
1998
|
+
* but passing this flag tells zstd to rely on user provided buffer instead.
|
|
1858
1999
|
*/
|
|
1859
2000
|
#define ZSTD_c_stableInBuffer ZSTD_c_experimentalParam9
|
|
1860
2001
|
|
|
@@ -1899,7 +2040,7 @@ ZSTDLIB_STATIC_API size_t ZSTD_CCtx_refPrefix_advanced(ZSTD_CCtx* cctx, const vo
|
|
|
1899
2040
|
* Without validation, providing a sequence that does not conform to the zstd spec will cause
|
|
1900
2041
|
* undefined behavior, and may produce a corrupted block.
|
|
1901
2042
|
*
|
|
1902
|
-
* With validation enabled,
|
|
2043
|
+
* With validation enabled, if sequence is invalid (see doc/zstd_compression_format.md for
|
|
1903
2044
|
* specifics regarding offset/matchlength requirements) then the function will bail out and
|
|
1904
2045
|
* return an error.
|
|
1905
2046
|
*
|
|
@@ -1949,6 +2090,79 @@ ZSTDLIB_STATIC_API size_t ZSTD_CCtx_refPrefix_advanced(ZSTD_CCtx* cctx, const vo
|
|
|
1949
2090
|
*/
|
|
1950
2091
|
#define ZSTD_c_deterministicRefPrefix ZSTD_c_experimentalParam15
|
|
1951
2092
|
|
|
2093
|
+
/* ZSTD_c_prefetchCDictTables
|
|
2094
|
+
* Controlled with ZSTD_paramSwitch_e enum. Default is ZSTD_ps_auto.
|
|
2095
|
+
*
|
|
2096
|
+
* In some situations, zstd uses CDict tables in-place rather than copying them
|
|
2097
|
+
* into the working context. (See docs on ZSTD_dictAttachPref_e above for details).
|
|
2098
|
+
* In such situations, compression speed is seriously impacted when CDict tables are
|
|
2099
|
+
* "cold" (outside CPU cache). This parameter instructs zstd to prefetch CDict tables
|
|
2100
|
+
* when they are used in-place.
|
|
2101
|
+
*
|
|
2102
|
+
* For sufficiently small inputs, the cost of the prefetch will outweigh the benefit.
|
|
2103
|
+
* For sufficiently large inputs, zstd will by default memcpy() CDict tables
|
|
2104
|
+
* into the working context, so there is no need to prefetch. This parameter is
|
|
2105
|
+
* targeted at a middle range of input sizes, where a prefetch is cheap enough to be
|
|
2106
|
+
* useful but memcpy() is too expensive. The exact range of input sizes where this
|
|
2107
|
+
* makes sense is best determined by careful experimentation.
|
|
2108
|
+
*
|
|
2109
|
+
* Note: for this parameter, ZSTD_ps_auto is currently equivalent to ZSTD_ps_disable,
|
|
2110
|
+
* but in the future zstd may conditionally enable this feature via an auto-detection
|
|
2111
|
+
* heuristic for cold CDicts.
|
|
2112
|
+
* Use ZSTD_ps_disable to opt out of prefetching under any circumstances.
|
|
2113
|
+
*/
|
|
2114
|
+
#define ZSTD_c_prefetchCDictTables ZSTD_c_experimentalParam16
|
|
2115
|
+
|
|
2116
|
+
/* ZSTD_c_enableSeqProducerFallback
|
|
2117
|
+
* Allowed values are 0 (disable) and 1 (enable). The default setting is 0.
|
|
2118
|
+
*
|
|
2119
|
+
* Controls whether zstd will fall back to an internal sequence producer if an
|
|
2120
|
+
* external sequence producer is registered and returns an error code. This fallback
|
|
2121
|
+
* is block-by-block: the internal sequence producer will only be called for blocks
|
|
2122
|
+
* where the external sequence producer returns an error code. Fallback parsing will
|
|
2123
|
+
* follow any other cParam settings, such as compression level, the same as in a
|
|
2124
|
+
* normal (fully-internal) compression operation.
|
|
2125
|
+
*
|
|
2126
|
+
* The user is strongly encouraged to read the full Block-Level Sequence Producer API
|
|
2127
|
+
* documentation (below) before setting this parameter. */
|
|
2128
|
+
#define ZSTD_c_enableSeqProducerFallback ZSTD_c_experimentalParam17
|
|
2129
|
+
|
|
2130
|
+
/* ZSTD_c_maxBlockSize
|
|
2131
|
+
* Allowed values are between 1KB and ZSTD_BLOCKSIZE_MAX (128KB).
|
|
2132
|
+
* The default is ZSTD_BLOCKSIZE_MAX, and setting to 0 will set to the default.
|
|
2133
|
+
*
|
|
2134
|
+
* This parameter can be used to set an upper bound on the blocksize
|
|
2135
|
+
* that overrides the default ZSTD_BLOCKSIZE_MAX. It cannot be used to set upper
|
|
2136
|
+
* bounds greater than ZSTD_BLOCKSIZE_MAX or bounds lower than 1KB (will make
|
|
2137
|
+
* compressBound() innacurate). Only currently meant to be used for testing.
|
|
2138
|
+
*
|
|
2139
|
+
*/
|
|
2140
|
+
#define ZSTD_c_maxBlockSize ZSTD_c_experimentalParam18
|
|
2141
|
+
|
|
2142
|
+
/* ZSTD_c_searchForExternalRepcodes
|
|
2143
|
+
* This parameter affects how zstd parses external sequences, such as sequences
|
|
2144
|
+
* provided through the compressSequences() API or from an external block-level
|
|
2145
|
+
* sequence producer.
|
|
2146
|
+
*
|
|
2147
|
+
* If set to ZSTD_ps_enable, the library will check for repeated offsets in
|
|
2148
|
+
* external sequences, even if those repcodes are not explicitly indicated in
|
|
2149
|
+
* the "rep" field. Note that this is the only way to exploit repcode matches
|
|
2150
|
+
* while using compressSequences() or an external sequence producer, since zstd
|
|
2151
|
+
* currently ignores the "rep" field of external sequences.
|
|
2152
|
+
*
|
|
2153
|
+
* If set to ZSTD_ps_disable, the library will not exploit repeated offsets in
|
|
2154
|
+
* external sequences, regardless of whether the "rep" field has been set. This
|
|
2155
|
+
* reduces sequence compression overhead by about 25% while sacrificing some
|
|
2156
|
+
* compression ratio.
|
|
2157
|
+
*
|
|
2158
|
+
* The default value is ZSTD_ps_auto, for which the library will enable/disable
|
|
2159
|
+
* based on compression level.
|
|
2160
|
+
*
|
|
2161
|
+
* Note: for now, this param only has an effect if ZSTD_c_blockDelimiters is
|
|
2162
|
+
* set to ZSTD_sf_explicitBlockDelimiters. That may change in the future.
|
|
2163
|
+
*/
|
|
2164
|
+
#define ZSTD_c_searchForExternalRepcodes ZSTD_c_experimentalParam19
|
|
2165
|
+
|
|
1952
2166
|
/*! ZSTD_CCtx_getParameter() :
|
|
1953
2167
|
* Get the requested compression parameter value, selected by enum ZSTD_cParameter,
|
|
1954
2168
|
* and store it into int* value.
|
|
@@ -2105,7 +2319,7 @@ ZSTDLIB_STATIC_API size_t ZSTD_DCtx_getParameter(ZSTD_DCtx* dctx, ZSTD_dParamete
|
|
|
2105
2319
|
* in the range [dst, dst + pos) MUST not be modified during decompression
|
|
2106
2320
|
* or you will get data corruption.
|
|
2107
2321
|
*
|
|
2108
|
-
* When this
|
|
2322
|
+
* When this flag is enabled zstd won't allocate an output buffer, because
|
|
2109
2323
|
* it can write directly to the ZSTD_outBuffer, but it will still allocate
|
|
2110
2324
|
* an input buffer large enough to fit any compressed block. This will also
|
|
2111
2325
|
* avoid the memcpy() from the internal output buffer to the ZSTD_outBuffer.
|
|
@@ -2158,6 +2372,17 @@ ZSTDLIB_STATIC_API size_t ZSTD_DCtx_getParameter(ZSTD_DCtx* dctx, ZSTD_dParamete
|
|
|
2158
2372
|
*/
|
|
2159
2373
|
#define ZSTD_d_refMultipleDDicts ZSTD_d_experimentalParam4
|
|
2160
2374
|
|
|
2375
|
+
/* ZSTD_d_disableHuffmanAssembly
|
|
2376
|
+
* Set to 1 to disable the Huffman assembly implementation.
|
|
2377
|
+
* The default value is 0, which allows zstd to use the Huffman assembly
|
|
2378
|
+
* implementation if available.
|
|
2379
|
+
*
|
|
2380
|
+
* This parameter can be used to disable Huffman assembly at runtime.
|
|
2381
|
+
* If you want to disable it at compile time you can define the macro
|
|
2382
|
+
* ZSTD_DISABLE_ASM.
|
|
2383
|
+
*/
|
|
2384
|
+
#define ZSTD_d_disableHuffmanAssembly ZSTD_d_experimentalParam5
|
|
2385
|
+
|
|
2161
2386
|
|
|
2162
2387
|
/*! ZSTD_DCtx_setFormat() :
|
|
2163
2388
|
* This function is REDUNDANT. Prefer ZSTD_DCtx_setParameter().
|
|
@@ -2166,6 +2391,7 @@ ZSTDLIB_STATIC_API size_t ZSTD_DCtx_getParameter(ZSTD_DCtx* dctx, ZSTD_dParamete
|
|
|
2166
2391
|
* such ZSTD_f_zstd1_magicless for example.
|
|
2167
2392
|
* @return : 0, or an error code (which can be tested using ZSTD_isError()). */
|
|
2168
2393
|
ZSTD_DEPRECATED("use ZSTD_DCtx_setParameter() instead")
|
|
2394
|
+
ZSTDLIB_STATIC_API
|
|
2169
2395
|
size_t ZSTD_DCtx_setFormat(ZSTD_DCtx* dctx, ZSTD_format_e format);
|
|
2170
2396
|
|
|
2171
2397
|
/*! ZSTD_decompressStream_simpleArgs() :
|
|
@@ -2202,6 +2428,7 @@ ZSTDLIB_STATIC_API size_t ZSTD_decompressStream_simpleArgs (
|
|
|
2202
2428
|
* This prototype will generate compilation warnings.
|
|
2203
2429
|
*/
|
|
2204
2430
|
ZSTD_DEPRECATED("use ZSTD_CCtx_reset, see zstd.h for detailed instructions")
|
|
2431
|
+
ZSTDLIB_STATIC_API
|
|
2205
2432
|
size_t ZSTD_initCStream_srcSize(ZSTD_CStream* zcs,
|
|
2206
2433
|
int compressionLevel,
|
|
2207
2434
|
unsigned long long pledgedSrcSize);
|
|
@@ -2219,6 +2446,7 @@ size_t ZSTD_initCStream_srcSize(ZSTD_CStream* zcs,
|
|
|
2219
2446
|
* This prototype will generate compilation warnings.
|
|
2220
2447
|
*/
|
|
2221
2448
|
ZSTD_DEPRECATED("use ZSTD_CCtx_reset, see zstd.h for detailed instructions")
|
|
2449
|
+
ZSTDLIB_STATIC_API
|
|
2222
2450
|
size_t ZSTD_initCStream_usingDict(ZSTD_CStream* zcs,
|
|
2223
2451
|
const void* dict, size_t dictSize,
|
|
2224
2452
|
int compressionLevel);
|
|
@@ -2239,6 +2467,7 @@ size_t ZSTD_initCStream_usingDict(ZSTD_CStream* zcs,
|
|
|
2239
2467
|
* This prototype will generate compilation warnings.
|
|
2240
2468
|
*/
|
|
2241
2469
|
ZSTD_DEPRECATED("use ZSTD_CCtx_reset, see zstd.h for detailed instructions")
|
|
2470
|
+
ZSTDLIB_STATIC_API
|
|
2242
2471
|
size_t ZSTD_initCStream_advanced(ZSTD_CStream* zcs,
|
|
2243
2472
|
const void* dict, size_t dictSize,
|
|
2244
2473
|
ZSTD_parameters params,
|
|
@@ -2253,6 +2482,7 @@ size_t ZSTD_initCStream_advanced(ZSTD_CStream* zcs,
|
|
|
2253
2482
|
* This prototype will generate compilation warnings.
|
|
2254
2483
|
*/
|
|
2255
2484
|
ZSTD_DEPRECATED("use ZSTD_CCtx_reset and ZSTD_CCtx_refCDict, see zstd.h for detailed instructions")
|
|
2485
|
+
ZSTDLIB_STATIC_API
|
|
2256
2486
|
size_t ZSTD_initCStream_usingCDict(ZSTD_CStream* zcs, const ZSTD_CDict* cdict);
|
|
2257
2487
|
|
|
2258
2488
|
/*! ZSTD_initCStream_usingCDict_advanced() :
|
|
@@ -2271,6 +2501,7 @@ size_t ZSTD_initCStream_usingCDict(ZSTD_CStream* zcs, const ZSTD_CDict* cdict);
|
|
|
2271
2501
|
* This prototype will generate compilation warnings.
|
|
2272
2502
|
*/
|
|
2273
2503
|
ZSTD_DEPRECATED("use ZSTD_CCtx_reset and ZSTD_CCtx_refCDict, see zstd.h for detailed instructions")
|
|
2504
|
+
ZSTDLIB_STATIC_API
|
|
2274
2505
|
size_t ZSTD_initCStream_usingCDict_advanced(ZSTD_CStream* zcs,
|
|
2275
2506
|
const ZSTD_CDict* cdict,
|
|
2276
2507
|
ZSTD_frameParameters fParams,
|
|
@@ -2295,6 +2526,7 @@ size_t ZSTD_initCStream_usingCDict_advanced(ZSTD_CStream* zcs,
|
|
|
2295
2526
|
* This prototype will generate compilation warnings.
|
|
2296
2527
|
*/
|
|
2297
2528
|
ZSTD_DEPRECATED("use ZSTD_CCtx_reset, see zstd.h for detailed instructions")
|
|
2529
|
+
ZSTDLIB_STATIC_API
|
|
2298
2530
|
size_t ZSTD_resetCStream(ZSTD_CStream* zcs, unsigned long long pledgedSrcSize);
|
|
2299
2531
|
|
|
2300
2532
|
|
|
@@ -2340,8 +2572,8 @@ ZSTDLIB_STATIC_API size_t ZSTD_toFlushNow(ZSTD_CCtx* cctx);
|
|
|
2340
2572
|
* ZSTD_DCtx_loadDictionary(zds, dict, dictSize);
|
|
2341
2573
|
*
|
|
2342
2574
|
* note: no dictionary will be used if dict == NULL or dictSize < 8
|
|
2343
|
-
* Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x
|
|
2344
2575
|
*/
|
|
2576
|
+
ZSTD_DEPRECATED("use ZSTD_DCtx_reset + ZSTD_DCtx_loadDictionary, see zstd.h for detailed instructions")
|
|
2345
2577
|
ZSTDLIB_STATIC_API size_t ZSTD_initDStream_usingDict(ZSTD_DStream* zds, const void* dict, size_t dictSize);
|
|
2346
2578
|
|
|
2347
2579
|
/*!
|
|
@@ -2351,8 +2583,8 @@ ZSTDLIB_STATIC_API size_t ZSTD_initDStream_usingDict(ZSTD_DStream* zds, const vo
|
|
|
2351
2583
|
* ZSTD_DCtx_refDDict(zds, ddict);
|
|
2352
2584
|
*
|
|
2353
2585
|
* note : ddict is referenced, it must outlive decompression session
|
|
2354
|
-
* Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x
|
|
2355
2586
|
*/
|
|
2587
|
+
ZSTD_DEPRECATED("use ZSTD_DCtx_reset + ZSTD_DCtx_refDDict, see zstd.h for detailed instructions")
|
|
2356
2588
|
ZSTDLIB_STATIC_API size_t ZSTD_initDStream_usingDDict(ZSTD_DStream* zds, const ZSTD_DDict* ddict);
|
|
2357
2589
|
|
|
2358
2590
|
/*!
|
|
@@ -2361,8 +2593,8 @@ ZSTDLIB_STATIC_API size_t ZSTD_initDStream_usingDDict(ZSTD_DStream* zds, const Z
|
|
|
2361
2593
|
* ZSTD_DCtx_reset(zds, ZSTD_reset_session_only);
|
|
2362
2594
|
*
|
|
2363
2595
|
* re-use decompression parameters from previous init; saves dictionary loading
|
|
2364
|
-
* Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x
|
|
2365
2596
|
*/
|
|
2597
|
+
ZSTD_DEPRECATED("use ZSTD_DCtx_reset, see zstd.h for detailed instructions")
|
|
2366
2598
|
ZSTDLIB_STATIC_API size_t ZSTD_resetDStream(ZSTD_DStream* zds);
|
|
2367
2599
|
|
|
2368
2600
|
|
|
@@ -2383,7 +2615,6 @@ ZSTDLIB_STATIC_API size_t ZSTD_resetDStream(ZSTD_DStream* zds);
|
|
|
2383
2615
|
|
|
2384
2616
|
Start by initializing a context.
|
|
2385
2617
|
Use ZSTD_compressBegin(), or ZSTD_compressBegin_usingDict() for dictionary compression.
|
|
2386
|
-
It's also possible to duplicate a reference context which has already been initialized, using ZSTD_copyCCtx()
|
|
2387
2618
|
|
|
2388
2619
|
Then, consume your input using ZSTD_compressContinue().
|
|
2389
2620
|
There are some important considerations to keep in mind when using this advanced function :
|
|
@@ -2408,15 +2639,20 @@ ZSTDLIB_STATIC_API size_t ZSTD_resetDStream(ZSTD_DStream* zds);
|
|
|
2408
2639
|
ZSTDLIB_STATIC_API size_t ZSTD_compressBegin(ZSTD_CCtx* cctx, int compressionLevel);
|
|
2409
2640
|
ZSTDLIB_STATIC_API size_t ZSTD_compressBegin_usingDict(ZSTD_CCtx* cctx, const void* dict, size_t dictSize, int compressionLevel);
|
|
2410
2641
|
ZSTDLIB_STATIC_API size_t ZSTD_compressBegin_usingCDict(ZSTD_CCtx* cctx, const ZSTD_CDict* cdict); /**< note: fails if cdict==NULL */
|
|
2411
|
-
|
|
2642
|
+
|
|
2643
|
+
ZSTD_DEPRECATED("This function will likely be removed in a future release. It is misleading and has very limited utility.")
|
|
2644
|
+
ZSTDLIB_STATIC_API
|
|
2645
|
+
size_t ZSTD_copyCCtx(ZSTD_CCtx* cctx, const ZSTD_CCtx* preparedCCtx, unsigned long long pledgedSrcSize); /**< note: if pledgedSrcSize is not known, use ZSTD_CONTENTSIZE_UNKNOWN */
|
|
2412
2646
|
|
|
2413
2647
|
ZSTDLIB_STATIC_API size_t ZSTD_compressContinue(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize);
|
|
2414
2648
|
ZSTDLIB_STATIC_API size_t ZSTD_compressEnd(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize);
|
|
2415
2649
|
|
|
2416
2650
|
/* The ZSTD_compressBegin_advanced() and ZSTD_compressBegin_usingCDict_advanced() are now DEPRECATED and will generate a compiler warning */
|
|
2417
2651
|
ZSTD_DEPRECATED("use advanced API to access custom parameters")
|
|
2652
|
+
ZSTDLIB_STATIC_API
|
|
2418
2653
|
size_t ZSTD_compressBegin_advanced(ZSTD_CCtx* cctx, const void* dict, size_t dictSize, ZSTD_parameters params, unsigned long long pledgedSrcSize); /**< pledgedSrcSize : If srcSize is not known at init time, use ZSTD_CONTENTSIZE_UNKNOWN */
|
|
2419
2654
|
ZSTD_DEPRECATED("use advanced API to access custom parameters")
|
|
2655
|
+
ZSTDLIB_STATIC_API
|
|
2420
2656
|
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 */
|
|
2421
2657
|
/**
|
|
2422
2658
|
Buffer-less streaming decompression (synchronous mode)
|
|
@@ -2429,8 +2665,8 @@ size_t ZSTD_compressBegin_usingCDict_advanced(ZSTD_CCtx* const cctx, const ZSTD_
|
|
|
2429
2665
|
Frame header is extracted from the beginning of compressed frame, so providing only the frame's beginning is enough.
|
|
2430
2666
|
Data fragment must be large enough to ensure successful decoding.
|
|
2431
2667
|
`ZSTD_frameHeaderSize_max` bytes is guaranteed to always be large enough.
|
|
2432
|
-
|
|
2433
|
-
>0 : `srcSize` is too small, please provide at least
|
|
2668
|
+
result : 0 : successful decoding, the `ZSTD_frameHeader` structure is correctly filled.
|
|
2669
|
+
>0 : `srcSize` is too small, please provide at least result bytes on next attempt.
|
|
2434
2670
|
errorCode, which can be tested using ZSTD_isError().
|
|
2435
2671
|
|
|
2436
2672
|
It fills a ZSTD_frameHeader structure with important information to correctly decode the frame,
|
|
@@ -2449,7 +2685,7 @@ size_t ZSTD_compressBegin_usingCDict_advanced(ZSTD_CCtx* const cctx, const ZSTD_
|
|
|
2449
2685
|
|
|
2450
2686
|
The most memory efficient way is to use a round buffer of sufficient size.
|
|
2451
2687
|
Sufficient size is determined by invoking ZSTD_decodingBufferSize_min(),
|
|
2452
|
-
which can
|
|
2688
|
+
which can return an error code if required value is too large for current system (in 32-bits mode).
|
|
2453
2689
|
In a round buffer methodology, ZSTD_decompressContinue() decompresses each block next to previous one,
|
|
2454
2690
|
up to the moment there is not enough room left in the buffer to guarantee decoding another full block,
|
|
2455
2691
|
which maximum size is provided in `ZSTD_frameHeader` structure, field `blockSizeMax`.
|
|
@@ -2469,7 +2705,7 @@ size_t ZSTD_compressBegin_usingCDict_advanced(ZSTD_CCtx* const cctx, const ZSTD_
|
|
|
2469
2705
|
ZSTD_nextSrcSizeToDecompress() tells how many bytes to provide as 'srcSize' to ZSTD_decompressContinue().
|
|
2470
2706
|
ZSTD_decompressContinue() requires this _exact_ amount of bytes, or it will fail.
|
|
2471
2707
|
|
|
2472
|
-
|
|
2708
|
+
result of ZSTD_decompressContinue() is the number of bytes regenerated within 'dst' (necessarily <= dstCapacity).
|
|
2473
2709
|
It can be zero : it just means ZSTD_decompressContinue() has decoded some metadata item.
|
|
2474
2710
|
It can also be an error code, which can be tested with ZSTD_isError().
|
|
2475
2711
|
|
|
@@ -2501,6 +2737,8 @@ typedef struct {
|
|
|
2501
2737
|
unsigned headerSize;
|
|
2502
2738
|
unsigned dictID;
|
|
2503
2739
|
unsigned checksumFlag;
|
|
2740
|
+
unsigned _reserved1;
|
|
2741
|
+
unsigned _reserved2;
|
|
2504
2742
|
} ZSTD_frameHeader;
|
|
2505
2743
|
|
|
2506
2744
|
/*! ZSTD_getFrameHeader() :
|
|
@@ -2523,6 +2761,7 @@ ZSTDLIB_STATIC_API size_t ZSTD_nextSrcSizeToDecompress(ZSTD_DCtx* dctx);
|
|
|
2523
2761
|
ZSTDLIB_STATIC_API size_t ZSTD_decompressContinue(ZSTD_DCtx* dctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize);
|
|
2524
2762
|
|
|
2525
2763
|
/* misc */
|
|
2764
|
+
ZSTD_DEPRECATED("This function will likely be removed in the next minor release. It is misleading and has very limited utility.")
|
|
2526
2765
|
ZSTDLIB_STATIC_API void ZSTD_copyDCtx(ZSTD_DCtx* dctx, const ZSTD_DCtx* preparedDCtx);
|
|
2527
2766
|
typedef enum { ZSTDnit_frameHeader, ZSTDnit_blockHeader, ZSTDnit_block, ZSTDnit_lastBlock, ZSTDnit_checksum, ZSTDnit_skippableFrame } ZSTD_nextInputType_e;
|
|
2528
2767
|
ZSTDLIB_STATIC_API ZSTD_nextInputType_e ZSTD_nextInputType(ZSTD_DCtx* dctx);
|
|
@@ -2545,7 +2784,6 @@ ZSTDLIB_STATIC_API ZSTD_nextInputType_e ZSTD_nextInputType(ZSTD_DCtx* dctx);
|
|
|
2545
2784
|
- It is necessary to init context before starting
|
|
2546
2785
|
+ compression : any ZSTD_compressBegin*() variant, including with dictionary
|
|
2547
2786
|
+ decompression : any ZSTD_decompressBegin*() variant, including with dictionary
|
|
2548
|
-
+ copyCCtx() and copyDCtx() can be used too
|
|
2549
2787
|
- Block size is limited, it must be <= ZSTD_getBlockSize() <= ZSTD_BLOCKSIZE_MAX == 128 KB
|
|
2550
2788
|
+ If input is larger than a block size, it's necessary to split input data into multiple blocks
|
|
2551
2789
|
+ For inputs larger than a single block, consider using regular ZSTD_compress() instead.
|
|
@@ -2568,6 +2806,167 @@ ZSTDLIB_STATIC_API size_t ZSTD_decompressBlock(ZSTD_DCtx* dctx, void* dst, size_
|
|
|
2568
2806
|
ZSTDLIB_STATIC_API size_t ZSTD_insertBlock (ZSTD_DCtx* dctx, const void* blockStart, size_t blockSize); /**< insert uncompressed block into `dctx` history. Useful for multi-blocks decompression. */
|
|
2569
2807
|
|
|
2570
2808
|
|
|
2809
|
+
/* ********************* BLOCK-LEVEL SEQUENCE PRODUCER API *********************
|
|
2810
|
+
*
|
|
2811
|
+
* *** OVERVIEW ***
|
|
2812
|
+
* The Block-Level Sequence Producer API allows users to provide their own custom
|
|
2813
|
+
* sequence producer which libzstd invokes to process each block. The produced list
|
|
2814
|
+
* of sequences (literals and matches) is then post-processed by libzstd to produce
|
|
2815
|
+
* valid compressed blocks.
|
|
2816
|
+
*
|
|
2817
|
+
* This block-level offload API is a more granular complement of the existing
|
|
2818
|
+
* frame-level offload API compressSequences() (introduced in v1.5.1). It offers
|
|
2819
|
+
* an easier migration story for applications already integrated with libzstd: the
|
|
2820
|
+
* user application continues to invoke the same compression functions
|
|
2821
|
+
* ZSTD_compress2() or ZSTD_compressStream2() as usual, and transparently benefits
|
|
2822
|
+
* from the specific advantages of the external sequence producer. For example,
|
|
2823
|
+
* the sequence producer could be tuned to take advantage of known characteristics
|
|
2824
|
+
* of the input, to offer better speed / ratio, or could leverage hardware
|
|
2825
|
+
* acceleration not available within libzstd itself.
|
|
2826
|
+
*
|
|
2827
|
+
* See contrib/externalSequenceProducer for an example program employing the
|
|
2828
|
+
* Block-Level Sequence Producer API.
|
|
2829
|
+
*
|
|
2830
|
+
* *** USAGE ***
|
|
2831
|
+
* The user is responsible for implementing a function of type
|
|
2832
|
+
* ZSTD_sequenceProducer_F. For each block, zstd will pass the following
|
|
2833
|
+
* arguments to the user-provided function:
|
|
2834
|
+
*
|
|
2835
|
+
* - sequenceProducerState: a pointer to a user-managed state for the sequence
|
|
2836
|
+
* producer.
|
|
2837
|
+
*
|
|
2838
|
+
* - outSeqs, outSeqsCapacity: an output buffer for the sequence producer.
|
|
2839
|
+
* outSeqsCapacity is guaranteed >= ZSTD_sequenceBound(srcSize). The memory
|
|
2840
|
+
* backing outSeqs is managed by the CCtx.
|
|
2841
|
+
*
|
|
2842
|
+
* - src, srcSize: an input buffer for the sequence producer to parse.
|
|
2843
|
+
* srcSize is guaranteed to be <= ZSTD_BLOCKSIZE_MAX.
|
|
2844
|
+
*
|
|
2845
|
+
* - dict, dictSize: a history buffer, which may be empty, which the sequence
|
|
2846
|
+
* producer may reference as it parses the src buffer. Currently, zstd will
|
|
2847
|
+
* always pass dictSize == 0 into external sequence producers, but this will
|
|
2848
|
+
* change in the future.
|
|
2849
|
+
*
|
|
2850
|
+
* - compressionLevel: a signed integer representing the zstd compression level
|
|
2851
|
+
* set by the user for the current operation. The sequence producer may choose
|
|
2852
|
+
* to use this information to change its compression strategy and speed/ratio
|
|
2853
|
+
* tradeoff. Note: the compression level does not reflect zstd parameters set
|
|
2854
|
+
* through the advanced API.
|
|
2855
|
+
*
|
|
2856
|
+
* - windowSize: a size_t representing the maximum allowed offset for external
|
|
2857
|
+
* sequences. Note that sequence offsets are sometimes allowed to exceed the
|
|
2858
|
+
* windowSize if a dictionary is present, see doc/zstd_compression_format.md
|
|
2859
|
+
* for details.
|
|
2860
|
+
*
|
|
2861
|
+
* The user-provided function shall return a size_t representing the number of
|
|
2862
|
+
* sequences written to outSeqs. This return value will be treated as an error
|
|
2863
|
+
* code if it is greater than outSeqsCapacity. The return value must be non-zero
|
|
2864
|
+
* if srcSize is non-zero. The ZSTD_SEQUENCE_PRODUCER_ERROR macro is provided
|
|
2865
|
+
* for convenience, but any value greater than outSeqsCapacity will be treated as
|
|
2866
|
+
* an error code.
|
|
2867
|
+
*
|
|
2868
|
+
* If the user-provided function does not return an error code, the sequences
|
|
2869
|
+
* written to outSeqs must be a valid parse of the src buffer. Data corruption may
|
|
2870
|
+
* occur if the parse is not valid. A parse is defined to be valid if the
|
|
2871
|
+
* following conditions hold:
|
|
2872
|
+
* - The sum of matchLengths and literalLengths must equal srcSize.
|
|
2873
|
+
* - All sequences in the parse, except for the final sequence, must have
|
|
2874
|
+
* matchLength >= ZSTD_MINMATCH_MIN. The final sequence must have
|
|
2875
|
+
* matchLength >= ZSTD_MINMATCH_MIN or matchLength == 0.
|
|
2876
|
+
* - All offsets must respect the windowSize parameter as specified in
|
|
2877
|
+
* doc/zstd_compression_format.md.
|
|
2878
|
+
* - If the final sequence has matchLength == 0, it must also have offset == 0.
|
|
2879
|
+
*
|
|
2880
|
+
* zstd will only validate these conditions (and fail compression if they do not
|
|
2881
|
+
* hold) if the ZSTD_c_validateSequences cParam is enabled. Note that sequence
|
|
2882
|
+
* validation has a performance cost.
|
|
2883
|
+
*
|
|
2884
|
+
* If the user-provided function returns an error, zstd will either fall back
|
|
2885
|
+
* to an internal sequence producer or fail the compression operation. The user can
|
|
2886
|
+
* choose between the two behaviors by setting the ZSTD_c_enableSeqProducerFallback
|
|
2887
|
+
* cParam. Fallback compression will follow any other cParam settings, such as
|
|
2888
|
+
* compression level, the same as in a normal compression operation.
|
|
2889
|
+
*
|
|
2890
|
+
* The user shall instruct zstd to use a particular ZSTD_sequenceProducer_F
|
|
2891
|
+
* function by calling
|
|
2892
|
+
* ZSTD_registerSequenceProducer(cctx,
|
|
2893
|
+
* sequenceProducerState,
|
|
2894
|
+
* sequenceProducer)
|
|
2895
|
+
* This setting will persist until the next parameter reset of the CCtx.
|
|
2896
|
+
*
|
|
2897
|
+
* The sequenceProducerState must be initialized by the user before calling
|
|
2898
|
+
* ZSTD_registerSequenceProducer(). The user is responsible for destroying the
|
|
2899
|
+
* sequenceProducerState.
|
|
2900
|
+
*
|
|
2901
|
+
* *** LIMITATIONS ***
|
|
2902
|
+
* This API is compatible with all zstd compression APIs which respect advanced parameters.
|
|
2903
|
+
* However, there are three limitations:
|
|
2904
|
+
*
|
|
2905
|
+
* First, the ZSTD_c_enableLongDistanceMatching cParam is not currently supported.
|
|
2906
|
+
* COMPRESSION WILL FAIL if it is enabled and the user tries to compress with a block-level
|
|
2907
|
+
* external sequence producer.
|
|
2908
|
+
* - Note that ZSTD_c_enableLongDistanceMatching is auto-enabled by default in some
|
|
2909
|
+
* cases (see its documentation for details). Users must explicitly set
|
|
2910
|
+
* ZSTD_c_enableLongDistanceMatching to ZSTD_ps_disable in such cases if an external
|
|
2911
|
+
* sequence producer is registered.
|
|
2912
|
+
* - As of this writing, ZSTD_c_enableLongDistanceMatching is disabled by default
|
|
2913
|
+
* whenever ZSTD_c_windowLog < 128MB, but that's subject to change. Users should
|
|
2914
|
+
* check the docs on ZSTD_c_enableLongDistanceMatching whenever the Block-Level Sequence
|
|
2915
|
+
* Producer API is used in conjunction with advanced settings (like ZSTD_c_windowLog).
|
|
2916
|
+
*
|
|
2917
|
+
* Second, history buffers are not currently supported. Concretely, zstd will always pass
|
|
2918
|
+
* dictSize == 0 to the external sequence producer (for now). This has two implications:
|
|
2919
|
+
* - Dictionaries are not currently supported. Compression will *not* fail if the user
|
|
2920
|
+
* references a dictionary, but the dictionary won't have any effect.
|
|
2921
|
+
* - Stream history is not currently supported. All advanced compression APIs, including
|
|
2922
|
+
* streaming APIs, work with external sequence producers, but each block is treated as
|
|
2923
|
+
* an independent chunk without history from previous blocks.
|
|
2924
|
+
*
|
|
2925
|
+
* Third, multi-threading within a single compression is not currently supported. In other words,
|
|
2926
|
+
* COMPRESSION WILL FAIL if ZSTD_c_nbWorkers > 0 and an external sequence producer is registered.
|
|
2927
|
+
* Multi-threading across compressions is fine: simply create one CCtx per thread.
|
|
2928
|
+
*
|
|
2929
|
+
* Long-term, we plan to overcome all three limitations. There is no technical blocker to
|
|
2930
|
+
* overcoming them. It is purely a question of engineering effort.
|
|
2931
|
+
*/
|
|
2932
|
+
|
|
2933
|
+
#define ZSTD_SEQUENCE_PRODUCER_ERROR ((size_t)(-1))
|
|
2934
|
+
|
|
2935
|
+
typedef size_t ZSTD_sequenceProducer_F (
|
|
2936
|
+
void* sequenceProducerState,
|
|
2937
|
+
ZSTD_Sequence* outSeqs, size_t outSeqsCapacity,
|
|
2938
|
+
const void* src, size_t srcSize,
|
|
2939
|
+
const void* dict, size_t dictSize,
|
|
2940
|
+
int compressionLevel,
|
|
2941
|
+
size_t windowSize
|
|
2942
|
+
);
|
|
2943
|
+
|
|
2944
|
+
/*! ZSTD_registerSequenceProducer() :
|
|
2945
|
+
* Instruct zstd to use a block-level external sequence producer function.
|
|
2946
|
+
*
|
|
2947
|
+
* The sequenceProducerState must be initialized by the caller, and the caller is
|
|
2948
|
+
* responsible for managing its lifetime. This parameter is sticky across
|
|
2949
|
+
* compressions. It will remain set until the user explicitly resets compression
|
|
2950
|
+
* parameters.
|
|
2951
|
+
*
|
|
2952
|
+
* Sequence producer registration is considered to be an "advanced parameter",
|
|
2953
|
+
* part of the "advanced API". This means it will only have an effect on compression
|
|
2954
|
+
* APIs which respect advanced parameters, such as compress2() and compressStream2().
|
|
2955
|
+
* Older compression APIs such as compressCCtx(), which predate the introduction of
|
|
2956
|
+
* "advanced parameters", will ignore any external sequence producer setting.
|
|
2957
|
+
*
|
|
2958
|
+
* The sequence producer can be "cleared" by registering a NULL function pointer. This
|
|
2959
|
+
* removes all limitations described above in the "LIMITATIONS" section of the API docs.
|
|
2960
|
+
*
|
|
2961
|
+
* The user is strongly encouraged to read the full API documentation (above) before
|
|
2962
|
+
* calling this function. */
|
|
2963
|
+
ZSTDLIB_STATIC_API void
|
|
2964
|
+
ZSTD_registerSequenceProducer(
|
|
2965
|
+
ZSTD_CCtx* cctx,
|
|
2966
|
+
void* sequenceProducerState,
|
|
2967
|
+
ZSTD_sequenceProducer_F* sequenceProducer
|
|
2968
|
+
);
|
|
2969
|
+
|
|
2571
2970
|
#endif /* ZSTD_H_ZSTD_STATIC_LINKING_ONLY */
|
|
2572
2971
|
|
|
2573
2972
|
#if defined (__cplusplus)
|