multi_compress 0.3.1 → 0.3.3
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/CHANGELOG.md +15 -3
- data/GET_STARTED.md +3 -3
- data/README.md +75 -66
- data/THIRD_PARTY_NOTICES.md +24 -0
- data/ext/multi_compress/brotli_dec_static_init.c +3 -0
- data/ext/multi_compress/brotli_enc_static_init.c +3 -0
- data/ext/multi_compress/extconf.rb +22 -1
- data/ext/multi_compress/multi_compress.c +152 -72
- data/ext/multi_compress/vendor/.vendored +2 -2
- data/ext/multi_compress/vendor/brotli/LICENSE +19 -0
- data/ext/multi_compress/vendor/brotli/c/common/constants.c +7 -7
- data/ext/multi_compress/vendor/brotli/c/common/constants.h +2 -5
- data/ext/multi_compress/vendor/brotli/c/common/context.c +2 -2
- data/ext/multi_compress/vendor/brotli/c/common/context.h +1 -2
- data/ext/multi_compress/vendor/brotli/c/common/dictionary.c +4 -5856
- data/ext/multi_compress/vendor/brotli/c/common/dictionary.h +1 -2
- data/ext/multi_compress/vendor/brotli/c/common/dictionary_inc.h +5847 -0
- data/ext/multi_compress/vendor/brotli/c/common/platform.c +0 -4
- data/ext/multi_compress/vendor/brotli/c/common/platform.h +182 -43
- data/ext/multi_compress/vendor/brotli/c/common/shared_dictionary.c +3 -7
- data/ext/multi_compress/vendor/brotli/c/common/shared_dictionary_internal.h +1 -1
- data/ext/multi_compress/vendor/brotli/c/common/static_init.h +56 -0
- data/ext/multi_compress/vendor/brotli/c/common/transform.c +6 -4
- data/ext/multi_compress/vendor/brotli/c/common/transform.h +1 -2
- data/ext/multi_compress/vendor/brotli/c/common/version.h +3 -3
- data/ext/multi_compress/vendor/brotli/c/dec/bit_reader.c +2 -3
- data/ext/multi_compress/vendor/brotli/c/dec/bit_reader.h +0 -4
- data/ext/multi_compress/vendor/brotli/c/dec/decode.c +128 -39
- data/ext/multi_compress/vendor/brotli/c/dec/huffman.c +2 -5
- data/ext/multi_compress/vendor/brotli/c/dec/huffman.h +0 -2
- data/ext/multi_compress/vendor/brotli/c/dec/prefix.c +67 -0
- data/ext/multi_compress/vendor/brotli/c/dec/prefix.h +18 -708
- data/ext/multi_compress/vendor/brotli/c/dec/prefix_inc.h +707 -0
- data/ext/multi_compress/vendor/brotli/c/dec/state.c +18 -15
- data/ext/multi_compress/vendor/brotli/c/dec/state.h +2 -6
- data/ext/multi_compress/vendor/brotli/c/dec/static_init.c +53 -0
- data/ext/multi_compress/vendor/brotli/c/dec/static_init.h +30 -0
- data/ext/multi_compress/vendor/brotli/c/enc/backward_references.c +32 -8
- data/ext/multi_compress/vendor/brotli/c/enc/backward_references.h +1 -5
- data/ext/multi_compress/vendor/brotli/c/enc/backward_references_hq.c +15 -15
- data/ext/multi_compress/vendor/brotli/c/enc/backward_references_hq.h +1 -5
- data/ext/multi_compress/vendor/brotli/c/enc/bit_cost.c +28 -4
- data/ext/multi_compress/vendor/brotli/c/enc/bit_cost.h +8 -40
- data/ext/multi_compress/vendor/brotli/c/enc/bit_cost_inc.h +1 -1
- data/ext/multi_compress/vendor/brotli/c/enc/block_splitter.c +9 -12
- data/ext/multi_compress/vendor/brotli/c/enc/block_splitter.h +0 -3
- data/ext/multi_compress/vendor/brotli/c/enc/block_splitter_inc.h +14 -8
- data/ext/multi_compress/vendor/brotli/c/enc/brotli_bit_stream.c +10 -9
- data/ext/multi_compress/vendor/brotli/c/enc/brotli_bit_stream.h +0 -6
- data/ext/multi_compress/vendor/brotli/c/enc/cluster.c +0 -2
- data/ext/multi_compress/vendor/brotli/c/enc/cluster.h +0 -2
- data/ext/multi_compress/vendor/brotli/c/enc/command.c +1 -1
- data/ext/multi_compress/vendor/brotli/c/enc/command.h +8 -10
- data/ext/multi_compress/vendor/brotli/c/enc/compound_dictionary.c +3 -5
- data/ext/multi_compress/vendor/brotli/c/enc/compound_dictionary.h +1 -4
- data/ext/multi_compress/vendor/brotli/c/enc/compress_fragment.c +3 -13
- data/ext/multi_compress/vendor/brotli/c/enc/compress_fragment.h +0 -2
- data/ext/multi_compress/vendor/brotli/c/enc/compress_fragment_two_pass.c +5 -15
- data/ext/multi_compress/vendor/brotli/c/enc/compress_fragment_two_pass.h +0 -2
- data/ext/multi_compress/vendor/brotli/c/enc/dictionary_hash.c +127 -1830
- data/ext/multi_compress/vendor/brotli/c/enc/dictionary_hash.h +23 -3
- data/ext/multi_compress/vendor/brotli/c/enc/dictionary_hash_inc.h +1829 -0
- data/ext/multi_compress/vendor/brotli/c/enc/encode.c +77 -52
- data/ext/multi_compress/vendor/brotli/c/enc/encoder_dict.c +9 -7
- data/ext/multi_compress/vendor/brotli/c/enc/encoder_dict.h +2 -4
- data/ext/multi_compress/vendor/brotli/c/enc/entropy_encode.c +3 -6
- data/ext/multi_compress/vendor/brotli/c/enc/entropy_encode.h +2 -4
- data/ext/multi_compress/vendor/brotli/c/enc/entropy_encode_static.h +18 -12
- data/ext/multi_compress/vendor/brotli/c/enc/fast_log.c +1 -1
- data/ext/multi_compress/vendor/brotli/c/enc/fast_log.h +2 -3
- data/ext/multi_compress/vendor/brotli/c/enc/find_match_length.h +0 -2
- data/ext/multi_compress/vendor/brotli/c/enc/hash.h +38 -31
- data/ext/multi_compress/vendor/brotli/c/enc/hash_base.h +38 -0
- data/ext/multi_compress/vendor/brotli/c/enc/hash_forgetful_chain_inc.h +11 -1
- data/ext/multi_compress/vendor/brotli/c/enc/hash_longest_match64_inc.h +24 -7
- data/ext/multi_compress/vendor/brotli/c/enc/hash_longest_match64_simd_inc.h +304 -0
- data/ext/multi_compress/vendor/brotli/c/enc/hash_longest_match_inc.h +30 -11
- data/ext/multi_compress/vendor/brotli/c/enc/hash_longest_match_quickly_inc.h +4 -0
- data/ext/multi_compress/vendor/brotli/c/enc/hash_longest_match_simd_inc.h +278 -0
- data/ext/multi_compress/vendor/brotli/c/enc/histogram.c +1 -0
- data/ext/multi_compress/vendor/brotli/c/enc/histogram.h +0 -4
- data/ext/multi_compress/vendor/brotli/c/enc/literal_cost.c +4 -6
- data/ext/multi_compress/vendor/brotli/c/enc/literal_cost.h +0 -2
- data/ext/multi_compress/vendor/brotli/c/enc/matching_tag_mask.h +69 -0
- data/ext/multi_compress/vendor/brotli/c/enc/memory.c +0 -5
- data/ext/multi_compress/vendor/brotli/c/enc/memory.h +0 -4
- data/ext/multi_compress/vendor/brotli/c/enc/metablock.c +7 -9
- data/ext/multi_compress/vendor/brotli/c/enc/metablock.h +3 -3
- data/ext/multi_compress/vendor/brotli/c/enc/metablock_inc.h +4 -4
- data/ext/multi_compress/vendor/brotli/c/enc/params.h +0 -1
- data/ext/multi_compress/vendor/brotli/c/enc/prefix.h +0 -2
- data/ext/multi_compress/vendor/brotli/c/enc/quality.h +17 -10
- data/ext/multi_compress/vendor/brotli/c/enc/ringbuffer.h +1 -4
- data/ext/multi_compress/vendor/brotli/c/enc/state.h +2 -2
- data/ext/multi_compress/vendor/brotli/c/enc/static_dict.c +5 -11
- data/ext/multi_compress/vendor/brotli/c/enc/static_dict.h +1 -3
- data/ext/multi_compress/vendor/brotli/c/enc/static_dict_lut.c +224 -0
- data/ext/multi_compress/vendor/brotli/c/enc/static_dict_lut.h +20 -5837
- data/ext/multi_compress/vendor/brotli/c/enc/static_dict_lut_inc.h +5830 -0
- data/ext/multi_compress/vendor/brotli/c/enc/static_init.c +59 -0
- data/ext/multi_compress/vendor/brotli/c/enc/static_init.h +30 -0
- data/ext/multi_compress/vendor/brotli/c/enc/static_init_lazy.cc +26 -0
- data/ext/multi_compress/vendor/brotli/c/enc/utf8_util.c +1 -1
- data/ext/multi_compress/vendor/brotli/c/enc/utf8_util.h +0 -2
- data/ext/multi_compress/vendor/brotli/c/enc/write_bits.h +0 -2
- data/ext/multi_compress/vendor/brotli/c/include/brotli/decode.h +1 -1
- data/ext/multi_compress/vendor/brotli/c/include/brotli/encode.h +5 -1
- data/ext/multi_compress/vendor/brotli/c/include/brotli/port.h +4 -7
- data/ext/multi_compress/vendor/brotli/c/include/brotli/types.h +2 -2
- data/ext/multi_compress/vendor/lz4/LICENSE +12 -0
- data/ext/multi_compress/vendor/zstd/COPYING +339 -0
- data/ext/multi_compress/vendor/zstd/LICENSE +30 -0
- data/ext/multi_compress/vendor/zstd/lib/Makefile +67 -35
- data/ext/multi_compress/vendor/zstd/lib/README.md +33 -2
- data/ext/multi_compress/vendor/zstd/lib/common/allocations.h +55 -0
- data/ext/multi_compress/vendor/zstd/lib/common/bits.h +205 -0
- data/ext/multi_compress/vendor/zstd/lib/common/bitstream.h +84 -108
- data/ext/multi_compress/vendor/zstd/lib/common/compiler.h +170 -41
- data/ext/multi_compress/vendor/zstd/lib/common/cpu.h +37 -1
- data/ext/multi_compress/vendor/zstd/lib/common/debug.c +7 -1
- data/ext/multi_compress/vendor/zstd/lib/common/debug.h +21 -21
- data/ext/multi_compress/vendor/zstd/lib/common/entropy_common.c +12 -40
- data/ext/multi_compress/vendor/zstd/lib/common/error_private.c +10 -2
- data/ext/multi_compress/vendor/zstd/lib/common/error_private.h +46 -47
- data/ext/multi_compress/vendor/zstd/lib/common/fse.h +8 -100
- data/ext/multi_compress/vendor/zstd/lib/common/fse_decompress.c +28 -116
- data/ext/multi_compress/vendor/zstd/lib/common/huf.h +79 -166
- data/ext/multi_compress/vendor/zstd/lib/common/mem.h +46 -66
- data/ext/multi_compress/vendor/zstd/lib/common/pool.c +27 -11
- data/ext/multi_compress/vendor/zstd/lib/common/pool.h +8 -11
- data/ext/multi_compress/vendor/zstd/lib/common/portability_macros.h +45 -11
- data/ext/multi_compress/vendor/zstd/lib/common/threading.c +74 -14
- data/ext/multi_compress/vendor/zstd/lib/common/threading.h +5 -18
- data/ext/multi_compress/vendor/zstd/lib/common/xxhash.c +5 -11
- data/ext/multi_compress/vendor/zstd/lib/common/xxhash.h +2411 -1003
- data/ext/multi_compress/vendor/zstd/lib/common/zstd_common.c +1 -36
- data/ext/multi_compress/vendor/zstd/lib/common/zstd_deps.h +13 -1
- data/ext/multi_compress/vendor/zstd/lib/common/zstd_internal.h +13 -182
- data/ext/multi_compress/vendor/zstd/lib/common/zstd_trace.h +6 -13
- data/ext/multi_compress/vendor/zstd/lib/compress/clevels.h +1 -1
- data/ext/multi_compress/vendor/zstd/lib/compress/fse_compress.c +15 -131
- data/ext/multi_compress/vendor/zstd/lib/compress/hist.c +11 -1
- data/ext/multi_compress/vendor/zstd/lib/compress/hist.h +8 -1
- data/ext/multi_compress/vendor/zstd/lib/compress/huf_compress.c +283 -189
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress.c +2419 -903
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_internal.h +423 -245
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_literals.c +116 -40
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_literals.h +16 -8
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_sequences.c +10 -10
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_sequences.h +8 -7
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_superblock.c +254 -139
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_superblock.h +1 -1
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_cwksp.h +184 -95
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_double_fast.c +163 -81
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_double_fast.h +18 -14
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_fast.c +507 -197
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_fast.h +7 -14
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_lazy.c +579 -484
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_lazy.h +133 -65
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_ldm.c +61 -40
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_ldm.h +7 -15
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_ldm_geartab.h +1 -1
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_opt.c +352 -218
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_opt.h +37 -21
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_preSplit.c +238 -0
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_preSplit.h +33 -0
- data/ext/multi_compress/vendor/zstd/lib/compress/zstdmt_compress.c +239 -175
- data/ext/multi_compress/vendor/zstd/lib/compress/zstdmt_compress.h +5 -16
- data/ext/multi_compress/vendor/zstd/lib/decompress/huf_decompress.c +543 -488
- data/ext/multi_compress/vendor/zstd/lib/decompress/huf_decompress_amd64.S +78 -61
- data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_ddict.c +4 -4
- data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_ddict.h +1 -1
- data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_decompress.c +295 -115
- data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_decompress_block.c +430 -293
- data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_decompress_block.h +7 -2
- data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_decompress_internal.h +11 -7
- data/ext/multi_compress/vendor/zstd/lib/deprecated/zbuff.h +1 -1
- data/ext/multi_compress/vendor/zstd/lib/deprecated/zbuff_common.c +1 -1
- data/ext/multi_compress/vendor/zstd/lib/deprecated/zbuff_compress.c +1 -1
- data/ext/multi_compress/vendor/zstd/lib/deprecated/zbuff_decompress.c +3 -1
- data/ext/multi_compress/vendor/zstd/lib/dictBuilder/cover.c +95 -46
- data/ext/multi_compress/vendor/zstd/lib/dictBuilder/cover.h +3 -9
- data/ext/multi_compress/vendor/zstd/lib/dictBuilder/divsufsort.h +0 -10
- data/ext/multi_compress/vendor/zstd/lib/dictBuilder/fastcover.c +4 -4
- data/ext/multi_compress/vendor/zstd/lib/dictBuilder/zdict.c +25 -97
- data/ext/multi_compress/vendor/zstd/lib/dll/example/Makefile +1 -1
- data/ext/multi_compress/vendor/zstd/lib/dll/example/README.md +1 -1
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_legacy.h +38 -1
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v01.c +19 -50
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v01.h +1 -1
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v02.c +27 -80
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v02.h +1 -1
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v03.c +28 -83
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v03.h +1 -1
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v04.c +25 -74
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v04.h +1 -1
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v05.c +31 -76
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v05.h +1 -1
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v06.c +44 -88
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v06.h +1 -1
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v07.c +33 -84
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v07.h +1 -1
- data/ext/multi_compress/vendor/zstd/lib/libzstd.mk +65 -33
- data/ext/multi_compress/vendor/zstd/lib/libzstd.pc.in +5 -5
- data/ext/multi_compress/vendor/zstd/lib/module.modulemap +13 -3
- data/ext/multi_compress/vendor/zstd/lib/zdict.h +65 -36
- data/ext/multi_compress/vendor/zstd/lib/zstd.h +890 -267
- data/ext/multi_compress/vendor/zstd/lib/zstd_errors.h +28 -16
- data/lib/multi_compress/version.rb +1 -1
- metadata +29 -2
|
@@ -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
|
|
@@ -7,28 +7,43 @@
|
|
|
7
7
|
* in the COPYING file in the root directory of this source tree).
|
|
8
8
|
* You may select, at your option, one of the above-listed licenses.
|
|
9
9
|
*/
|
|
10
|
-
#if defined (__cplusplus)
|
|
11
|
-
extern "C" {
|
|
12
|
-
#endif
|
|
13
10
|
|
|
14
11
|
#ifndef ZSTD_H_235446
|
|
15
12
|
#define ZSTD_H_235446
|
|
16
13
|
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
|
|
15
|
+
/* ====== Dependencies ======*/
|
|
19
16
|
#include <stddef.h> /* size_t */
|
|
20
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
|
|
21
26
|
|
|
22
27
|
/* ===== ZSTDLIB_API : control library symbols visibility ===== */
|
|
23
28
|
#ifndef ZSTDLIB_VISIBLE
|
|
24
|
-
|
|
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__)
|
|
25
33
|
# define ZSTDLIB_VISIBLE __attribute__ ((visibility ("default")))
|
|
26
|
-
# define ZSTDLIB_HIDDEN __attribute__ ((visibility ("hidden")))
|
|
27
34
|
# else
|
|
28
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
|
|
29
43
|
# define ZSTDLIB_HIDDEN
|
|
30
44
|
# endif
|
|
31
45
|
#endif
|
|
46
|
+
|
|
32
47
|
#if defined(ZSTD_DLL_EXPORT) && (ZSTD_DLL_EXPORT==1)
|
|
33
48
|
# define ZSTDLIB_API __declspec(dllexport) ZSTDLIB_VISIBLE
|
|
34
49
|
#elif defined(ZSTD_DLL_IMPORT) && (ZSTD_DLL_IMPORT==1)
|
|
@@ -37,6 +52,28 @@ extern "C" {
|
|
|
37
52
|
# define ZSTDLIB_API ZSTDLIB_VISIBLE
|
|
38
53
|
#endif
|
|
39
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
|
+
|
|
40
77
|
|
|
41
78
|
/*******************************************************************************
|
|
42
79
|
Introduction
|
|
@@ -74,7 +111,7 @@ extern "C" {
|
|
|
74
111
|
/*------ Version ------*/
|
|
75
112
|
#define ZSTD_VERSION_MAJOR 1
|
|
76
113
|
#define ZSTD_VERSION_MINOR 5
|
|
77
|
-
#define ZSTD_VERSION_RELEASE
|
|
114
|
+
#define ZSTD_VERSION_RELEASE 7
|
|
78
115
|
#define ZSTD_VERSION_NUMBER (ZSTD_VERSION_MAJOR *100*100 + ZSTD_VERSION_MINOR *100 + ZSTD_VERSION_RELEASE)
|
|
79
116
|
|
|
80
117
|
/*! ZSTD_versionNumber() :
|
|
@@ -112,11 +149,12 @@ ZSTDLIB_API const char* ZSTD_versionString(void);
|
|
|
112
149
|
|
|
113
150
|
|
|
114
151
|
/***************************************
|
|
115
|
-
* Simple API
|
|
152
|
+
* Simple Core API
|
|
116
153
|
***************************************/
|
|
117
154
|
/*! ZSTD_compress() :
|
|
118
155
|
* Compresses `src` content as a single zstd compressed frame into already allocated `dst`.
|
|
119
|
-
*
|
|
156
|
+
* NOTE: Providing `dstCapacity >= ZSTD_compressBound(srcSize)` guarantees that zstd will have
|
|
157
|
+
* enough space to successfully compress the data.
|
|
120
158
|
* @return : compressed size written into `dst` (<= `dstCapacity),
|
|
121
159
|
* or an error code if it fails (which can be tested using ZSTD_isError()). */
|
|
122
160
|
ZSTDLIB_API size_t ZSTD_compress( void* dst, size_t dstCapacity,
|
|
@@ -124,47 +162,55 @@ ZSTDLIB_API size_t ZSTD_compress( void* dst, size_t dstCapacity,
|
|
|
124
162
|
int compressionLevel);
|
|
125
163
|
|
|
126
164
|
/*! ZSTD_decompress() :
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
165
|
+
* `compressedSize` : must be the _exact_ size of some number of compressed and/or skippable frames.
|
|
166
|
+
* Multiple compressed frames can be decompressed at once with this method.
|
|
167
|
+
* The result will be the concatenation of all decompressed frames, back to back.
|
|
168
|
+
* `dstCapacity` is an upper bound of originalSize to regenerate.
|
|
169
|
+
* First frame's decompressed size can be extracted using ZSTD_getFrameContentSize().
|
|
170
|
+
* If maximum upper bound isn't known, prefer using streaming mode to decompress data.
|
|
171
|
+
* @return : the number of bytes decompressed into `dst` (<= `dstCapacity`),
|
|
172
|
+
* or an errorCode if it fails (which can be tested using ZSTD_isError()). */
|
|
132
173
|
ZSTDLIB_API size_t ZSTD_decompress( void* dst, size_t dstCapacity,
|
|
133
174
|
const void* src, size_t compressedSize);
|
|
134
175
|
|
|
176
|
+
|
|
177
|
+
/*====== Decompression helper functions ======*/
|
|
178
|
+
|
|
135
179
|
/*! ZSTD_getFrameContentSize() : requires v1.3.0+
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
180
|
+
* `src` should point to the start of a ZSTD encoded frame.
|
|
181
|
+
* `srcSize` must be at least as large as the frame header.
|
|
182
|
+
* hint : any size >= `ZSTD_frameHeaderSize_max` is large enough.
|
|
183
|
+
* @return : - decompressed size of `src` frame content, if known
|
|
184
|
+
* - ZSTD_CONTENTSIZE_UNKNOWN if the size cannot be determined
|
|
185
|
+
* - ZSTD_CONTENTSIZE_ERROR if an error occurred (e.g. invalid magic number, srcSize too small)
|
|
186
|
+
* note 1 : a 0 return value means the frame is valid but "empty".
|
|
187
|
+
* When invoking this method on a skippable frame, it will return 0.
|
|
188
|
+
* note 2 : decompressed size is an optional field, it may not be present (typically in streaming mode).
|
|
189
|
+
* When `return==ZSTD_CONTENTSIZE_UNKNOWN`, data to decompress could be any size.
|
|
190
|
+
* In which case, it's necessary to use streaming mode to decompress data.
|
|
191
|
+
* Optionally, application can rely on some implicit limit,
|
|
192
|
+
* as ZSTD_decompress() only needs an upper bound of decompressed size.
|
|
193
|
+
* (For example, data could be necessarily cut into blocks <= 16 KB).
|
|
194
|
+
* note 3 : decompressed size is always present when compression is completed using single-pass functions,
|
|
195
|
+
* such as ZSTD_compress(), ZSTD_compressCCtx() ZSTD_compress_usingDict() or ZSTD_compress_usingCDict().
|
|
196
|
+
* note 4 : decompressed size can be very large (64-bits value),
|
|
197
|
+
* potentially larger than what local system can handle as a single memory segment.
|
|
198
|
+
* In which case, it's necessary to use streaming mode to decompress data.
|
|
199
|
+
* note 5 : If source is untrusted, decompressed size could be wrong or intentionally modified.
|
|
200
|
+
* Always ensure return value fits within application's authorized limits.
|
|
201
|
+
* Each application can set its own limits.
|
|
202
|
+
* note 6 : This function replaces ZSTD_getDecompressedSize() */
|
|
158
203
|
#define ZSTD_CONTENTSIZE_UNKNOWN (0ULL - 1)
|
|
159
204
|
#define ZSTD_CONTENTSIZE_ERROR (0ULL - 2)
|
|
160
205
|
ZSTDLIB_API unsigned long long ZSTD_getFrameContentSize(const void *src, size_t srcSize);
|
|
161
206
|
|
|
162
|
-
/*! ZSTD_getDecompressedSize() :
|
|
163
|
-
*
|
|
207
|
+
/*! ZSTD_getDecompressedSize() (obsolete):
|
|
208
|
+
* This function is now obsolete, in favor of ZSTD_getFrameContentSize().
|
|
164
209
|
* Both functions work the same way, but ZSTD_getDecompressedSize() blends
|
|
165
210
|
* "empty", "unknown" and "error" results to the same return value (0),
|
|
166
211
|
* while ZSTD_getFrameContentSize() gives them separate return values.
|
|
167
212
|
* @return : decompressed size of `src` frame content _if known and not empty_, 0 otherwise. */
|
|
213
|
+
ZSTD_DEPRECATED("Replaced by ZSTD_getFrameContentSize")
|
|
168
214
|
ZSTDLIB_API unsigned long long ZSTD_getDecompressedSize(const void* src, size_t srcSize);
|
|
169
215
|
|
|
170
216
|
/*! ZSTD_findFrameCompressedSize() : Requires v1.4.0+
|
|
@@ -172,18 +218,50 @@ ZSTDLIB_API unsigned long long ZSTD_getDecompressedSize(const void* src, size_t
|
|
|
172
218
|
* `srcSize` must be >= first frame size
|
|
173
219
|
* @return : the compressed size of the first frame starting at `src`,
|
|
174
220
|
* suitable to pass as `srcSize` to `ZSTD_decompress` or similar,
|
|
175
|
-
*
|
|
221
|
+
* or an error code if input is invalid
|
|
222
|
+
* Note 1: this method is called _find*() because it's not enough to read the header,
|
|
223
|
+
* it may have to scan through the frame's content, to reach its end.
|
|
224
|
+
* Note 2: this method also works with Skippable Frames. In which case,
|
|
225
|
+
* it returns the size of the complete skippable frame,
|
|
226
|
+
* which is always equal to its content size + 8 bytes for headers. */
|
|
176
227
|
ZSTDLIB_API size_t ZSTD_findFrameCompressedSize(const void* src, size_t srcSize);
|
|
177
228
|
|
|
178
229
|
|
|
179
|
-
/*======
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
230
|
+
/*====== Compression helper functions ======*/
|
|
231
|
+
|
|
232
|
+
/*! ZSTD_compressBound() :
|
|
233
|
+
* maximum compressed size in worst case single-pass scenario.
|
|
234
|
+
* When invoking `ZSTD_compress()`, or any other one-pass compression function,
|
|
235
|
+
* it's recommended to provide @dstCapacity >= ZSTD_compressBound(srcSize)
|
|
236
|
+
* as it eliminates one potential failure scenario,
|
|
237
|
+
* aka not enough room in dst buffer to write the compressed frame.
|
|
238
|
+
* Note : ZSTD_compressBound() itself can fail, if @srcSize >= ZSTD_MAX_INPUT_SIZE .
|
|
239
|
+
* In which case, ZSTD_compressBound() will return an error code
|
|
240
|
+
* which can be tested using ZSTD_isError().
|
|
241
|
+
*
|
|
242
|
+
* ZSTD_COMPRESSBOUND() :
|
|
243
|
+
* same as ZSTD_compressBound(), but as a macro.
|
|
244
|
+
* It can be used to produce constants, which can be useful for static allocation,
|
|
245
|
+
* for example to size a static array on stack.
|
|
246
|
+
* Will produce constant value 0 if srcSize is too large.
|
|
247
|
+
*/
|
|
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); /*!< maximum compressed size in worst case single-pass scenario */
|
|
251
|
+
|
|
252
|
+
|
|
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); /*!< tells if a `size_t` function result is an error code */
|
|
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); /*!< provides readable string from a function result */
|
|
262
|
+
ZSTDLIB_API int ZSTD_minCLevel(void); /*!< minimum negative compression level allowed, requires v1.4.0+ */
|
|
263
|
+
ZSTDLIB_API int ZSTD_maxCLevel(void); /*!< maximum compression level available */
|
|
264
|
+
ZSTDLIB_API int ZSTD_defaultCLevel(void); /*!< default compression level, specified by ZSTD_CLEVEL_DEFAULT, requires v1.5.0+ */
|
|
187
265
|
|
|
188
266
|
|
|
189
267
|
/***************************************
|
|
@@ -191,25 +269,25 @@ ZSTDLIB_API int ZSTD_defaultCLevel(void); /*!< default compres
|
|
|
191
269
|
***************************************/
|
|
192
270
|
/*= Compression context
|
|
193
271
|
* When compressing many times,
|
|
194
|
-
* it is recommended to allocate a context just once,
|
|
195
|
-
* and
|
|
196
|
-
* This will make workload
|
|
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.
|
|
197
275
|
* Note : re-using context is just a speed / resource optimization.
|
|
198
276
|
* It doesn't change the compression ratio, which remains identical.
|
|
199
|
-
* Note 2
|
|
200
|
-
* use one different context per thread
|
|
277
|
+
* Note 2: For parallel execution in multi-threaded environments,
|
|
278
|
+
* use one different context per thread .
|
|
201
279
|
*/
|
|
202
280
|
typedef struct ZSTD_CCtx_s ZSTD_CCtx;
|
|
203
281
|
ZSTDLIB_API ZSTD_CCtx* ZSTD_createCCtx(void);
|
|
204
|
-
ZSTDLIB_API size_t ZSTD_freeCCtx(ZSTD_CCtx* cctx); /*
|
|
282
|
+
ZSTDLIB_API size_t ZSTD_freeCCtx(ZSTD_CCtx* cctx); /* compatible with NULL pointer */
|
|
205
283
|
|
|
206
284
|
/*! ZSTD_compressCCtx() :
|
|
207
285
|
* Same as ZSTD_compress(), using an explicit ZSTD_CCtx.
|
|
208
|
-
* Important : in order to
|
|
209
|
-
* this function compresses at requested compression level,
|
|
210
|
-
* __ignoring any other parameter__ .
|
|
286
|
+
* Important : in order to mirror `ZSTD_compress()` behavior,
|
|
287
|
+
* this function compresses at the requested compression level,
|
|
288
|
+
* __ignoring any other advanced parameter__ .
|
|
211
289
|
* If any advanced parameter was set using the advanced API,
|
|
212
|
-
* they will all be reset. Only
|
|
290
|
+
* they will all be reset. Only @compressionLevel remains.
|
|
213
291
|
*/
|
|
214
292
|
ZSTDLIB_API size_t ZSTD_compressCCtx(ZSTD_CCtx* cctx,
|
|
215
293
|
void* dst, size_t dstCapacity,
|
|
@@ -219,7 +297,7 @@ ZSTDLIB_API size_t ZSTD_compressCCtx(ZSTD_CCtx* cctx,
|
|
|
219
297
|
/*= Decompression context
|
|
220
298
|
* When decompressing many times,
|
|
221
299
|
* it is recommended to allocate a context only once,
|
|
222
|
-
* and
|
|
300
|
+
* and reuse it for each successive compression operation.
|
|
223
301
|
* This will make workload friendlier for system's memory.
|
|
224
302
|
* Use one context per thread for parallel execution. */
|
|
225
303
|
typedef struct ZSTD_DCtx_s ZSTD_DCtx;
|
|
@@ -229,7 +307,7 @@ ZSTDLIB_API size_t ZSTD_freeDCtx(ZSTD_DCtx* dctx); /* accept NULL pointer *
|
|
|
229
307
|
/*! ZSTD_decompressDCtx() :
|
|
230
308
|
* Same as ZSTD_decompress(),
|
|
231
309
|
* requires an allocated ZSTD_DCtx.
|
|
232
|
-
* Compatible with sticky parameters.
|
|
310
|
+
* Compatible with sticky parameters (see below).
|
|
233
311
|
*/
|
|
234
312
|
ZSTDLIB_API size_t ZSTD_decompressDCtx(ZSTD_DCtx* dctx,
|
|
235
313
|
void* dst, size_t dstCapacity,
|
|
@@ -245,12 +323,12 @@ ZSTDLIB_API size_t ZSTD_decompressDCtx(ZSTD_DCtx* dctx,
|
|
|
245
323
|
* using ZSTD_CCtx_set*() functions.
|
|
246
324
|
* Pushed parameters are sticky : they are valid for next compressed frame, and any subsequent frame.
|
|
247
325
|
* "sticky" parameters are applicable to `ZSTD_compress2()` and `ZSTD_compressStream*()` !
|
|
248
|
-
* __They do not apply to
|
|
326
|
+
* __They do not apply to one-shot variants such as ZSTD_compressCCtx()__ .
|
|
249
327
|
*
|
|
250
328
|
* It's possible to reset all parameters to "default" using ZSTD_CCtx_reset().
|
|
251
329
|
*
|
|
252
330
|
* This API supersedes all other "advanced" API entry points in the experimental section.
|
|
253
|
-
* In the future, we expect to remove
|
|
331
|
+
* In the future, we expect to remove API entry points from experimental which are redundant with this API.
|
|
254
332
|
*/
|
|
255
333
|
|
|
256
334
|
|
|
@@ -333,6 +411,19 @@ typedef enum {
|
|
|
333
411
|
* The higher the value of selected strategy, the more complex it is,
|
|
334
412
|
* resulting in stronger and slower compression.
|
|
335
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
|
+
*/
|
|
336
427
|
/* LDM mode parameters */
|
|
337
428
|
ZSTD_c_enableLongDistanceMatching=160, /* Enable long distance matching.
|
|
338
429
|
* This parameter is designed to improve compression ratio
|
|
@@ -412,15 +503,18 @@ typedef enum {
|
|
|
412
503
|
* ZSTD_c_forceMaxWindow
|
|
413
504
|
* ZSTD_c_forceAttachDict
|
|
414
505
|
* ZSTD_c_literalCompressionMode
|
|
415
|
-
* ZSTD_c_targetCBlockSize
|
|
416
506
|
* ZSTD_c_srcSizeHint
|
|
417
507
|
* ZSTD_c_enableDedicatedDictSearch
|
|
418
508
|
* ZSTD_c_stableInBuffer
|
|
419
509
|
* ZSTD_c_stableOutBuffer
|
|
420
510
|
* ZSTD_c_blockDelimiters
|
|
421
511
|
* ZSTD_c_validateSequences
|
|
422
|
-
*
|
|
512
|
+
* ZSTD_c_blockSplitterLevel
|
|
513
|
+
* ZSTD_c_splitAfterSequences
|
|
423
514
|
* ZSTD_c_useRowMatchFinder
|
|
515
|
+
* ZSTD_c_prefetchCDictTables
|
|
516
|
+
* ZSTD_c_enableSeqProducerFallback
|
|
517
|
+
* ZSTD_c_maxBlockSize
|
|
424
518
|
* Because they are not stable, it's necessary to define ZSTD_STATIC_LINKING_ONLY to access them.
|
|
425
519
|
* note : never ever use experimentalParam? names directly;
|
|
426
520
|
* also, the enums values themselves are unstable and can still change.
|
|
@@ -430,7 +524,7 @@ typedef enum {
|
|
|
430
524
|
ZSTD_c_experimentalParam3=1000,
|
|
431
525
|
ZSTD_c_experimentalParam4=1001,
|
|
432
526
|
ZSTD_c_experimentalParam5=1002,
|
|
433
|
-
ZSTD_c_experimentalParam6=1003
|
|
527
|
+
/* was ZSTD_c_experimentalParam6=1003; is now ZSTD_c_targetCBlockSize */
|
|
434
528
|
ZSTD_c_experimentalParam7=1004,
|
|
435
529
|
ZSTD_c_experimentalParam8=1005,
|
|
436
530
|
ZSTD_c_experimentalParam9=1006,
|
|
@@ -439,7 +533,12 @@ typedef enum {
|
|
|
439
533
|
ZSTD_c_experimentalParam12=1009,
|
|
440
534
|
ZSTD_c_experimentalParam13=1010,
|
|
441
535
|
ZSTD_c_experimentalParam14=1011,
|
|
442
|
-
ZSTD_c_experimentalParam15=1012
|
|
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
|
|
443
542
|
} ZSTD_cParameter;
|
|
444
543
|
|
|
445
544
|
typedef struct {
|
|
@@ -502,7 +601,7 @@ typedef enum {
|
|
|
502
601
|
* They will be used to compress next frame.
|
|
503
602
|
* Resetting session never fails.
|
|
504
603
|
* - The parameters : changes all parameters back to "default".
|
|
505
|
-
* This removes any reference to any dictionary
|
|
604
|
+
* This also removes any reference to any dictionary or external sequence producer.
|
|
506
605
|
* Parameters can only be changed between 2 sessions (i.e. no compression is currently ongoing)
|
|
507
606
|
* otherwise the reset fails, and function returns an error value (which can be tested using ZSTD_isError())
|
|
508
607
|
* - Both : similar to resetting the session, followed by resetting parameters.
|
|
@@ -511,11 +610,13 @@ ZSTDLIB_API size_t ZSTD_CCtx_reset(ZSTD_CCtx* cctx, ZSTD_ResetDirective reset);
|
|
|
511
610
|
|
|
512
611
|
/*! ZSTD_compress2() :
|
|
513
612
|
* Behave the same as ZSTD_compressCCtx(), but compression parameters are set using the advanced API.
|
|
613
|
+
* (note that this entry point doesn't even expose a compression level parameter).
|
|
514
614
|
* ZSTD_compress2() always starts a new frame.
|
|
515
615
|
* Should cctx hold data from a previously unfinished frame, everything about it is forgotten.
|
|
516
616
|
* - Compression parameters are pushed into CCtx before starting compression, using ZSTD_CCtx_set*()
|
|
517
617
|
* - The function is always blocking, returns when compression is completed.
|
|
518
|
-
*
|
|
618
|
+
* NOTE: Providing `dstCapacity >= ZSTD_compressBound(srcSize)` guarantees that zstd will have
|
|
619
|
+
* enough space to successfully compress the data, though it is possible it fails for other reasons.
|
|
519
620
|
* @return : compressed size written into `dst` (<= `dstCapacity),
|
|
520
621
|
* or an error code if it fails (which can be tested using ZSTD_isError()).
|
|
521
622
|
*/
|
|
@@ -552,13 +653,17 @@ typedef enum {
|
|
|
552
653
|
* ZSTD_d_stableOutBuffer
|
|
553
654
|
* ZSTD_d_forceIgnoreChecksum
|
|
554
655
|
* ZSTD_d_refMultipleDDicts
|
|
656
|
+
* ZSTD_d_disableHuffmanAssembly
|
|
657
|
+
* ZSTD_d_maxBlockSize
|
|
555
658
|
* Because they are not stable, it's necessary to define ZSTD_STATIC_LINKING_ONLY to access them.
|
|
556
659
|
* note : never ever use experimentalParam? names directly
|
|
557
660
|
*/
|
|
558
661
|
ZSTD_d_experimentalParam1=1000,
|
|
559
662
|
ZSTD_d_experimentalParam2=1001,
|
|
560
663
|
ZSTD_d_experimentalParam3=1002,
|
|
561
|
-
ZSTD_d_experimentalParam4=1003
|
|
664
|
+
ZSTD_d_experimentalParam4=1003,
|
|
665
|
+
ZSTD_d_experimentalParam5=1004,
|
|
666
|
+
ZSTD_d_experimentalParam6=1005
|
|
562
667
|
|
|
563
668
|
} ZSTD_dParameter;
|
|
564
669
|
|
|
@@ -613,14 +718,14 @@ typedef struct ZSTD_outBuffer_s {
|
|
|
613
718
|
* A ZSTD_CStream object is required to track streaming operation.
|
|
614
719
|
* Use ZSTD_createCStream() and ZSTD_freeCStream() to create/release resources.
|
|
615
720
|
* ZSTD_CStream objects can be reused multiple times on consecutive compression operations.
|
|
616
|
-
* It is recommended to
|
|
721
|
+
* It is recommended to reuse ZSTD_CStream since it will play nicer with system's memory, by re-using already allocated memory.
|
|
617
722
|
*
|
|
618
723
|
* For parallel execution, use one separate ZSTD_CStream per thread.
|
|
619
724
|
*
|
|
620
725
|
* note : since v1.3.0, ZSTD_CStream and ZSTD_CCtx are the same thing.
|
|
621
726
|
*
|
|
622
727
|
* Parameters are sticky : when starting a new compression on the same context,
|
|
623
|
-
* it will
|
|
728
|
+
* it will reuse the same sticky parameters as previous compression session.
|
|
624
729
|
* When in doubt, it's recommended to fully initialize the context before usage.
|
|
625
730
|
* Use ZSTD_CCtx_reset() to reset the context and ZSTD_CCtx_setParameter(),
|
|
626
731
|
* ZSTD_CCtx_setPledgedSrcSize(), or ZSTD_CCtx_loadDictionary() and friends to
|
|
@@ -709,6 +814,11 @@ typedef enum {
|
|
|
709
814
|
* only ZSTD_e_end or ZSTD_e_flush operations are allowed.
|
|
710
815
|
* Before starting a new compression job, or changing compression parameters,
|
|
711
816
|
* it is required to fully flush internal buffers.
|
|
817
|
+
* - note: if an operation ends with an error, it may leave @cctx in an undefined state.
|
|
818
|
+
* Therefore, it's UB to invoke ZSTD_compressStream2() of ZSTD_compressStream() on such a state.
|
|
819
|
+
* In order to be re-employed after an error, a state must be reset,
|
|
820
|
+
* which can be done explicitly (ZSTD_CCtx_reset()),
|
|
821
|
+
* or is sometimes implied by methods starting a new compression job (ZSTD_initCStream(), ZSTD_compressCCtx())
|
|
712
822
|
*/
|
|
713
823
|
ZSTDLIB_API size_t ZSTD_compressStream2( ZSTD_CCtx* cctx,
|
|
714
824
|
ZSTD_outBuffer* output,
|
|
@@ -737,8 +847,6 @@ ZSTDLIB_API size_t ZSTD_CStreamOutSize(void); /**< recommended size for output
|
|
|
737
847
|
* This following is a legacy streaming API, available since v1.0+ .
|
|
738
848
|
* It can be replaced by ZSTD_CCtx_reset() and ZSTD_compressStream2().
|
|
739
849
|
* 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
850
|
******************************************************************************/
|
|
743
851
|
|
|
744
852
|
/*!
|
|
@@ -747,6 +855,9 @@ ZSTDLIB_API size_t ZSTD_CStreamOutSize(void); /**< recommended size for output
|
|
|
747
855
|
* ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
|
|
748
856
|
* ZSTD_CCtx_refCDict(zcs, NULL); // clear the dictionary (if any)
|
|
749
857
|
* ZSTD_CCtx_setParameter(zcs, ZSTD_c_compressionLevel, compressionLevel);
|
|
858
|
+
*
|
|
859
|
+
* Note that ZSTD_initCStream() clears any previously set dictionary. Use the new API
|
|
860
|
+
* to compress with a dictionary.
|
|
750
861
|
*/
|
|
751
862
|
ZSTDLIB_API size_t ZSTD_initCStream(ZSTD_CStream* zcs, int compressionLevel);
|
|
752
863
|
/*!
|
|
@@ -767,7 +878,7 @@ ZSTDLIB_API size_t ZSTD_endStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output);
|
|
|
767
878
|
*
|
|
768
879
|
* A ZSTD_DStream object is required to track streaming operations.
|
|
769
880
|
* Use ZSTD_createDStream() and ZSTD_freeDStream() to create/release resources.
|
|
770
|
-
* ZSTD_DStream objects can be re-
|
|
881
|
+
* ZSTD_DStream objects can be re-employed multiple times.
|
|
771
882
|
*
|
|
772
883
|
* Use ZSTD_initDStream() to start a new decompression operation.
|
|
773
884
|
* @return : recommended first input size
|
|
@@ -777,16 +888,21 @@ ZSTDLIB_API size_t ZSTD_endStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output);
|
|
|
777
888
|
* The function will update both `pos` fields.
|
|
778
889
|
* If `input.pos < input.size`, some input has not been consumed.
|
|
779
890
|
* It's up to the caller to present again remaining data.
|
|
891
|
+
*
|
|
780
892
|
* The function tries to flush all data decoded immediately, respecting output buffer size.
|
|
781
893
|
* If `output.pos < output.size`, decoder has flushed everything it could.
|
|
782
|
-
*
|
|
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).
|
|
783
899
|
* In which case, call ZSTD_decompressStream() again to flush whatever remains in the buffer.
|
|
784
900
|
* Note : with no additional input provided, amount of data flushed is necessarily <= ZSTD_BLOCKSIZE_MAX.
|
|
785
901
|
* @return : 0 when a frame is completely decoded and fully flushed,
|
|
786
902
|
* or an error code, which can be tested using ZSTD_isError(),
|
|
787
903
|
* or any other value > 0, which means there is still some decoding or flushing to do to complete current frame :
|
|
788
904
|
* the return value is a suggested next input size (just a hint for better latency)
|
|
789
|
-
* that will never request more than the remaining frame
|
|
905
|
+
* that will never request more than the remaining content of the compressed frame.
|
|
790
906
|
* *******************************************************************************/
|
|
791
907
|
|
|
792
908
|
typedef ZSTD_DCtx ZSTD_DStream; /**< DCtx and DStream are now effectively same object (>= v1.3.0) */
|
|
@@ -797,13 +913,38 @@ ZSTDLIB_API size_t ZSTD_freeDStream(ZSTD_DStream* zds); /* accept NULL pointer
|
|
|
797
913
|
|
|
798
914
|
/*===== Streaming decompression functions =====*/
|
|
799
915
|
|
|
800
|
-
|
|
916
|
+
/*! ZSTD_initDStream() :
|
|
917
|
+
* Initialize/reset DStream state for new decompression operation.
|
|
918
|
+
* Call before new decompression operation using same DStream.
|
|
801
919
|
*
|
|
920
|
+
* Note : This function is redundant with the advanced API and equivalent to:
|
|
802
921
|
* ZSTD_DCtx_reset(zds, ZSTD_reset_session_only);
|
|
803
922
|
* ZSTD_DCtx_refDDict(zds, NULL);
|
|
804
923
|
*/
|
|
805
924
|
ZSTDLIB_API size_t ZSTD_initDStream(ZSTD_DStream* zds);
|
|
806
925
|
|
|
926
|
+
/*! ZSTD_decompressStream() :
|
|
927
|
+
* Streaming decompression function.
|
|
928
|
+
* Call repetitively to consume full input updating it as necessary.
|
|
929
|
+
* Function will update both input and output `pos` fields exposing current state via these fields:
|
|
930
|
+
* - `input.pos < input.size`, some input remaining and caller should provide remaining input
|
|
931
|
+
* on the next call.
|
|
932
|
+
* - `output.pos < output.size`, decoder flushed internal output buffer.
|
|
933
|
+
* - `output.pos == output.size`, unflushed data potentially present in the internal buffers,
|
|
934
|
+
* check ZSTD_decompressStream() @return value,
|
|
935
|
+
* if > 0, invoke it again to flush remaining data to output.
|
|
936
|
+
* Note : with no additional input, amount of data flushed <= ZSTD_BLOCKSIZE_MAX.
|
|
937
|
+
*
|
|
938
|
+
* @return : 0 when a frame is completely decoded and fully flushed,
|
|
939
|
+
* or an error code, which can be tested using ZSTD_isError(),
|
|
940
|
+
* or any other value > 0, which means there is some decoding or flushing to do to complete current frame.
|
|
941
|
+
*
|
|
942
|
+
* Note: when an operation returns with an error code, the @zds state may be left in undefined state.
|
|
943
|
+
* It's UB to invoke `ZSTD_decompressStream()` on such a state.
|
|
944
|
+
* In order to re-use such a state, it must be first reset,
|
|
945
|
+
* which can be done explicitly (`ZSTD_DCtx_reset()`),
|
|
946
|
+
* or is implied for operations starting some new decompression job (`ZSTD_initDStream`, `ZSTD_decompressDCtx()`, `ZSTD_decompress_usingDict()`)
|
|
947
|
+
*/
|
|
807
948
|
ZSTDLIB_API size_t ZSTD_decompressStream(ZSTD_DStream* zds, ZSTD_outBuffer* output, ZSTD_inBuffer* input);
|
|
808
949
|
|
|
809
950
|
ZSTDLIB_API size_t ZSTD_DStreamInSize(void); /*!< recommended size for input buffer */
|
|
@@ -922,7 +1063,7 @@ ZSTDLIB_API unsigned ZSTD_getDictID_fromDDict(const ZSTD_DDict* ddict);
|
|
|
922
1063
|
* If @return == 0, the dictID could not be decoded.
|
|
923
1064
|
* This could for one of the following reasons :
|
|
924
1065
|
* - 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.
|
|
1066
|
+
* - The frame was built with dictID intentionally removed. Whatever dictionary is necessary is a hidden piece of information.
|
|
926
1067
|
* Note : this use case also happens when using a non-conformant dictionary.
|
|
927
1068
|
* - `srcSize` is too small, and as a result, the frame header could not be decoded (only possible if `srcSize < ZSTD_FRAMEHEADERSIZE_MAX`).
|
|
928
1069
|
* - This is not a Zstandard frame.
|
|
@@ -934,9 +1075,11 @@ ZSTDLIB_API unsigned ZSTD_getDictID_fromFrame(const void* src, size_t srcSize);
|
|
|
934
1075
|
* Advanced dictionary and prefix API (Requires v1.4.0+)
|
|
935
1076
|
*
|
|
936
1077
|
* This API allows dictionaries to be used with ZSTD_compress2(),
|
|
937
|
-
* ZSTD_compressStream2(), and ZSTD_decompressDCtx().
|
|
938
|
-
*
|
|
939
|
-
*
|
|
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.
|
|
940
1083
|
******************************************************************************/
|
|
941
1084
|
|
|
942
1085
|
|
|
@@ -946,8 +1089,9 @@ ZSTDLIB_API unsigned ZSTD_getDictID_fromFrame(const void* src, size_t srcSize);
|
|
|
946
1089
|
* @result : 0, or an error code (which can be tested with ZSTD_isError()).
|
|
947
1090
|
* Special: Loading a NULL (or 0-size) dictionary invalidates previous dictionary,
|
|
948
1091
|
* meaning "return to no-dictionary mode".
|
|
949
|
-
* Note 1 : Dictionary is sticky, it will be used for all future compressed frames
|
|
950
|
-
*
|
|
1092
|
+
* Note 1 : Dictionary is sticky, it will be used for all future compressed frames,
|
|
1093
|
+
* until parameters are reset, a new dictionary is loaded, or the dictionary
|
|
1094
|
+
* is explicitly invalidated by loading a NULL dictionary.
|
|
951
1095
|
* Note 2 : Loading a dictionary involves building tables.
|
|
952
1096
|
* It's also a CPU consuming operation, with non-negligible impact on latency.
|
|
953
1097
|
* Tables are dependent on compression parameters, and for this reason,
|
|
@@ -956,11 +1100,15 @@ ZSTDLIB_API unsigned ZSTD_getDictID_fromFrame(const void* src, size_t srcSize);
|
|
|
956
1100
|
* Use experimental ZSTD_CCtx_loadDictionary_byReference() to reference content instead.
|
|
957
1101
|
* In such a case, dictionary buffer must outlive its users.
|
|
958
1102
|
* Note 4 : Use ZSTD_CCtx_loadDictionary_advanced()
|
|
959
|
-
* to precisely select how dictionary content must be interpreted.
|
|
1103
|
+
* to precisely select how dictionary content must be interpreted.
|
|
1104
|
+
* Note 5 : This method does not benefit from LDM (long distance mode).
|
|
1105
|
+
* If you want to employ LDM on some large dictionary content,
|
|
1106
|
+
* prefer employing ZSTD_CCtx_refPrefix() described below.
|
|
1107
|
+
*/
|
|
960
1108
|
ZSTDLIB_API size_t ZSTD_CCtx_loadDictionary(ZSTD_CCtx* cctx, const void* dict, size_t dictSize);
|
|
961
1109
|
|
|
962
1110
|
/*! ZSTD_CCtx_refCDict() : Requires v1.4.0+
|
|
963
|
-
* Reference a prepared dictionary, to be used for all
|
|
1111
|
+
* Reference a prepared dictionary, to be used for all future compressed frames.
|
|
964
1112
|
* Note that compression parameters are enforced from within CDict,
|
|
965
1113
|
* and supersede any compression parameter previously set within CCtx.
|
|
966
1114
|
* The parameters ignored are labelled as "superseded-by-cdict" in the ZSTD_cParameter enum docs.
|
|
@@ -979,6 +1127,7 @@ ZSTDLIB_API size_t ZSTD_CCtx_refCDict(ZSTD_CCtx* cctx, const ZSTD_CDict* cdict);
|
|
|
979
1127
|
* Decompression will need same prefix to properly regenerate data.
|
|
980
1128
|
* Compressing with a prefix is similar in outcome as performing a diff and compressing it,
|
|
981
1129
|
* but performs much faster, especially during decompression (compression speed is tunable with compression level).
|
|
1130
|
+
* This method is compatible with LDM (long distance mode).
|
|
982
1131
|
* @result : 0, or an error code (which can be tested with ZSTD_isError()).
|
|
983
1132
|
* Special: Adding any prefix (including NULL) invalidates any previous prefix or dictionary
|
|
984
1133
|
* Note 1 : Prefix buffer is referenced. It **must** outlive compression.
|
|
@@ -995,9 +1144,9 @@ ZSTDLIB_API size_t ZSTD_CCtx_refPrefix(ZSTD_CCtx* cctx,
|
|
|
995
1144
|
const void* prefix, size_t prefixSize);
|
|
996
1145
|
|
|
997
1146
|
/*! ZSTD_DCtx_loadDictionary() : Requires v1.4.0+
|
|
998
|
-
* Create an internal DDict from dict buffer,
|
|
999
|
-
*
|
|
1000
|
-
*
|
|
1147
|
+
* Create an internal DDict from dict buffer, to be used to decompress all future frames.
|
|
1148
|
+
* The dictionary remains valid for all future frames, until explicitly invalidated, or
|
|
1149
|
+
* a new dictionary is loaded.
|
|
1001
1150
|
* @result : 0, or an error code (which can be tested with ZSTD_isError()).
|
|
1002
1151
|
* Special : Adding a NULL (or 0-size) dictionary invalidates any previous dictionary,
|
|
1003
1152
|
* meaning "return to no-dictionary mode".
|
|
@@ -1021,9 +1170,10 @@ ZSTDLIB_API size_t ZSTD_DCtx_loadDictionary(ZSTD_DCtx* dctx, const void* dict, s
|
|
|
1021
1170
|
* The memory for the table is allocated on the first call to refDDict, and can be
|
|
1022
1171
|
* freed with ZSTD_freeDCtx().
|
|
1023
1172
|
*
|
|
1173
|
+
* If called with ZSTD_d_refMultipleDDicts disabled (the default), only one dictionary
|
|
1174
|
+
* will be managed, and referencing a dictionary effectively "discards" any previous one.
|
|
1175
|
+
*
|
|
1024
1176
|
* @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
1177
|
* Special: referencing a NULL DDict means "return to no-dictionary mode".
|
|
1028
1178
|
* Note 2 : DDict is just referenced, its lifetime must outlive its usage from DCtx.
|
|
1029
1179
|
*/
|
|
@@ -1060,6 +1210,10 @@ ZSTDLIB_API size_t ZSTD_sizeof_DStream(const ZSTD_DStream* zds);
|
|
|
1060
1210
|
ZSTDLIB_API size_t ZSTD_sizeof_CDict(const ZSTD_CDict* cdict);
|
|
1061
1211
|
ZSTDLIB_API size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict);
|
|
1062
1212
|
|
|
1213
|
+
#if defined (__cplusplus)
|
|
1214
|
+
}
|
|
1215
|
+
#endif
|
|
1216
|
+
|
|
1063
1217
|
#endif /* ZSTD_H_235446 */
|
|
1064
1218
|
|
|
1065
1219
|
|
|
@@ -1075,6 +1229,10 @@ ZSTDLIB_API size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict);
|
|
|
1075
1229
|
#if defined(ZSTD_STATIC_LINKING_ONLY) && !defined(ZSTD_H_ZSTD_STATIC_LINKING_ONLY)
|
|
1076
1230
|
#define ZSTD_H_ZSTD_STATIC_LINKING_ONLY
|
|
1077
1231
|
|
|
1232
|
+
#if defined (__cplusplus)
|
|
1233
|
+
extern "C" {
|
|
1234
|
+
#endif
|
|
1235
|
+
|
|
1078
1236
|
/* This can be overridden externally to hide static symbols. */
|
|
1079
1237
|
#ifndef ZSTDLIB_STATIC_API
|
|
1080
1238
|
# if defined(ZSTD_DLL_EXPORT) && (ZSTD_DLL_EXPORT==1)
|
|
@@ -1086,28 +1244,6 @@ ZSTDLIB_API size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict);
|
|
|
1086
1244
|
# endif
|
|
1087
1245
|
#endif
|
|
1088
1246
|
|
|
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
1247
|
/****************************************************************************************
|
|
1112
1248
|
* experimental API (static linking only)
|
|
1113
1249
|
****************************************************************************************
|
|
@@ -1142,6 +1278,7 @@ ZSTDLIB_API size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict);
|
|
|
1142
1278
|
#define ZSTD_TARGETLENGTH_MIN 0 /* note : comparing this constant to an unsigned results in a tautological test */
|
|
1143
1279
|
#define ZSTD_STRATEGY_MIN ZSTD_fast
|
|
1144
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. */
|
|
1145
1282
|
|
|
1146
1283
|
|
|
1147
1284
|
#define ZSTD_OVERLAPLOG_MIN 0
|
|
@@ -1165,7 +1302,7 @@ ZSTDLIB_API size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict);
|
|
|
1165
1302
|
#define ZSTD_LDM_HASHRATELOG_MAX (ZSTD_WINDOWLOG_MAX - ZSTD_HASHLOG_MIN)
|
|
1166
1303
|
|
|
1167
1304
|
/* Advanced parameter bounds */
|
|
1168
|
-
#define ZSTD_TARGETCBLOCKSIZE_MIN
|
|
1305
|
+
#define ZSTD_TARGETCBLOCKSIZE_MIN 1340 /* suitable to fit into an ethernet / wifi / 4G transport frame */
|
|
1169
1306
|
#define ZSTD_TARGETCBLOCKSIZE_MAX ZSTD_BLOCKSIZE_MAX
|
|
1170
1307
|
#define ZSTD_SRCSIZEHINT_MIN 0
|
|
1171
1308
|
#define ZSTD_SRCSIZEHINT_MAX INT_MAX
|
|
@@ -1207,7 +1344,7 @@ typedef struct {
|
|
|
1207
1344
|
*
|
|
1208
1345
|
* Note: This field is optional. ZSTD_generateSequences() will calculate the value of
|
|
1209
1346
|
* 'rep', but repeat offsets do not necessarily need to be calculated from an external
|
|
1210
|
-
* sequence provider
|
|
1347
|
+
* sequence provider perspective. For example, ZSTD_compressSequences() does not
|
|
1211
1348
|
* use this 'rep' field at all (as of now).
|
|
1212
1349
|
*/
|
|
1213
1350
|
} ZSTD_Sequence;
|
|
@@ -1312,17 +1449,18 @@ typedef enum {
|
|
|
1312
1449
|
} ZSTD_literalCompressionMode_e;
|
|
1313
1450
|
|
|
1314
1451
|
typedef enum {
|
|
1315
|
-
/* Note: This enum controls features which are conditionally beneficial.
|
|
1316
|
-
* decision on whether or not to enable the feature (ZSTD_ps_auto),
|
|
1317
|
-
*
|
|
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.
|
|
1318
1455
|
*/
|
|
1319
1456
|
ZSTD_ps_auto = 0, /* Let the library automatically determine whether the feature shall be enabled */
|
|
1320
1457
|
ZSTD_ps_enable = 1, /* Force-enable the feature */
|
|
1321
1458
|
ZSTD_ps_disable = 2 /* Do not use the feature */
|
|
1322
|
-
}
|
|
1459
|
+
} ZSTD_ParamSwitch_e;
|
|
1460
|
+
#define ZSTD_paramSwitch_e ZSTD_ParamSwitch_e /* old name */
|
|
1323
1461
|
|
|
1324
1462
|
/***************************************
|
|
1325
|
-
* Frame size functions
|
|
1463
|
+
* Frame header and size functions
|
|
1326
1464
|
***************************************/
|
|
1327
1465
|
|
|
1328
1466
|
/*! ZSTD_findDecompressedSize() :
|
|
@@ -1364,38 +1502,134 @@ ZSTDLIB_STATIC_API unsigned long long ZSTD_findDecompressedSize(const void* src,
|
|
|
1364
1502
|
ZSTDLIB_STATIC_API unsigned long long ZSTD_decompressBound(const void* src, size_t srcSize);
|
|
1365
1503
|
|
|
1366
1504
|
/*! ZSTD_frameHeaderSize() :
|
|
1367
|
-
* srcSize must be >= ZSTD_FRAMEHEADERSIZE_PREFIX.
|
|
1505
|
+
* srcSize must be large enough, aka >= ZSTD_FRAMEHEADERSIZE_PREFIX.
|
|
1368
1506
|
* @return : size of the Frame Header,
|
|
1369
1507
|
* or an error code (if srcSize is too small) */
|
|
1370
1508
|
ZSTDLIB_STATIC_API size_t ZSTD_frameHeaderSize(const void* src, size_t srcSize);
|
|
1371
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;
|
|
1522
|
+
} ZSTD_FrameHeader;
|
|
1523
|
+
#define ZSTD_frameHeader ZSTD_FrameHeader /* old name */
|
|
1524
|
+
|
|
1525
|
+
/*! ZSTD_getFrameHeader() :
|
|
1526
|
+
* decode Frame Header into `zfhPtr`, or requires larger `srcSize`.
|
|
1527
|
+
* @return : 0 => header is complete, `zfhPtr` is correctly filled,
|
|
1528
|
+
* >0 => `srcSize` is too small, @return value is the wanted `srcSize` amount, `zfhPtr` is not filled,
|
|
1529
|
+
* or an error code, which can be tested using ZSTD_isError() */
|
|
1530
|
+
ZSTDLIB_STATIC_API size_t ZSTD_getFrameHeader(ZSTD_FrameHeader* zfhPtr, const void* src, size_t srcSize);
|
|
1531
|
+
/*! ZSTD_getFrameHeader_advanced() :
|
|
1532
|
+
* same as ZSTD_getFrameHeader(),
|
|
1533
|
+
* with added capability to select a format (like ZSTD_f_zstd1_magicless) */
|
|
1534
|
+
ZSTDLIB_STATIC_API size_t ZSTD_getFrameHeader_advanced(ZSTD_FrameHeader* zfhPtr, const void* src, size_t srcSize, ZSTD_format_e format);
|
|
1535
|
+
|
|
1536
|
+
/*! ZSTD_decompressionMargin() :
|
|
1537
|
+
* Zstd supports in-place decompression, where the input and output buffers overlap.
|
|
1538
|
+
* In this case, the output buffer must be at least (Margin + Output_Size) bytes large,
|
|
1539
|
+
* and the input buffer must be at the end of the output buffer.
|
|
1540
|
+
*
|
|
1541
|
+
* _______________________ Output Buffer ________________________
|
|
1542
|
+
* | |
|
|
1543
|
+
* | ____ Input Buffer ____|
|
|
1544
|
+
* | | |
|
|
1545
|
+
* v v v
|
|
1546
|
+
* |---------------------------------------|-----------|----------|
|
|
1547
|
+
* ^ ^ ^
|
|
1548
|
+
* |___________________ Output_Size ___________________|_ Margin _|
|
|
1549
|
+
*
|
|
1550
|
+
* NOTE: See also ZSTD_DECOMPRESSION_MARGIN().
|
|
1551
|
+
* NOTE: This applies only to single-pass decompression through ZSTD_decompress() or
|
|
1552
|
+
* ZSTD_decompressDCtx().
|
|
1553
|
+
* NOTE: This function supports multi-frame input.
|
|
1554
|
+
*
|
|
1555
|
+
* @param src The compressed frame(s)
|
|
1556
|
+
* @param srcSize The size of the compressed frame(s)
|
|
1557
|
+
* @returns The decompression margin or an error that can be checked with ZSTD_isError().
|
|
1558
|
+
*/
|
|
1559
|
+
ZSTDLIB_STATIC_API size_t ZSTD_decompressionMargin(const void* src, size_t srcSize);
|
|
1560
|
+
|
|
1561
|
+
/*! ZSTD_DECOMPRESS_MARGIN() :
|
|
1562
|
+
* Similar to ZSTD_decompressionMargin(), but instead of computing the margin from
|
|
1563
|
+
* the compressed frame, compute it from the original size and the blockSizeLog.
|
|
1564
|
+
* See ZSTD_decompressionMargin() for details.
|
|
1565
|
+
*
|
|
1566
|
+
* WARNING: This macro does not support multi-frame input, the input must be a single
|
|
1567
|
+
* zstd frame. If you need that support use the function, or implement it yourself.
|
|
1568
|
+
*
|
|
1569
|
+
* @param originalSize The original uncompressed size of the data.
|
|
1570
|
+
* @param blockSize The block size == MIN(windowSize, ZSTD_BLOCKSIZE_MAX).
|
|
1571
|
+
* Unless you explicitly set the windowLog smaller than
|
|
1572
|
+
* ZSTD_BLOCKSIZELOG_MAX you can just use ZSTD_BLOCKSIZE_MAX.
|
|
1573
|
+
*/
|
|
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
|
+
|
|
1372
1581
|
typedef enum {
|
|
1373
|
-
ZSTD_sf_noBlockDelimiters = 0, /*
|
|
1374
|
-
ZSTD_sf_explicitBlockDelimiters = 1 /*
|
|
1375
|
-
}
|
|
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
|
+
|
|
1587
|
+
/*! ZSTD_sequenceBound() :
|
|
1588
|
+
* `srcSize` : size of the input buffer
|
|
1589
|
+
* @return : upper-bound for the number of sequences that can be generated
|
|
1590
|
+
* from a buffer of srcSize bytes
|
|
1591
|
+
*
|
|
1592
|
+
* note : returns number of sequences - to get bytes, multiply by sizeof(ZSTD_Sequence).
|
|
1593
|
+
*/
|
|
1594
|
+
ZSTDLIB_STATIC_API size_t ZSTD_sequenceBound(size_t srcSize);
|
|
1376
1595
|
|
|
1377
1596
|
/*! ZSTD_generateSequences() :
|
|
1378
|
-
*
|
|
1597
|
+
* WARNING: This function is meant for debugging and informational purposes ONLY!
|
|
1598
|
+
* Its implementation is flawed, and it will be deleted in a future version.
|
|
1599
|
+
* It is not guaranteed to succeed, as there are several cases where it will give
|
|
1600
|
+
* up and fail. You should NOT use this function in production code.
|
|
1601
|
+
*
|
|
1602
|
+
* This function is deprecated, and will be removed in a future version.
|
|
1603
|
+
*
|
|
1604
|
+
* Generate sequences using ZSTD_compress2(), given a source buffer.
|
|
1605
|
+
*
|
|
1606
|
+
* @param zc The compression context to be used for ZSTD_compress2(). Set any
|
|
1607
|
+
* compression parameters you need on this context.
|
|
1608
|
+
* @param outSeqs The output sequences buffer of size @p outSeqsSize
|
|
1609
|
+
* @param outSeqsCapacity The size of the output sequences buffer.
|
|
1610
|
+
* ZSTD_sequenceBound(srcSize) is an upper bound on the number
|
|
1611
|
+
* of sequences that can be generated.
|
|
1612
|
+
* @param src The source buffer to generate sequences from of size @p srcSize.
|
|
1613
|
+
* @param srcSize The size of the source buffer.
|
|
1379
1614
|
*
|
|
1380
1615
|
* Each block will end with a dummy sequence
|
|
1381
1616
|
* with offset == 0, matchLength == 0, and litLength == length of last literals.
|
|
1382
1617
|
* litLength may be == 0, and if so, then the sequence of (of: 0 ml: 0 ll: 0)
|
|
1383
1618
|
* simply acts as a block delimiter.
|
|
1384
1619
|
*
|
|
1385
|
-
*
|
|
1386
|
-
*
|
|
1387
|
-
*
|
|
1388
|
-
* The output of this function can be fed into ZSTD_compressSequences() with CCtx
|
|
1389
|
-
* setting of ZSTD_c_blockDelimiters as ZSTD_sf_explicitBlockDelimiters
|
|
1390
|
-
* @return : number of sequences generated
|
|
1620
|
+
* @returns The number of sequences generated, necessarily less than
|
|
1621
|
+
* ZSTD_sequenceBound(srcSize), or an error code that can be checked
|
|
1622
|
+
* with ZSTD_isError().
|
|
1391
1623
|
*/
|
|
1392
|
-
|
|
1393
|
-
ZSTDLIB_STATIC_API size_t
|
|
1394
|
-
|
|
1624
|
+
ZSTD_DEPRECATED("For debugging only, will be replaced by ZSTD_extractSequences()")
|
|
1625
|
+
ZSTDLIB_STATIC_API size_t
|
|
1626
|
+
ZSTD_generateSequences(ZSTD_CCtx* zc,
|
|
1627
|
+
ZSTD_Sequence* outSeqs, size_t outSeqsCapacity,
|
|
1628
|
+
const void* src, size_t srcSize);
|
|
1395
1629
|
|
|
1396
1630
|
/*! ZSTD_mergeBlockDelimiters() :
|
|
1397
1631
|
* Given an array of ZSTD_Sequence, remove all sequences that represent block delimiters/last literals
|
|
1398
|
-
* by merging them into
|
|
1632
|
+
* by merging them into the literals of the next sequence.
|
|
1399
1633
|
*
|
|
1400
1634
|
* As such, the final generated result has no explicit representation of block boundaries,
|
|
1401
1635
|
* and the final last literals segment is not represented in the sequences.
|
|
@@ -1407,8 +1641,10 @@ ZSTDLIB_STATIC_API size_t ZSTD_generateSequences(ZSTD_CCtx* zc, ZSTD_Sequence* o
|
|
|
1407
1641
|
ZSTDLIB_STATIC_API size_t ZSTD_mergeBlockDelimiters(ZSTD_Sequence* sequences, size_t seqsSize);
|
|
1408
1642
|
|
|
1409
1643
|
/*! ZSTD_compressSequences() :
|
|
1410
|
-
* Compress an array of ZSTD_Sequence,
|
|
1411
|
-
*
|
|
1644
|
+
* Compress an array of ZSTD_Sequence, associated with @src buffer, into dst.
|
|
1645
|
+
* @src contains the entire input (not just the literals).
|
|
1646
|
+
* If @srcSize > sum(sequence.length), the remaining bytes are considered all literals
|
|
1647
|
+
* If a dictionary is included, then the cctx should reference the dict (see: ZSTD_CCtx_refCDict(), ZSTD_CCtx_loadDictionary(), etc.).
|
|
1412
1648
|
* The entire source is compressed into a single frame.
|
|
1413
1649
|
*
|
|
1414
1650
|
* The compression behavior changes based on cctx params. In particular:
|
|
@@ -1417,11 +1653,17 @@ ZSTDLIB_STATIC_API size_t ZSTD_mergeBlockDelimiters(ZSTD_Sequence* sequences, si
|
|
|
1417
1653
|
* the block size derived from the cctx, and sequences may be split. This is the default setting.
|
|
1418
1654
|
*
|
|
1419
1655
|
* If ZSTD_c_blockDelimiters == ZSTD_sf_explicitBlockDelimiters, the array of ZSTD_Sequence is expected to contain
|
|
1420
|
-
* block delimiters (defined in ZSTD_Sequence). Behavior is undefined if no block delimiters are provided.
|
|
1656
|
+
* valid block delimiters (defined in ZSTD_Sequence). Behavior is undefined if no block delimiters are provided.
|
|
1657
|
+
*
|
|
1658
|
+
* When ZSTD_c_blockDelimiters == ZSTD_sf_explicitBlockDelimiters, it's possible to decide generating repcodes
|
|
1659
|
+
* using the advanced parameter ZSTD_c_repcodeResolution. Repcodes will improve compression ratio, though the benefit
|
|
1660
|
+
* can vary greatly depending on Sequences. On the other hand, repcode resolution is an expensive operation.
|
|
1661
|
+
* By default, it's disabled at low (<10) compression levels, and enabled above the threshold (>=10).
|
|
1662
|
+
* ZSTD_c_repcodeResolution makes it possible to directly manage this processing in either direction.
|
|
1421
1663
|
*
|
|
1422
|
-
* If ZSTD_c_validateSequences == 0, this function
|
|
1423
|
-
* behavior. If ZSTD_c_validateSequences == 1, then
|
|
1424
|
-
* specifics regarding offset/matchlength requirements) then
|
|
1664
|
+
* If ZSTD_c_validateSequences == 0, this function blindly accepts the Sequences provided. Invalid Sequences cause undefined
|
|
1665
|
+
* behavior. If ZSTD_c_validateSequences == 1, then the function will detect invalid Sequences (see doc/zstd_compression_format.md for
|
|
1666
|
+
* specifics regarding offset/matchlength requirements) and then bail out and return an error.
|
|
1425
1667
|
*
|
|
1426
1668
|
* In addition to the two adjustable experimental params, there are other important cctx params.
|
|
1427
1669
|
* - ZSTD_c_minMatch MUST be set as less than or equal to the smallest match generated by the match finder. It has a minimum value of ZSTD_MINMATCH_MIN.
|
|
@@ -1429,23 +1671,51 @@ ZSTDLIB_STATIC_API size_t ZSTD_mergeBlockDelimiters(ZSTD_Sequence* sequences, si
|
|
|
1429
1671
|
* - ZSTD_c_windowLog affects offset validation: this function will return an error at higher debug levels if a provided offset
|
|
1430
1672
|
* is larger than what the spec allows for a given window log and dictionary (if present). See: doc/zstd_compression_format.md
|
|
1431
1673
|
*
|
|
1432
|
-
* Note: Repcodes are, as of now, always re-calculated within this function,
|
|
1433
|
-
* Note
|
|
1434
|
-
* and cannot emit an RLE block that disagrees with the repcode history
|
|
1435
|
-
* @return : final compressed size or a ZSTD error.
|
|
1436
|
-
*/
|
|
1437
|
-
ZSTDLIB_STATIC_API size_t
|
|
1438
|
-
|
|
1439
|
-
|
|
1674
|
+
* Note: Repcodes are, as of now, always re-calculated within this function, ZSTD_Sequence.rep is effectively unused.
|
|
1675
|
+
* Dev Note: Once ability to ingest repcodes become available, the explicit block delims mode must respect those repcodes exactly,
|
|
1676
|
+
* and cannot emit an RLE block that disagrees with the repcode history.
|
|
1677
|
+
* @return : final compressed size, or a ZSTD error code.
|
|
1678
|
+
*/
|
|
1679
|
+
ZSTDLIB_STATIC_API size_t
|
|
1680
|
+
ZSTD_compressSequences(ZSTD_CCtx* cctx,
|
|
1681
|
+
void* dst, size_t dstCapacity,
|
|
1682
|
+
const ZSTD_Sequence* inSeqs, size_t inSeqsSize,
|
|
1683
|
+
const void* src, size_t srcSize);
|
|
1684
|
+
|
|
1685
|
+
|
|
1686
|
+
/*! ZSTD_compressSequencesAndLiterals() :
|
|
1687
|
+
* This is a variant of ZSTD_compressSequences() which,
|
|
1688
|
+
* instead of receiving (src,srcSize) as input parameter, receives (literals,litSize),
|
|
1689
|
+
* aka all the literals, already extracted and laid out into a single continuous buffer.
|
|
1690
|
+
* This can be useful if the process generating the sequences also happens to generate the buffer of literals,
|
|
1691
|
+
* thus skipping an extraction + caching stage.
|
|
1692
|
+
* It's a speed optimization, useful when the right conditions are met,
|
|
1693
|
+
* but it also features the following limitations:
|
|
1694
|
+
* - Only supports explicit delimiter mode
|
|
1695
|
+
* - Currently does not support Sequences validation (so input Sequences are trusted)
|
|
1696
|
+
* - Not compatible with frame checksum, which must be disabled
|
|
1697
|
+
* - If any block is incompressible, will fail and return an error
|
|
1698
|
+
* - @litSize must be == sum of all @.litLength fields in @inSeqs. Any discrepancy will generate an error.
|
|
1699
|
+
* - @litBufCapacity is the size of the underlying buffer into which literals are written, starting at address @literals.
|
|
1700
|
+
* @litBufCapacity must be at least 8 bytes larger than @litSize.
|
|
1701
|
+
* - @decompressedSize must be correct, and correspond to the sum of all Sequences. Any discrepancy will generate an error.
|
|
1702
|
+
* @return : final compressed size, or a ZSTD error code.
|
|
1703
|
+
*/
|
|
1704
|
+
ZSTDLIB_STATIC_API size_t
|
|
1705
|
+
ZSTD_compressSequencesAndLiterals(ZSTD_CCtx* cctx,
|
|
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);
|
|
1440
1710
|
|
|
1441
1711
|
|
|
1442
1712
|
/*! ZSTD_writeSkippableFrame() :
|
|
1443
1713
|
* Generates a zstd skippable frame containing data given by src, and writes it to dst buffer.
|
|
1444
1714
|
*
|
|
1445
|
-
* Skippable frames begin with a
|
|
1715
|
+
* Skippable frames begin with a 4-byte magic number. There are 16 possible choices of magic number,
|
|
1446
1716
|
* ranging from ZSTD_MAGIC_SKIPPABLE_START to ZSTD_MAGIC_SKIPPABLE_START+15.
|
|
1447
|
-
* As such, the parameter magicVariant controls the exact skippable frame magic number variant used,
|
|
1448
|
-
* the magic number used will be ZSTD_MAGIC_SKIPPABLE_START + magicVariant.
|
|
1717
|
+
* As such, the parameter magicVariant controls the exact skippable frame magic number variant used,
|
|
1718
|
+
* so the magic number used will be ZSTD_MAGIC_SKIPPABLE_START + magicVariant.
|
|
1449
1719
|
*
|
|
1450
1720
|
* Returns an error if destination buffer is not large enough, if the source size is not representable
|
|
1451
1721
|
* with a 4-byte unsigned int, or if the parameter magicVariant is greater than 15 (and therefore invalid).
|
|
@@ -1453,26 +1723,28 @@ ZSTDLIB_STATIC_API size_t ZSTD_compressSequences(ZSTD_CCtx* const cctx, void* ds
|
|
|
1453
1723
|
* @return : number of bytes written or a ZSTD error.
|
|
1454
1724
|
*/
|
|
1455
1725
|
ZSTDLIB_STATIC_API size_t ZSTD_writeSkippableFrame(void* dst, size_t dstCapacity,
|
|
1456
|
-
|
|
1726
|
+
const void* src, size_t srcSize,
|
|
1727
|
+
unsigned magicVariant);
|
|
1457
1728
|
|
|
1458
1729
|
/*! ZSTD_readSkippableFrame() :
|
|
1459
|
-
* Retrieves a zstd skippable frame
|
|
1730
|
+
* Retrieves the content of a zstd skippable frame starting at @src, and writes it to @dst buffer.
|
|
1460
1731
|
*
|
|
1461
|
-
* The parameter magicVariant will receive the magicVariant that was supplied when the frame was written,
|
|
1462
|
-
* i.e. magicNumber - ZSTD_MAGIC_SKIPPABLE_START.
|
|
1463
|
-
* in the magicVariant.
|
|
1732
|
+
* The parameter @magicVariant will receive the magicVariant that was supplied when the frame was written,
|
|
1733
|
+
* i.e. magicNumber - ZSTD_MAGIC_SKIPPABLE_START.
|
|
1734
|
+
* This can be NULL if the caller is not interested in the magicVariant.
|
|
1464
1735
|
*
|
|
1465
1736
|
* Returns an error if destination buffer is not large enough, or if the frame is not skippable.
|
|
1466
1737
|
*
|
|
1467
1738
|
* @return : number of bytes written or a ZSTD error.
|
|
1468
1739
|
*/
|
|
1469
|
-
|
|
1470
|
-
|
|
1740
|
+
ZSTDLIB_STATIC_API size_t ZSTD_readSkippableFrame(void* dst, size_t dstCapacity,
|
|
1741
|
+
unsigned* magicVariant,
|
|
1742
|
+
const void* src, size_t srcSize);
|
|
1471
1743
|
|
|
1472
1744
|
/*! ZSTD_isSkippableFrame() :
|
|
1473
1745
|
* Tells if the content of `buffer` starts with a valid Frame Identifier for a skippable frame.
|
|
1474
1746
|
*/
|
|
1475
|
-
|
|
1747
|
+
ZSTDLIB_STATIC_API unsigned ZSTD_isSkippableFrame(const void* buffer, size_t size);
|
|
1476
1748
|
|
|
1477
1749
|
|
|
1478
1750
|
|
|
@@ -1483,48 +1755,59 @@ ZSTDLIB_API unsigned ZSTD_isSkippableFrame(const void* buffer, size_t size);
|
|
|
1483
1755
|
/*! ZSTD_estimate*() :
|
|
1484
1756
|
* These functions make it possible to estimate memory usage
|
|
1485
1757
|
* of a future {D,C}Ctx, before its creation.
|
|
1758
|
+
* This is useful in combination with ZSTD_initStatic(),
|
|
1759
|
+
* which makes it possible to employ a static buffer for ZSTD_CCtx* state.
|
|
1486
1760
|
*
|
|
1487
1761
|
* ZSTD_estimateCCtxSize() will provide a memory budget large enough
|
|
1488
|
-
*
|
|
1489
|
-
*
|
|
1490
|
-
* does not include space for a window buffer.
|
|
1491
|
-
* Therefore, the estimation is only guaranteed for single-shot compressions, not streaming.
|
|
1762
|
+
* to compress data of any size using one-shot compression ZSTD_compressCCtx() or ZSTD_compress2()
|
|
1763
|
+
* associated with any compression level up to max specified one.
|
|
1492
1764
|
* The estimate will assume the input may be arbitrarily large,
|
|
1493
1765
|
* which is the worst case.
|
|
1494
1766
|
*
|
|
1767
|
+
* Note that the size estimation is specific for one-shot compression,
|
|
1768
|
+
* it is not valid for streaming (see ZSTD_estimateCStreamSize*())
|
|
1769
|
+
* nor other potential ways of using a ZSTD_CCtx* state.
|
|
1770
|
+
*
|
|
1495
1771
|
* When srcSize can be bound by a known and rather "small" value,
|
|
1496
|
-
* this
|
|
1497
|
-
* because the
|
|
1498
|
-
* This tighter estimation can be provided by more advanced functions
|
|
1772
|
+
* this knowledge can be used to provide a tighter budget estimation
|
|
1773
|
+
* because the ZSTD_CCtx* state will need less memory for small inputs.
|
|
1774
|
+
* This tighter estimation can be provided by employing more advanced functions
|
|
1499
1775
|
* ZSTD_estimateCCtxSize_usingCParams(), which can be used in tandem with ZSTD_getCParams(),
|
|
1500
1776
|
* and ZSTD_estimateCCtxSize_usingCCtxParams(), which can be used in tandem with ZSTD_CCtxParams_setParameter().
|
|
1501
1777
|
* Both can be used to estimate memory using custom compression parameters and arbitrary srcSize limits.
|
|
1502
1778
|
*
|
|
1503
|
-
* Note
|
|
1779
|
+
* Note : only single-threaded compression is supported.
|
|
1504
1780
|
* ZSTD_estimateCCtxSize_usingCCtxParams() will return an error code if ZSTD_c_nbWorkers is >= 1.
|
|
1505
1781
|
*/
|
|
1506
|
-
ZSTDLIB_STATIC_API size_t ZSTD_estimateCCtxSize(int
|
|
1782
|
+
ZSTDLIB_STATIC_API size_t ZSTD_estimateCCtxSize(int maxCompressionLevel);
|
|
1507
1783
|
ZSTDLIB_STATIC_API size_t ZSTD_estimateCCtxSize_usingCParams(ZSTD_compressionParameters cParams);
|
|
1508
1784
|
ZSTDLIB_STATIC_API size_t ZSTD_estimateCCtxSize_usingCCtxParams(const ZSTD_CCtx_params* params);
|
|
1509
1785
|
ZSTDLIB_STATIC_API size_t ZSTD_estimateDCtxSize(void);
|
|
1510
1786
|
|
|
1511
1787
|
/*! ZSTD_estimateCStreamSize() :
|
|
1512
|
-
* ZSTD_estimateCStreamSize() will provide a budget large enough for
|
|
1513
|
-
*
|
|
1788
|
+
* ZSTD_estimateCStreamSize() will provide a memory budget large enough for streaming compression
|
|
1789
|
+
* using any compression level up to the max specified one.
|
|
1790
|
+
* It will also consider src size to be arbitrarily "large", which is a worst case scenario.
|
|
1514
1791
|
* If srcSize is known to always be small, ZSTD_estimateCStreamSize_usingCParams() can provide a tighter estimation.
|
|
1515
1792
|
* ZSTD_estimateCStreamSize_usingCParams() can be used in tandem with ZSTD_getCParams() to create cParams from compressionLevel.
|
|
1516
1793
|
* ZSTD_estimateCStreamSize_usingCCtxParams() can be used in tandem with ZSTD_CCtxParams_setParameter(). Only single-threaded compression is supported. This function will return an error code if ZSTD_c_nbWorkers is >= 1.
|
|
1517
1794
|
* Note : CStream size estimation is only correct for single-threaded compression.
|
|
1518
|
-
*
|
|
1795
|
+
* ZSTD_estimateCStreamSize_usingCCtxParams() will return an error code if ZSTD_c_nbWorkers is >= 1.
|
|
1796
|
+
* Note 2 : ZSTD_estimateCStreamSize* functions are not compatible with the Block-Level Sequence Producer API at this time.
|
|
1797
|
+
* Size estimates assume that no external sequence producer is registered.
|
|
1798
|
+
*
|
|
1799
|
+
* ZSTD_DStream memory budget depends on frame's window Size.
|
|
1519
1800
|
* This information can be passed manually, using ZSTD_estimateDStreamSize,
|
|
1520
1801
|
* or deducted from a valid frame Header, using ZSTD_estimateDStreamSize_fromFrame();
|
|
1802
|
+
* Any frame requesting a window size larger than max specified one will be rejected.
|
|
1521
1803
|
* Note : if streaming is init with function ZSTD_init?Stream_usingDict(),
|
|
1522
1804
|
* 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
|
|
1524
|
-
|
|
1805
|
+
* In this case, get total size by adding ZSTD_estimate?DictSize
|
|
1806
|
+
*/
|
|
1807
|
+
ZSTDLIB_STATIC_API size_t ZSTD_estimateCStreamSize(int maxCompressionLevel);
|
|
1525
1808
|
ZSTDLIB_STATIC_API size_t ZSTD_estimateCStreamSize_usingCParams(ZSTD_compressionParameters cParams);
|
|
1526
1809
|
ZSTDLIB_STATIC_API size_t ZSTD_estimateCStreamSize_usingCCtxParams(const ZSTD_CCtx_params* params);
|
|
1527
|
-
ZSTDLIB_STATIC_API size_t ZSTD_estimateDStreamSize(size_t
|
|
1810
|
+
ZSTDLIB_STATIC_API size_t ZSTD_estimateDStreamSize(size_t maxWindowSize);
|
|
1528
1811
|
ZSTDLIB_STATIC_API size_t ZSTD_estimateDStreamSize_fromFrame(const void* src, size_t srcSize);
|
|
1529
1812
|
|
|
1530
1813
|
/*! ZSTD_estimate?DictSize() :
|
|
@@ -1589,7 +1872,15 @@ static
|
|
|
1589
1872
|
#ifdef __GNUC__
|
|
1590
1873
|
__attribute__((__unused__))
|
|
1591
1874
|
#endif
|
|
1875
|
+
|
|
1876
|
+
#if defined(__clang__) && __clang_major__ >= 5
|
|
1877
|
+
#pragma clang diagnostic push
|
|
1878
|
+
#pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant"
|
|
1879
|
+
#endif
|
|
1592
1880
|
ZSTD_customMem const ZSTD_defaultCMem = { NULL, NULL, NULL }; /**< this constant defers to stdlib's functions */
|
|
1881
|
+
#if defined(__clang__) && __clang_major__ >= 5
|
|
1882
|
+
#pragma clang diagnostic pop
|
|
1883
|
+
#endif
|
|
1593
1884
|
|
|
1594
1885
|
ZSTDLIB_STATIC_API ZSTD_CCtx* ZSTD_createCCtx_advanced(ZSTD_customMem customMem);
|
|
1595
1886
|
ZSTDLIB_STATIC_API ZSTD_CStream* ZSTD_createCStream_advanced(ZSTD_customMem customMem);
|
|
@@ -1670,22 +1961,45 @@ ZSTDLIB_STATIC_API size_t ZSTD_checkCParams(ZSTD_compressionParameters params);
|
|
|
1670
1961
|
* This function never fails (wide contract) */
|
|
1671
1962
|
ZSTDLIB_STATIC_API ZSTD_compressionParameters ZSTD_adjustCParams(ZSTD_compressionParameters cPar, unsigned long long srcSize, size_t dictSize);
|
|
1672
1963
|
|
|
1964
|
+
/*! ZSTD_CCtx_setCParams() :
|
|
1965
|
+
* Set all parameters provided within @p cparams into the working @p cctx.
|
|
1966
|
+
* Note : if modifying parameters during compression (MT mode only),
|
|
1967
|
+
* note that changes to the .windowLog parameter will be ignored.
|
|
1968
|
+
* @return 0 on success, or an error code (can be checked with ZSTD_isError()).
|
|
1969
|
+
* On failure, no parameters are updated.
|
|
1970
|
+
*/
|
|
1971
|
+
ZSTDLIB_STATIC_API size_t ZSTD_CCtx_setCParams(ZSTD_CCtx* cctx, ZSTD_compressionParameters cparams);
|
|
1972
|
+
|
|
1973
|
+
/*! ZSTD_CCtx_setFParams() :
|
|
1974
|
+
* Set all parameters provided within @p fparams into the working @p cctx.
|
|
1975
|
+
* @return 0 on success, or an error code (can be checked with ZSTD_isError()).
|
|
1976
|
+
*/
|
|
1977
|
+
ZSTDLIB_STATIC_API size_t ZSTD_CCtx_setFParams(ZSTD_CCtx* cctx, ZSTD_frameParameters fparams);
|
|
1978
|
+
|
|
1979
|
+
/*! ZSTD_CCtx_setParams() :
|
|
1980
|
+
* Set all parameters provided within @p params into the working @p cctx.
|
|
1981
|
+
* @return 0 on success, or an error code (can be checked with ZSTD_isError()).
|
|
1982
|
+
*/
|
|
1983
|
+
ZSTDLIB_STATIC_API size_t ZSTD_CCtx_setParams(ZSTD_CCtx* cctx, ZSTD_parameters params);
|
|
1984
|
+
|
|
1673
1985
|
/*! ZSTD_compress_advanced() :
|
|
1674
1986
|
* Note : this function is now DEPRECATED.
|
|
1675
1987
|
* It can be replaced by ZSTD_compress2(), in combination with ZSTD_CCtx_setParameter() and other parameter setters.
|
|
1676
1988
|
* This prototype will generate compilation warnings. */
|
|
1677
1989
|
ZSTD_DEPRECATED("use ZSTD_compress2")
|
|
1990
|
+
ZSTDLIB_STATIC_API
|
|
1678
1991
|
size_t ZSTD_compress_advanced(ZSTD_CCtx* cctx,
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1992
|
+
void* dst, size_t dstCapacity,
|
|
1993
|
+
const void* src, size_t srcSize,
|
|
1994
|
+
const void* dict,size_t dictSize,
|
|
1995
|
+
ZSTD_parameters params);
|
|
1683
1996
|
|
|
1684
1997
|
/*! ZSTD_compress_usingCDict_advanced() :
|
|
1685
1998
|
* Note : this function is now DEPRECATED.
|
|
1686
1999
|
* It can be replaced by ZSTD_compress2(), in combination with ZSTD_CCtx_loadDictionary() and other parameter setters.
|
|
1687
2000
|
* This prototype will generate compilation warnings. */
|
|
1688
2001
|
ZSTD_DEPRECATED("use ZSTD_compress2 with ZSTD_CCtx_loadDictionary")
|
|
2002
|
+
ZSTDLIB_STATIC_API
|
|
1689
2003
|
size_t ZSTD_compress_usingCDict_advanced(ZSTD_CCtx* cctx,
|
|
1690
2004
|
void* dst, size_t dstCapacity,
|
|
1691
2005
|
const void* src, size_t srcSize,
|
|
@@ -1746,7 +2060,7 @@ ZSTDLIB_STATIC_API size_t ZSTD_CCtx_refPrefix_advanced(ZSTD_CCtx* cctx, const vo
|
|
|
1746
2060
|
* See the comments on that enum for an explanation of the feature. */
|
|
1747
2061
|
#define ZSTD_c_forceAttachDict ZSTD_c_experimentalParam4
|
|
1748
2062
|
|
|
1749
|
-
/* Controlled with
|
|
2063
|
+
/* Controlled with ZSTD_ParamSwitch_e enum.
|
|
1750
2064
|
* Default is ZSTD_ps_auto.
|
|
1751
2065
|
* Set to ZSTD_ps_disable to never compress literals.
|
|
1752
2066
|
* Set to ZSTD_ps_enable to always compress literals. (Note: uncompressed literals
|
|
@@ -1758,11 +2072,6 @@ ZSTDLIB_STATIC_API size_t ZSTD_CCtx_refPrefix_advanced(ZSTD_CCtx* cctx, const vo
|
|
|
1758
2072
|
*/
|
|
1759
2073
|
#define ZSTD_c_literalCompressionMode ZSTD_c_experimentalParam5
|
|
1760
2074
|
|
|
1761
|
-
/* Tries to fit compressed block size to be around targetCBlockSize.
|
|
1762
|
-
* No target when targetCBlockSize == 0.
|
|
1763
|
-
* There is no guarantee on compressed block size (default:0) */
|
|
1764
|
-
#define ZSTD_c_targetCBlockSize ZSTD_c_experimentalParam6
|
|
1765
|
-
|
|
1766
2075
|
/* User's best guess of source size.
|
|
1767
2076
|
* Hint is not valid when srcSizeHint == 0.
|
|
1768
2077
|
* There is no guarantee that hint is close to actual source size,
|
|
@@ -1829,13 +2138,16 @@ ZSTDLIB_STATIC_API size_t ZSTD_CCtx_refPrefix_advanced(ZSTD_CCtx* cctx, const vo
|
|
|
1829
2138
|
* Experimental parameter.
|
|
1830
2139
|
* Default is 0 == disabled. Set to 1 to enable.
|
|
1831
2140
|
*
|
|
1832
|
-
* Tells the compressor that
|
|
1833
|
-
*
|
|
1834
|
-
*
|
|
1835
|
-
*
|
|
1836
|
-
*
|
|
1837
|
-
*
|
|
1838
|
-
*
|
|
2141
|
+
* Tells the compressor that input data presented with ZSTD_inBuffer
|
|
2142
|
+
* will ALWAYS be the same between calls.
|
|
2143
|
+
* Technically, the @src pointer must never be changed,
|
|
2144
|
+
* and the @pos field can only be updated by zstd.
|
|
2145
|
+
* However, it's possible to increase the @size field,
|
|
2146
|
+
* allowing scenarios where more data can be appended after compressions starts.
|
|
2147
|
+
* These conditions are checked by the compressor,
|
|
2148
|
+
* and compression will fail if they are not respected.
|
|
2149
|
+
* Also, data in the ZSTD_inBuffer within the range [src, src + pos)
|
|
2150
|
+
* MUST not be modified during compression or it will result in data corruption.
|
|
1839
2151
|
*
|
|
1840
2152
|
* When this flag is enabled zstd won't allocate an input window buffer,
|
|
1841
2153
|
* because the user guarantees it can reference the ZSTD_inBuffer until
|
|
@@ -1843,18 +2155,15 @@ ZSTDLIB_STATIC_API size_t ZSTD_CCtx_refPrefix_advanced(ZSTD_CCtx* cctx, const vo
|
|
|
1843
2155
|
* large enough to fit a block (see ZSTD_c_stableOutBuffer). This will also
|
|
1844
2156
|
* avoid the memcpy() from the input buffer to the input window buffer.
|
|
1845
2157
|
*
|
|
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
2158
|
* NOTE: So long as the ZSTD_inBuffer always points to valid memory, using
|
|
1850
2159
|
* this flag is ALWAYS memory safe, and will never access out-of-bounds
|
|
1851
|
-
* memory. However, compression WILL fail if
|
|
2160
|
+
* memory. However, compression WILL fail if conditions are not respected.
|
|
1852
2161
|
*
|
|
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
|
|
2162
|
+
* WARNING: The data in the ZSTD_inBuffer in the range [src, src + pos) MUST
|
|
2163
|
+
* not be modified during compression or it will result in data corruption.
|
|
2164
|
+
* This is because zstd needs to reference data in the ZSTD_inBuffer to find
|
|
1856
2165
|
* matches. Normally zstd maintains its own window buffer for this purpose,
|
|
1857
|
-
* but passing this flag tells zstd to
|
|
2166
|
+
* but passing this flag tells zstd to rely on user provided buffer instead.
|
|
1858
2167
|
*/
|
|
1859
2168
|
#define ZSTD_c_stableInBuffer ZSTD_c_experimentalParam9
|
|
1860
2169
|
|
|
@@ -1892,22 +2201,46 @@ ZSTDLIB_STATIC_API size_t ZSTD_CCtx_refPrefix_advanced(ZSTD_CCtx* cctx, const vo
|
|
|
1892
2201
|
/* ZSTD_c_validateSequences
|
|
1893
2202
|
* Default is 0 == disabled. Set to 1 to enable sequence validation.
|
|
1894
2203
|
*
|
|
1895
|
-
* For use with sequence compression API: ZSTD_compressSequences().
|
|
1896
|
-
* Designates whether or not
|
|
2204
|
+
* For use with sequence compression API: ZSTD_compressSequences*().
|
|
2205
|
+
* Designates whether or not provided sequences are validated within ZSTD_compressSequences*()
|
|
1897
2206
|
* during function execution.
|
|
1898
2207
|
*
|
|
1899
|
-
*
|
|
1900
|
-
*
|
|
2208
|
+
* When Sequence validation is disabled (default), Sequences are compressed as-is,
|
|
2209
|
+
* so they must correct, otherwise it would result in a corruption error.
|
|
1901
2210
|
*
|
|
1902
|
-
*
|
|
2211
|
+
* Sequence validation adds some protection, by ensuring that all values respect boundary conditions.
|
|
2212
|
+
* If a Sequence is detected invalid (see doc/zstd_compression_format.md for
|
|
1903
2213
|
* specifics regarding offset/matchlength requirements) then the function will bail out and
|
|
1904
2214
|
* return an error.
|
|
1905
|
-
*
|
|
1906
2215
|
*/
|
|
1907
2216
|
#define ZSTD_c_validateSequences ZSTD_c_experimentalParam12
|
|
1908
2217
|
|
|
1909
|
-
/*
|
|
1910
|
-
*
|
|
2218
|
+
/* ZSTD_c_blockSplitterLevel
|
|
2219
|
+
* note: this parameter only influences the first splitter stage,
|
|
2220
|
+
* which is active before producing the sequences.
|
|
2221
|
+
* ZSTD_c_splitAfterSequences controls the next splitter stage,
|
|
2222
|
+
* which is active after sequence production.
|
|
2223
|
+
* Note that both can be combined.
|
|
2224
|
+
* Allowed values are between 0 and ZSTD_BLOCKSPLITTER_LEVEL_MAX included.
|
|
2225
|
+
* 0 means "auto", which will select a value depending on current ZSTD_c_strategy.
|
|
2226
|
+
* 1 means no splitting.
|
|
2227
|
+
* Then, values from 2 to 6 are sorted in increasing cpu load order.
|
|
2228
|
+
*
|
|
2229
|
+
* Note that currently the first block is never split,
|
|
2230
|
+
* to ensure expansion guarantees in presence of incompressible data.
|
|
2231
|
+
*/
|
|
2232
|
+
#define ZSTD_BLOCKSPLITTER_LEVEL_MAX 6
|
|
2233
|
+
#define ZSTD_c_blockSplitterLevel ZSTD_c_experimentalParam20
|
|
2234
|
+
|
|
2235
|
+
/* ZSTD_c_splitAfterSequences
|
|
2236
|
+
* This is a stronger splitter algorithm,
|
|
2237
|
+
* based on actual sequences previously produced by the selected parser.
|
|
2238
|
+
* It's also slower, and as a consequence, mostly used for high compression levels.
|
|
2239
|
+
* While the post-splitter does overlap with the pre-splitter,
|
|
2240
|
+
* both can nonetheless be combined,
|
|
2241
|
+
* notably with ZSTD_c_blockSplitterLevel at ZSTD_BLOCKSPLITTER_LEVEL_MAX,
|
|
2242
|
+
* resulting in higher compression ratio than just one of them.
|
|
2243
|
+
*
|
|
1911
2244
|
* Default is ZSTD_ps_auto.
|
|
1912
2245
|
* Set to ZSTD_ps_disable to never use block splitter.
|
|
1913
2246
|
* Set to ZSTD_ps_enable to always use block splitter.
|
|
@@ -1915,10 +2248,10 @@ ZSTDLIB_STATIC_API size_t ZSTD_CCtx_refPrefix_advanced(ZSTD_CCtx* cctx, const vo
|
|
|
1915
2248
|
* By default, in ZSTD_ps_auto, the library will decide at runtime whether to use
|
|
1916
2249
|
* block splitting based on the compression parameters.
|
|
1917
2250
|
*/
|
|
1918
|
-
#define
|
|
2251
|
+
#define ZSTD_c_splitAfterSequences ZSTD_c_experimentalParam13
|
|
1919
2252
|
|
|
1920
2253
|
/* ZSTD_c_useRowMatchFinder
|
|
1921
|
-
* Controlled with
|
|
2254
|
+
* Controlled with ZSTD_ParamSwitch_e enum.
|
|
1922
2255
|
* Default is ZSTD_ps_auto.
|
|
1923
2256
|
* Set to ZSTD_ps_disable to never use row-based matchfinder.
|
|
1924
2257
|
* Set to ZSTD_ps_enable to force usage of row-based matchfinder.
|
|
@@ -1949,6 +2282,80 @@ ZSTDLIB_STATIC_API size_t ZSTD_CCtx_refPrefix_advanced(ZSTD_CCtx* cctx, const vo
|
|
|
1949
2282
|
*/
|
|
1950
2283
|
#define ZSTD_c_deterministicRefPrefix ZSTD_c_experimentalParam15
|
|
1951
2284
|
|
|
2285
|
+
/* ZSTD_c_prefetchCDictTables
|
|
2286
|
+
* Controlled with ZSTD_ParamSwitch_e enum. Default is ZSTD_ps_auto.
|
|
2287
|
+
*
|
|
2288
|
+
* In some situations, zstd uses CDict tables in-place rather than copying them
|
|
2289
|
+
* into the working context. (See docs on ZSTD_dictAttachPref_e above for details).
|
|
2290
|
+
* In such situations, compression speed is seriously impacted when CDict tables are
|
|
2291
|
+
* "cold" (outside CPU cache). This parameter instructs zstd to prefetch CDict tables
|
|
2292
|
+
* when they are used in-place.
|
|
2293
|
+
*
|
|
2294
|
+
* For sufficiently small inputs, the cost of the prefetch will outweigh the benefit.
|
|
2295
|
+
* For sufficiently large inputs, zstd will by default memcpy() CDict tables
|
|
2296
|
+
* into the working context, so there is no need to prefetch. This parameter is
|
|
2297
|
+
* targeted at a middle range of input sizes, where a prefetch is cheap enough to be
|
|
2298
|
+
* useful but memcpy() is too expensive. The exact range of input sizes where this
|
|
2299
|
+
* makes sense is best determined by careful experimentation.
|
|
2300
|
+
*
|
|
2301
|
+
* Note: for this parameter, ZSTD_ps_auto is currently equivalent to ZSTD_ps_disable,
|
|
2302
|
+
* but in the future zstd may conditionally enable this feature via an auto-detection
|
|
2303
|
+
* heuristic for cold CDicts.
|
|
2304
|
+
* Use ZSTD_ps_disable to opt out of prefetching under any circumstances.
|
|
2305
|
+
*/
|
|
2306
|
+
#define ZSTD_c_prefetchCDictTables ZSTD_c_experimentalParam16
|
|
2307
|
+
|
|
2308
|
+
/* ZSTD_c_enableSeqProducerFallback
|
|
2309
|
+
* Allowed values are 0 (disable) and 1 (enable). The default setting is 0.
|
|
2310
|
+
*
|
|
2311
|
+
* Controls whether zstd will fall back to an internal sequence producer if an
|
|
2312
|
+
* external sequence producer is registered and returns an error code. This fallback
|
|
2313
|
+
* is block-by-block: the internal sequence producer will only be called for blocks
|
|
2314
|
+
* where the external sequence producer returns an error code. Fallback parsing will
|
|
2315
|
+
* follow any other cParam settings, such as compression level, the same as in a
|
|
2316
|
+
* normal (fully-internal) compression operation.
|
|
2317
|
+
*
|
|
2318
|
+
* The user is strongly encouraged to read the full Block-Level Sequence Producer API
|
|
2319
|
+
* documentation (below) before setting this parameter. */
|
|
2320
|
+
#define ZSTD_c_enableSeqProducerFallback ZSTD_c_experimentalParam17
|
|
2321
|
+
|
|
2322
|
+
/* ZSTD_c_maxBlockSize
|
|
2323
|
+
* Allowed values are between 1KB and ZSTD_BLOCKSIZE_MAX (128KB).
|
|
2324
|
+
* The default is ZSTD_BLOCKSIZE_MAX, and setting to 0 will set to the default.
|
|
2325
|
+
*
|
|
2326
|
+
* This parameter can be used to set an upper bound on the blocksize
|
|
2327
|
+
* that overrides the default ZSTD_BLOCKSIZE_MAX. It cannot be used to set upper
|
|
2328
|
+
* bounds greater than ZSTD_BLOCKSIZE_MAX or bounds lower than 1KB (will make
|
|
2329
|
+
* compressBound() inaccurate). Only currently meant to be used for testing.
|
|
2330
|
+
*/
|
|
2331
|
+
#define ZSTD_c_maxBlockSize ZSTD_c_experimentalParam18
|
|
2332
|
+
|
|
2333
|
+
/* ZSTD_c_repcodeResolution
|
|
2334
|
+
* This parameter only has an effect if ZSTD_c_blockDelimiters is
|
|
2335
|
+
* set to ZSTD_sf_explicitBlockDelimiters (may change in the future).
|
|
2336
|
+
*
|
|
2337
|
+
* This parameter affects how zstd parses external sequences,
|
|
2338
|
+
* provided via the ZSTD_compressSequences*() API
|
|
2339
|
+
* or from an external block-level sequence producer.
|
|
2340
|
+
*
|
|
2341
|
+
* If set to ZSTD_ps_enable, the library will check for repeated offsets within
|
|
2342
|
+
* external sequences, even if those repcodes are not explicitly indicated in
|
|
2343
|
+
* the "rep" field. Note that this is the only way to exploit repcode matches
|
|
2344
|
+
* while using compressSequences*() or an external sequence producer, since zstd
|
|
2345
|
+
* currently ignores the "rep" field of external sequences.
|
|
2346
|
+
*
|
|
2347
|
+
* If set to ZSTD_ps_disable, the library will not exploit repeated offsets in
|
|
2348
|
+
* external sequences, regardless of whether the "rep" field has been set. This
|
|
2349
|
+
* reduces sequence compression overhead by about 25% while sacrificing some
|
|
2350
|
+
* compression ratio.
|
|
2351
|
+
*
|
|
2352
|
+
* The default value is ZSTD_ps_auto, for which the library will enable/disable
|
|
2353
|
+
* based on compression level (currently: level<10 disables, level>=10 enables).
|
|
2354
|
+
*/
|
|
2355
|
+
#define ZSTD_c_repcodeResolution ZSTD_c_experimentalParam19
|
|
2356
|
+
#define ZSTD_c_searchForExternalRepcodes ZSTD_c_experimentalParam19 /* older name */
|
|
2357
|
+
|
|
2358
|
+
|
|
1952
2359
|
/*! ZSTD_CCtx_getParameter() :
|
|
1953
2360
|
* Get the requested compression parameter value, selected by enum ZSTD_cParameter,
|
|
1954
2361
|
* and store it into int* value.
|
|
@@ -2105,7 +2512,7 @@ ZSTDLIB_STATIC_API size_t ZSTD_DCtx_getParameter(ZSTD_DCtx* dctx, ZSTD_dParamete
|
|
|
2105
2512
|
* in the range [dst, dst + pos) MUST not be modified during decompression
|
|
2106
2513
|
* or you will get data corruption.
|
|
2107
2514
|
*
|
|
2108
|
-
* When this
|
|
2515
|
+
* When this flag is enabled zstd won't allocate an output buffer, because
|
|
2109
2516
|
* it can write directly to the ZSTD_outBuffer, but it will still allocate
|
|
2110
2517
|
* an input buffer large enough to fit any compressed block. This will also
|
|
2111
2518
|
* avoid the memcpy() from the internal output buffer to the ZSTD_outBuffer.
|
|
@@ -2158,6 +2565,33 @@ ZSTDLIB_STATIC_API size_t ZSTD_DCtx_getParameter(ZSTD_DCtx* dctx, ZSTD_dParamete
|
|
|
2158
2565
|
*/
|
|
2159
2566
|
#define ZSTD_d_refMultipleDDicts ZSTD_d_experimentalParam4
|
|
2160
2567
|
|
|
2568
|
+
/* ZSTD_d_disableHuffmanAssembly
|
|
2569
|
+
* Set to 1 to disable the Huffman assembly implementation.
|
|
2570
|
+
* The default value is 0, which allows zstd to use the Huffman assembly
|
|
2571
|
+
* implementation if available.
|
|
2572
|
+
*
|
|
2573
|
+
* This parameter can be used to disable Huffman assembly at runtime.
|
|
2574
|
+
* If you want to disable it at compile time you can define the macro
|
|
2575
|
+
* ZSTD_DISABLE_ASM.
|
|
2576
|
+
*/
|
|
2577
|
+
#define ZSTD_d_disableHuffmanAssembly ZSTD_d_experimentalParam5
|
|
2578
|
+
|
|
2579
|
+
/* ZSTD_d_maxBlockSize
|
|
2580
|
+
* Allowed values are between 1KB and ZSTD_BLOCKSIZE_MAX (128KB).
|
|
2581
|
+
* The default is ZSTD_BLOCKSIZE_MAX, and setting to 0 will set to the default.
|
|
2582
|
+
*
|
|
2583
|
+
* Forces the decompressor to reject blocks whose content size is
|
|
2584
|
+
* larger than the configured maxBlockSize. When maxBlockSize is
|
|
2585
|
+
* larger than the windowSize, the windowSize is used instead.
|
|
2586
|
+
* This saves memory on the decoder when you know all blocks are small.
|
|
2587
|
+
*
|
|
2588
|
+
* This option is typically used in conjunction with ZSTD_c_maxBlockSize.
|
|
2589
|
+
*
|
|
2590
|
+
* WARNING: This causes the decoder to reject otherwise valid frames
|
|
2591
|
+
* that have block sizes larger than the configured maxBlockSize.
|
|
2592
|
+
*/
|
|
2593
|
+
#define ZSTD_d_maxBlockSize ZSTD_d_experimentalParam6
|
|
2594
|
+
|
|
2161
2595
|
|
|
2162
2596
|
/*! ZSTD_DCtx_setFormat() :
|
|
2163
2597
|
* This function is REDUNDANT. Prefer ZSTD_DCtx_setParameter().
|
|
@@ -2166,6 +2600,7 @@ ZSTDLIB_STATIC_API size_t ZSTD_DCtx_getParameter(ZSTD_DCtx* dctx, ZSTD_dParamete
|
|
|
2166
2600
|
* such ZSTD_f_zstd1_magicless for example.
|
|
2167
2601
|
* @return : 0, or an error code (which can be tested using ZSTD_isError()). */
|
|
2168
2602
|
ZSTD_DEPRECATED("use ZSTD_DCtx_setParameter() instead")
|
|
2603
|
+
ZSTDLIB_STATIC_API
|
|
2169
2604
|
size_t ZSTD_DCtx_setFormat(ZSTD_DCtx* dctx, ZSTD_format_e format);
|
|
2170
2605
|
|
|
2171
2606
|
/*! ZSTD_decompressStream_simpleArgs() :
|
|
@@ -2202,6 +2637,7 @@ ZSTDLIB_STATIC_API size_t ZSTD_decompressStream_simpleArgs (
|
|
|
2202
2637
|
* This prototype will generate compilation warnings.
|
|
2203
2638
|
*/
|
|
2204
2639
|
ZSTD_DEPRECATED("use ZSTD_CCtx_reset, see zstd.h for detailed instructions")
|
|
2640
|
+
ZSTDLIB_STATIC_API
|
|
2205
2641
|
size_t ZSTD_initCStream_srcSize(ZSTD_CStream* zcs,
|
|
2206
2642
|
int compressionLevel,
|
|
2207
2643
|
unsigned long long pledgedSrcSize);
|
|
@@ -2219,17 +2655,15 @@ size_t ZSTD_initCStream_srcSize(ZSTD_CStream* zcs,
|
|
|
2219
2655
|
* This prototype will generate compilation warnings.
|
|
2220
2656
|
*/
|
|
2221
2657
|
ZSTD_DEPRECATED("use ZSTD_CCtx_reset, see zstd.h for detailed instructions")
|
|
2658
|
+
ZSTDLIB_STATIC_API
|
|
2222
2659
|
size_t ZSTD_initCStream_usingDict(ZSTD_CStream* zcs,
|
|
2223
2660
|
const void* dict, size_t dictSize,
|
|
2224
2661
|
int compressionLevel);
|
|
2225
2662
|
|
|
2226
2663
|
/*! ZSTD_initCStream_advanced() :
|
|
2227
|
-
* This function is DEPRECATED, and is
|
|
2664
|
+
* This function is DEPRECATED, and is equivalent to:
|
|
2228
2665
|
* ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
|
|
2229
|
-
*
|
|
2230
|
-
* for ((param, value) : params) {
|
|
2231
|
-
* ZSTD_CCtx_setParameter(zcs, param, value);
|
|
2232
|
-
* }
|
|
2666
|
+
* ZSTD_CCtx_setParams(zcs, params);
|
|
2233
2667
|
* ZSTD_CCtx_setPledgedSrcSize(zcs, pledgedSrcSize);
|
|
2234
2668
|
* ZSTD_CCtx_loadDictionary(zcs, dict, dictSize);
|
|
2235
2669
|
*
|
|
@@ -2239,6 +2673,7 @@ size_t ZSTD_initCStream_usingDict(ZSTD_CStream* zcs,
|
|
|
2239
2673
|
* This prototype will generate compilation warnings.
|
|
2240
2674
|
*/
|
|
2241
2675
|
ZSTD_DEPRECATED("use ZSTD_CCtx_reset, see zstd.h for detailed instructions")
|
|
2676
|
+
ZSTDLIB_STATIC_API
|
|
2242
2677
|
size_t ZSTD_initCStream_advanced(ZSTD_CStream* zcs,
|
|
2243
2678
|
const void* dict, size_t dictSize,
|
|
2244
2679
|
ZSTD_parameters params,
|
|
@@ -2253,15 +2688,13 @@ size_t ZSTD_initCStream_advanced(ZSTD_CStream* zcs,
|
|
|
2253
2688
|
* This prototype will generate compilation warnings.
|
|
2254
2689
|
*/
|
|
2255
2690
|
ZSTD_DEPRECATED("use ZSTD_CCtx_reset and ZSTD_CCtx_refCDict, see zstd.h for detailed instructions")
|
|
2691
|
+
ZSTDLIB_STATIC_API
|
|
2256
2692
|
size_t ZSTD_initCStream_usingCDict(ZSTD_CStream* zcs, const ZSTD_CDict* cdict);
|
|
2257
2693
|
|
|
2258
2694
|
/*! ZSTD_initCStream_usingCDict_advanced() :
|
|
2259
|
-
* This function is DEPRECATED, and is
|
|
2695
|
+
* This function is DEPRECATED, and is equivalent to:
|
|
2260
2696
|
* ZSTD_CCtx_reset(zcs, ZSTD_reset_session_only);
|
|
2261
|
-
*
|
|
2262
|
-
* for ((fParam, value) : fParams) {
|
|
2263
|
-
* ZSTD_CCtx_setParameter(zcs, fParam, value);
|
|
2264
|
-
* }
|
|
2697
|
+
* ZSTD_CCtx_setFParams(zcs, fParams);
|
|
2265
2698
|
* ZSTD_CCtx_setPledgedSrcSize(zcs, pledgedSrcSize);
|
|
2266
2699
|
* ZSTD_CCtx_refCDict(zcs, cdict);
|
|
2267
2700
|
*
|
|
@@ -2271,6 +2704,7 @@ size_t ZSTD_initCStream_usingCDict(ZSTD_CStream* zcs, const ZSTD_CDict* cdict);
|
|
|
2271
2704
|
* This prototype will generate compilation warnings.
|
|
2272
2705
|
*/
|
|
2273
2706
|
ZSTD_DEPRECATED("use ZSTD_CCtx_reset and ZSTD_CCtx_refCDict, see zstd.h for detailed instructions")
|
|
2707
|
+
ZSTDLIB_STATIC_API
|
|
2274
2708
|
size_t ZSTD_initCStream_usingCDict_advanced(ZSTD_CStream* zcs,
|
|
2275
2709
|
const ZSTD_CDict* cdict,
|
|
2276
2710
|
ZSTD_frameParameters fParams,
|
|
@@ -2285,7 +2719,7 @@ size_t ZSTD_initCStream_usingCDict_advanced(ZSTD_CStream* zcs,
|
|
|
2285
2719
|
* explicitly specified.
|
|
2286
2720
|
*
|
|
2287
2721
|
* start a new frame, using same parameters from previous frame.
|
|
2288
|
-
* This is typically useful to skip dictionary loading stage, since it will
|
|
2722
|
+
* This is typically useful to skip dictionary loading stage, since it will reuse it in-place.
|
|
2289
2723
|
* Note that zcs must be init at least once before using ZSTD_resetCStream().
|
|
2290
2724
|
* If pledgedSrcSize is not known at reset time, use macro ZSTD_CONTENTSIZE_UNKNOWN.
|
|
2291
2725
|
* If pledgedSrcSize > 0, its value must be correct, as it will be written in header, and controlled at the end.
|
|
@@ -2295,6 +2729,7 @@ size_t ZSTD_initCStream_usingCDict_advanced(ZSTD_CStream* zcs,
|
|
|
2295
2729
|
* This prototype will generate compilation warnings.
|
|
2296
2730
|
*/
|
|
2297
2731
|
ZSTD_DEPRECATED("use ZSTD_CCtx_reset, see zstd.h for detailed instructions")
|
|
2732
|
+
ZSTDLIB_STATIC_API
|
|
2298
2733
|
size_t ZSTD_resetCStream(ZSTD_CStream* zcs, unsigned long long pledgedSrcSize);
|
|
2299
2734
|
|
|
2300
2735
|
|
|
@@ -2340,8 +2775,8 @@ ZSTDLIB_STATIC_API size_t ZSTD_toFlushNow(ZSTD_CCtx* cctx);
|
|
|
2340
2775
|
* ZSTD_DCtx_loadDictionary(zds, dict, dictSize);
|
|
2341
2776
|
*
|
|
2342
2777
|
* 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
2778
|
*/
|
|
2779
|
+
ZSTD_DEPRECATED("use ZSTD_DCtx_reset + ZSTD_DCtx_loadDictionary, see zstd.h for detailed instructions")
|
|
2345
2780
|
ZSTDLIB_STATIC_API size_t ZSTD_initDStream_usingDict(ZSTD_DStream* zds, const void* dict, size_t dictSize);
|
|
2346
2781
|
|
|
2347
2782
|
/*!
|
|
@@ -2351,8 +2786,8 @@ ZSTDLIB_STATIC_API size_t ZSTD_initDStream_usingDict(ZSTD_DStream* zds, const vo
|
|
|
2351
2786
|
* ZSTD_DCtx_refDDict(zds, ddict);
|
|
2352
2787
|
*
|
|
2353
2788
|
* 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
2789
|
*/
|
|
2790
|
+
ZSTD_DEPRECATED("use ZSTD_DCtx_reset + ZSTD_DCtx_refDDict, see zstd.h for detailed instructions")
|
|
2356
2791
|
ZSTDLIB_STATIC_API size_t ZSTD_initDStream_usingDDict(ZSTD_DStream* zds, const ZSTD_DDict* ddict);
|
|
2357
2792
|
|
|
2358
2793
|
/*!
|
|
@@ -2360,18 +2795,202 @@ ZSTDLIB_STATIC_API size_t ZSTD_initDStream_usingDDict(ZSTD_DStream* zds, const Z
|
|
|
2360
2795
|
*
|
|
2361
2796
|
* ZSTD_DCtx_reset(zds, ZSTD_reset_session_only);
|
|
2362
2797
|
*
|
|
2363
|
-
*
|
|
2364
|
-
* Note : this prototype will be marked as deprecated and generate compilation warnings on reaching v1.5.x
|
|
2798
|
+
* reuse decompression parameters from previous init; saves dictionary loading
|
|
2365
2799
|
*/
|
|
2800
|
+
ZSTD_DEPRECATED("use ZSTD_DCtx_reset, see zstd.h for detailed instructions")
|
|
2366
2801
|
ZSTDLIB_STATIC_API size_t ZSTD_resetDStream(ZSTD_DStream* zds);
|
|
2367
2802
|
|
|
2368
2803
|
|
|
2804
|
+
/* ********************* BLOCK-LEVEL SEQUENCE PRODUCER API *********************
|
|
2805
|
+
*
|
|
2806
|
+
* *** OVERVIEW ***
|
|
2807
|
+
* The Block-Level Sequence Producer API allows users to provide their own custom
|
|
2808
|
+
* sequence producer which libzstd invokes to process each block. The produced list
|
|
2809
|
+
* of sequences (literals and matches) is then post-processed by libzstd to produce
|
|
2810
|
+
* valid compressed blocks.
|
|
2811
|
+
*
|
|
2812
|
+
* This block-level offload API is a more granular complement of the existing
|
|
2813
|
+
* frame-level offload API compressSequences() (introduced in v1.5.1). It offers
|
|
2814
|
+
* an easier migration story for applications already integrated with libzstd: the
|
|
2815
|
+
* user application continues to invoke the same compression functions
|
|
2816
|
+
* ZSTD_compress2() or ZSTD_compressStream2() as usual, and transparently benefits
|
|
2817
|
+
* from the specific advantages of the external sequence producer. For example,
|
|
2818
|
+
* the sequence producer could be tuned to take advantage of known characteristics
|
|
2819
|
+
* of the input, to offer better speed / ratio, or could leverage hardware
|
|
2820
|
+
* acceleration not available within libzstd itself.
|
|
2821
|
+
*
|
|
2822
|
+
* See contrib/externalSequenceProducer for an example program employing the
|
|
2823
|
+
* Block-Level Sequence Producer API.
|
|
2824
|
+
*
|
|
2825
|
+
* *** USAGE ***
|
|
2826
|
+
* The user is responsible for implementing a function of type
|
|
2827
|
+
* ZSTD_sequenceProducer_F. For each block, zstd will pass the following
|
|
2828
|
+
* arguments to the user-provided function:
|
|
2829
|
+
*
|
|
2830
|
+
* - sequenceProducerState: a pointer to a user-managed state for the sequence
|
|
2831
|
+
* producer.
|
|
2832
|
+
*
|
|
2833
|
+
* - outSeqs, outSeqsCapacity: an output buffer for the sequence producer.
|
|
2834
|
+
* outSeqsCapacity is guaranteed >= ZSTD_sequenceBound(srcSize). The memory
|
|
2835
|
+
* backing outSeqs is managed by the CCtx.
|
|
2836
|
+
*
|
|
2837
|
+
* - src, srcSize: an input buffer for the sequence producer to parse.
|
|
2838
|
+
* srcSize is guaranteed to be <= ZSTD_BLOCKSIZE_MAX.
|
|
2839
|
+
*
|
|
2840
|
+
* - dict, dictSize: a history buffer, which may be empty, which the sequence
|
|
2841
|
+
* producer may reference as it parses the src buffer. Currently, zstd will
|
|
2842
|
+
* always pass dictSize == 0 into external sequence producers, but this will
|
|
2843
|
+
* change in the future.
|
|
2844
|
+
*
|
|
2845
|
+
* - compressionLevel: a signed integer representing the zstd compression level
|
|
2846
|
+
* set by the user for the current operation. The sequence producer may choose
|
|
2847
|
+
* to use this information to change its compression strategy and speed/ratio
|
|
2848
|
+
* tradeoff. Note: the compression level does not reflect zstd parameters set
|
|
2849
|
+
* through the advanced API.
|
|
2850
|
+
*
|
|
2851
|
+
* - windowSize: a size_t representing the maximum allowed offset for external
|
|
2852
|
+
* sequences. Note that sequence offsets are sometimes allowed to exceed the
|
|
2853
|
+
* windowSize if a dictionary is present, see doc/zstd_compression_format.md
|
|
2854
|
+
* for details.
|
|
2855
|
+
*
|
|
2856
|
+
* The user-provided function shall return a size_t representing the number of
|
|
2857
|
+
* sequences written to outSeqs. This return value will be treated as an error
|
|
2858
|
+
* code if it is greater than outSeqsCapacity. The return value must be non-zero
|
|
2859
|
+
* if srcSize is non-zero. The ZSTD_SEQUENCE_PRODUCER_ERROR macro is provided
|
|
2860
|
+
* for convenience, but any value greater than outSeqsCapacity will be treated as
|
|
2861
|
+
* an error code.
|
|
2862
|
+
*
|
|
2863
|
+
* If the user-provided function does not return an error code, the sequences
|
|
2864
|
+
* written to outSeqs must be a valid parse of the src buffer. Data corruption may
|
|
2865
|
+
* occur if the parse is not valid. A parse is defined to be valid if the
|
|
2866
|
+
* following conditions hold:
|
|
2867
|
+
* - The sum of matchLengths and literalLengths must equal srcSize.
|
|
2868
|
+
* - All sequences in the parse, except for the final sequence, must have
|
|
2869
|
+
* matchLength >= ZSTD_MINMATCH_MIN. The final sequence must have
|
|
2870
|
+
* matchLength >= ZSTD_MINMATCH_MIN or matchLength == 0.
|
|
2871
|
+
* - All offsets must respect the windowSize parameter as specified in
|
|
2872
|
+
* doc/zstd_compression_format.md.
|
|
2873
|
+
* - If the final sequence has matchLength == 0, it must also have offset == 0.
|
|
2874
|
+
*
|
|
2875
|
+
* zstd will only validate these conditions (and fail compression if they do not
|
|
2876
|
+
* hold) if the ZSTD_c_validateSequences cParam is enabled. Note that sequence
|
|
2877
|
+
* validation has a performance cost.
|
|
2878
|
+
*
|
|
2879
|
+
* If the user-provided function returns an error, zstd will either fall back
|
|
2880
|
+
* to an internal sequence producer or fail the compression operation. The user can
|
|
2881
|
+
* choose between the two behaviors by setting the ZSTD_c_enableSeqProducerFallback
|
|
2882
|
+
* cParam. Fallback compression will follow any other cParam settings, such as
|
|
2883
|
+
* compression level, the same as in a normal compression operation.
|
|
2884
|
+
*
|
|
2885
|
+
* The user shall instruct zstd to use a particular ZSTD_sequenceProducer_F
|
|
2886
|
+
* function by calling
|
|
2887
|
+
* ZSTD_registerSequenceProducer(cctx,
|
|
2888
|
+
* sequenceProducerState,
|
|
2889
|
+
* sequenceProducer)
|
|
2890
|
+
* This setting will persist until the next parameter reset of the CCtx.
|
|
2891
|
+
*
|
|
2892
|
+
* The sequenceProducerState must be initialized by the user before calling
|
|
2893
|
+
* ZSTD_registerSequenceProducer(). The user is responsible for destroying the
|
|
2894
|
+
* sequenceProducerState.
|
|
2895
|
+
*
|
|
2896
|
+
* *** LIMITATIONS ***
|
|
2897
|
+
* This API is compatible with all zstd compression APIs which respect advanced parameters.
|
|
2898
|
+
* However, there are three limitations:
|
|
2899
|
+
*
|
|
2900
|
+
* First, the ZSTD_c_enableLongDistanceMatching cParam is not currently supported.
|
|
2901
|
+
* COMPRESSION WILL FAIL if it is enabled and the user tries to compress with a block-level
|
|
2902
|
+
* external sequence producer.
|
|
2903
|
+
* - Note that ZSTD_c_enableLongDistanceMatching is auto-enabled by default in some
|
|
2904
|
+
* cases (see its documentation for details). Users must explicitly set
|
|
2905
|
+
* ZSTD_c_enableLongDistanceMatching to ZSTD_ps_disable in such cases if an external
|
|
2906
|
+
* sequence producer is registered.
|
|
2907
|
+
* - As of this writing, ZSTD_c_enableLongDistanceMatching is disabled by default
|
|
2908
|
+
* whenever ZSTD_c_windowLog < 128MB, but that's subject to change. Users should
|
|
2909
|
+
* check the docs on ZSTD_c_enableLongDistanceMatching whenever the Block-Level Sequence
|
|
2910
|
+
* Producer API is used in conjunction with advanced settings (like ZSTD_c_windowLog).
|
|
2911
|
+
*
|
|
2912
|
+
* Second, history buffers are not currently supported. Concretely, zstd will always pass
|
|
2913
|
+
* dictSize == 0 to the external sequence producer (for now). This has two implications:
|
|
2914
|
+
* - Dictionaries are not currently supported. Compression will *not* fail if the user
|
|
2915
|
+
* references a dictionary, but the dictionary won't have any effect.
|
|
2916
|
+
* - Stream history is not currently supported. All advanced compression APIs, including
|
|
2917
|
+
* streaming APIs, work with external sequence producers, but each block is treated as
|
|
2918
|
+
* an independent chunk without history from previous blocks.
|
|
2919
|
+
*
|
|
2920
|
+
* Third, multi-threading within a single compression is not currently supported. In other words,
|
|
2921
|
+
* COMPRESSION WILL FAIL if ZSTD_c_nbWorkers > 0 and an external sequence producer is registered.
|
|
2922
|
+
* Multi-threading across compressions is fine: simply create one CCtx per thread.
|
|
2923
|
+
*
|
|
2924
|
+
* Long-term, we plan to overcome all three limitations. There is no technical blocker to
|
|
2925
|
+
* overcoming them. It is purely a question of engineering effort.
|
|
2926
|
+
*/
|
|
2927
|
+
|
|
2928
|
+
#define ZSTD_SEQUENCE_PRODUCER_ERROR ((size_t)(-1))
|
|
2929
|
+
|
|
2930
|
+
typedef size_t (*ZSTD_sequenceProducer_F) (
|
|
2931
|
+
void* sequenceProducerState,
|
|
2932
|
+
ZSTD_Sequence* outSeqs, size_t outSeqsCapacity,
|
|
2933
|
+
const void* src, size_t srcSize,
|
|
2934
|
+
const void* dict, size_t dictSize,
|
|
2935
|
+
int compressionLevel,
|
|
2936
|
+
size_t windowSize
|
|
2937
|
+
);
|
|
2938
|
+
|
|
2939
|
+
/*! ZSTD_registerSequenceProducer() :
|
|
2940
|
+
* Instruct zstd to use a block-level external sequence producer function.
|
|
2941
|
+
*
|
|
2942
|
+
* The sequenceProducerState must be initialized by the caller, and the caller is
|
|
2943
|
+
* responsible for managing its lifetime. This parameter is sticky across
|
|
2944
|
+
* compressions. It will remain set until the user explicitly resets compression
|
|
2945
|
+
* parameters.
|
|
2946
|
+
*
|
|
2947
|
+
* Sequence producer registration is considered to be an "advanced parameter",
|
|
2948
|
+
* part of the "advanced API". This means it will only have an effect on compression
|
|
2949
|
+
* APIs which respect advanced parameters, such as compress2() and compressStream2().
|
|
2950
|
+
* Older compression APIs such as compressCCtx(), which predate the introduction of
|
|
2951
|
+
* "advanced parameters", will ignore any external sequence producer setting.
|
|
2952
|
+
*
|
|
2953
|
+
* The sequence producer can be "cleared" by registering a NULL function pointer. This
|
|
2954
|
+
* removes all limitations described above in the "LIMITATIONS" section of the API docs.
|
|
2955
|
+
*
|
|
2956
|
+
* The user is strongly encouraged to read the full API documentation (above) before
|
|
2957
|
+
* calling this function. */
|
|
2958
|
+
ZSTDLIB_STATIC_API void
|
|
2959
|
+
ZSTD_registerSequenceProducer(
|
|
2960
|
+
ZSTD_CCtx* cctx,
|
|
2961
|
+
void* sequenceProducerState,
|
|
2962
|
+
ZSTD_sequenceProducer_F sequenceProducer
|
|
2963
|
+
);
|
|
2964
|
+
|
|
2965
|
+
/*! ZSTD_CCtxParams_registerSequenceProducer() :
|
|
2966
|
+
* Same as ZSTD_registerSequenceProducer(), but operates on ZSTD_CCtx_params.
|
|
2967
|
+
* This is used for accurate size estimation with ZSTD_estimateCCtxSize_usingCCtxParams(),
|
|
2968
|
+
* which is needed when creating a ZSTD_CCtx with ZSTD_initStaticCCtx().
|
|
2969
|
+
*
|
|
2970
|
+
* If you are using the external sequence producer API in a scenario where ZSTD_initStaticCCtx()
|
|
2971
|
+
* is required, then this function is for you. Otherwise, you probably don't need it.
|
|
2972
|
+
*
|
|
2973
|
+
* See tests/zstreamtest.c for example usage. */
|
|
2974
|
+
ZSTDLIB_STATIC_API void
|
|
2975
|
+
ZSTD_CCtxParams_registerSequenceProducer(
|
|
2976
|
+
ZSTD_CCtx_params* params,
|
|
2977
|
+
void* sequenceProducerState,
|
|
2978
|
+
ZSTD_sequenceProducer_F sequenceProducer
|
|
2979
|
+
);
|
|
2980
|
+
|
|
2981
|
+
|
|
2369
2982
|
/*********************************************************************
|
|
2370
|
-
* Buffer-less and synchronous inner streaming functions
|
|
2983
|
+
* Buffer-less and synchronous inner streaming functions (DEPRECATED)
|
|
2371
2984
|
*
|
|
2372
|
-
* This
|
|
2373
|
-
*
|
|
2374
|
-
*
|
|
2985
|
+
* This API is deprecated, and will be removed in a future version.
|
|
2986
|
+
* It allows streaming (de)compression with user allocated buffers.
|
|
2987
|
+
* However, it is hard to use, and not as well tested as the rest of
|
|
2988
|
+
* our API.
|
|
2989
|
+
*
|
|
2990
|
+
* Please use the normal streaming API instead: ZSTD_compressStream2,
|
|
2991
|
+
* and ZSTD_decompressStream.
|
|
2992
|
+
* If there is functionality that you need, but it doesn't provide,
|
|
2993
|
+
* please open an issue on our GitHub.
|
|
2375
2994
|
********************************************************************* */
|
|
2376
2995
|
|
|
2377
2996
|
/**
|
|
@@ -2379,11 +2998,10 @@ ZSTDLIB_STATIC_API size_t ZSTD_resetDStream(ZSTD_DStream* zds);
|
|
|
2379
2998
|
|
|
2380
2999
|
A ZSTD_CCtx object is required to track streaming operations.
|
|
2381
3000
|
Use ZSTD_createCCtx() / ZSTD_freeCCtx() to manage resource.
|
|
2382
|
-
ZSTD_CCtx object can be
|
|
3001
|
+
ZSTD_CCtx object can be reused multiple times within successive compression operations.
|
|
2383
3002
|
|
|
2384
3003
|
Start by initializing a context.
|
|
2385
3004
|
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
3005
|
|
|
2388
3006
|
Then, consume your input using ZSTD_compressContinue().
|
|
2389
3007
|
There are some important considerations to keep in mind when using this advanced function :
|
|
@@ -2401,39 +3019,49 @@ ZSTDLIB_STATIC_API size_t ZSTD_resetDStream(ZSTD_DStream* zds);
|
|
|
2401
3019
|
It's possible to use srcSize==0, in which case, it will write a final empty block to end the frame.
|
|
2402
3020
|
Without last block mark, frames are considered unfinished (hence corrupted) by compliant decoders.
|
|
2403
3021
|
|
|
2404
|
-
`ZSTD_CCtx` object can be
|
|
3022
|
+
`ZSTD_CCtx` object can be reused (ZSTD_compressBegin()) to compress again.
|
|
2405
3023
|
*/
|
|
2406
3024
|
|
|
2407
3025
|
/*===== Buffer-less streaming compression functions =====*/
|
|
3026
|
+
ZSTD_DEPRECATED("The buffer-less API is deprecated in favor of the normal streaming API. See docs.")
|
|
2408
3027
|
ZSTDLIB_STATIC_API size_t ZSTD_compressBegin(ZSTD_CCtx* cctx, int compressionLevel);
|
|
3028
|
+
ZSTD_DEPRECATED("The buffer-less API is deprecated in favor of the normal streaming API. See docs.")
|
|
2409
3029
|
ZSTDLIB_STATIC_API size_t ZSTD_compressBegin_usingDict(ZSTD_CCtx* cctx, const void* dict, size_t dictSize, int compressionLevel);
|
|
3030
|
+
ZSTD_DEPRECATED("The buffer-less API is deprecated in favor of the normal streaming API. See docs.")
|
|
2410
3031
|
ZSTDLIB_STATIC_API size_t ZSTD_compressBegin_usingCDict(ZSTD_CCtx* cctx, const ZSTD_CDict* cdict); /**< note: fails if cdict==NULL */
|
|
2411
|
-
ZSTDLIB_STATIC_API 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
3032
|
|
|
3033
|
+
ZSTD_DEPRECATED("This function will likely be removed in a future release. It is misleading and has very limited utility.")
|
|
3034
|
+
ZSTDLIB_STATIC_API
|
|
3035
|
+
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 */
|
|
3036
|
+
|
|
3037
|
+
ZSTD_DEPRECATED("The buffer-less API is deprecated in favor of the normal streaming API. See docs.")
|
|
2413
3038
|
ZSTDLIB_STATIC_API size_t ZSTD_compressContinue(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize);
|
|
3039
|
+
ZSTD_DEPRECATED("The buffer-less API is deprecated in favor of the normal streaming API. See docs.")
|
|
2414
3040
|
ZSTDLIB_STATIC_API size_t ZSTD_compressEnd(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize);
|
|
2415
3041
|
|
|
2416
3042
|
/* The ZSTD_compressBegin_advanced() and ZSTD_compressBegin_usingCDict_advanced() are now DEPRECATED and will generate a compiler warning */
|
|
2417
3043
|
ZSTD_DEPRECATED("use advanced API to access custom parameters")
|
|
3044
|
+
ZSTDLIB_STATIC_API
|
|
2418
3045
|
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
3046
|
ZSTD_DEPRECATED("use advanced API to access custom parameters")
|
|
3047
|
+
ZSTDLIB_STATIC_API
|
|
2420
3048
|
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
3049
|
/**
|
|
2422
3050
|
Buffer-less streaming decompression (synchronous mode)
|
|
2423
3051
|
|
|
2424
3052
|
A ZSTD_DCtx object is required to track streaming operations.
|
|
2425
3053
|
Use ZSTD_createDCtx() / ZSTD_freeDCtx() to manage it.
|
|
2426
|
-
A ZSTD_DCtx object can be
|
|
3054
|
+
A ZSTD_DCtx object can be reused multiple times.
|
|
2427
3055
|
|
|
2428
3056
|
First typical operation is to retrieve frame parameters, using ZSTD_getFrameHeader().
|
|
2429
3057
|
Frame header is extracted from the beginning of compressed frame, so providing only the frame's beginning is enough.
|
|
2430
3058
|
Data fragment must be large enough to ensure successful decoding.
|
|
2431
3059
|
`ZSTD_frameHeaderSize_max` bytes is guaranteed to always be large enough.
|
|
2432
|
-
|
|
2433
|
-
>0 : `srcSize` is too small, please provide at least
|
|
3060
|
+
result : 0 : successful decoding, the `ZSTD_frameHeader` structure is correctly filled.
|
|
3061
|
+
>0 : `srcSize` is too small, please provide at least result bytes on next attempt.
|
|
2434
3062
|
errorCode, which can be tested using ZSTD_isError().
|
|
2435
3063
|
|
|
2436
|
-
It fills a
|
|
3064
|
+
It fills a ZSTD_FrameHeader structure with important information to correctly decode the frame,
|
|
2437
3065
|
such as the dictionary ID, content size, or maximum back-reference distance (`windowSize`).
|
|
2438
3066
|
Note that these values could be wrong, either because of data corruption, or because a 3rd party deliberately spoofs false information.
|
|
2439
3067
|
As a consequence, check that values remain within valid application range.
|
|
@@ -2449,7 +3077,7 @@ size_t ZSTD_compressBegin_usingCDict_advanced(ZSTD_CCtx* const cctx, const ZSTD_
|
|
|
2449
3077
|
|
|
2450
3078
|
The most memory efficient way is to use a round buffer of sufficient size.
|
|
2451
3079
|
Sufficient size is determined by invoking ZSTD_decodingBufferSize_min(),
|
|
2452
|
-
which can
|
|
3080
|
+
which can return an error code if required value is too large for current system (in 32-bits mode).
|
|
2453
3081
|
In a round buffer methodology, ZSTD_decompressContinue() decompresses each block next to previous one,
|
|
2454
3082
|
up to the moment there is not enough room left in the buffer to guarantee decoding another full block,
|
|
2455
3083
|
which maximum size is provided in `ZSTD_frameHeader` structure, field `blockSizeMax`.
|
|
@@ -2469,7 +3097,7 @@ size_t ZSTD_compressBegin_usingCDict_advanced(ZSTD_CCtx* const cctx, const ZSTD_
|
|
|
2469
3097
|
ZSTD_nextSrcSizeToDecompress() tells how many bytes to provide as 'srcSize' to ZSTD_decompressContinue().
|
|
2470
3098
|
ZSTD_decompressContinue() requires this _exact_ amount of bytes, or it will fail.
|
|
2471
3099
|
|
|
2472
|
-
|
|
3100
|
+
result of ZSTD_decompressContinue() is the number of bytes regenerated within 'dst' (necessarily <= dstCapacity).
|
|
2473
3101
|
It can be zero : it just means ZSTD_decompressContinue() has decoded some metadata item.
|
|
2474
3102
|
It can also be an error code, which can be tested with ZSTD_isError().
|
|
2475
3103
|
|
|
@@ -2492,27 +3120,7 @@ size_t ZSTD_compressBegin_usingCDict_advanced(ZSTD_CCtx* const cctx, const ZSTD_
|
|
|
2492
3120
|
*/
|
|
2493
3121
|
|
|
2494
3122
|
/*===== Buffer-less streaming decompression functions =====*/
|
|
2495
|
-
typedef enum { ZSTD_frame, ZSTD_skippableFrame } ZSTD_frameType_e;
|
|
2496
|
-
typedef struct {
|
|
2497
|
-
unsigned long long frameContentSize; /* if == ZSTD_CONTENTSIZE_UNKNOWN, it means this field is not available. 0 means "empty" */
|
|
2498
|
-
unsigned long long windowSize; /* can be very large, up to <= frameContentSize */
|
|
2499
|
-
unsigned blockSizeMax;
|
|
2500
|
-
ZSTD_frameType_e frameType; /* if == ZSTD_skippableFrame, frameContentSize is the size of skippable content */
|
|
2501
|
-
unsigned headerSize;
|
|
2502
|
-
unsigned dictID;
|
|
2503
|
-
unsigned checksumFlag;
|
|
2504
|
-
} ZSTD_frameHeader;
|
|
2505
3123
|
|
|
2506
|
-
/*! ZSTD_getFrameHeader() :
|
|
2507
|
-
* decode Frame Header, or requires larger `srcSize`.
|
|
2508
|
-
* @return : 0, `zfhPtr` is correctly filled,
|
|
2509
|
-
* >0, `srcSize` is too small, value is wanted `srcSize` amount,
|
|
2510
|
-
* or an error code, which can be tested using ZSTD_isError() */
|
|
2511
|
-
ZSTDLIB_STATIC_API size_t ZSTD_getFrameHeader(ZSTD_frameHeader* zfhPtr, const void* src, size_t srcSize); /**< doesn't consume input */
|
|
2512
|
-
/*! ZSTD_getFrameHeader_advanced() :
|
|
2513
|
-
* same as ZSTD_getFrameHeader(),
|
|
2514
|
-
* with added capability to select a format (like ZSTD_f_zstd1_magicless) */
|
|
2515
|
-
ZSTDLIB_STATIC_API size_t ZSTD_getFrameHeader_advanced(ZSTD_frameHeader* zfhPtr, const void* src, size_t srcSize, ZSTD_format_e format);
|
|
2516
3124
|
ZSTDLIB_STATIC_API size_t ZSTD_decodingBufferSize_min(unsigned long long windowSize, unsigned long long frameContentSize); /**< when frame content size is not known, pass in frameContentSize == ZSTD_CONTENTSIZE_UNKNOWN */
|
|
2517
3125
|
|
|
2518
3126
|
ZSTDLIB_STATIC_API size_t ZSTD_decompressBegin(ZSTD_DCtx* dctx);
|
|
@@ -2523,6 +3131,7 @@ ZSTDLIB_STATIC_API size_t ZSTD_nextSrcSizeToDecompress(ZSTD_DCtx* dctx);
|
|
|
2523
3131
|
ZSTDLIB_STATIC_API size_t ZSTD_decompressContinue(ZSTD_DCtx* dctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize);
|
|
2524
3132
|
|
|
2525
3133
|
/* misc */
|
|
3134
|
+
ZSTD_DEPRECATED("This function will likely be removed in the next minor release. It is misleading and has very limited utility.")
|
|
2526
3135
|
ZSTDLIB_STATIC_API void ZSTD_copyDCtx(ZSTD_DCtx* dctx, const ZSTD_DCtx* preparedDCtx);
|
|
2527
3136
|
typedef enum { ZSTDnit_frameHeader, ZSTDnit_blockHeader, ZSTDnit_block, ZSTDnit_lastBlock, ZSTDnit_checksum, ZSTDnit_skippableFrame } ZSTD_nextInputType_e;
|
|
2528
3137
|
ZSTDLIB_STATIC_API ZSTD_nextInputType_e ZSTD_nextInputType(ZSTD_DCtx* dctx);
|
|
@@ -2530,11 +3139,23 @@ ZSTDLIB_STATIC_API ZSTD_nextInputType_e ZSTD_nextInputType(ZSTD_DCtx* dctx);
|
|
|
2530
3139
|
|
|
2531
3140
|
|
|
2532
3141
|
|
|
2533
|
-
/*
|
|
2534
|
-
/** Block level API */
|
|
2535
|
-
/*
|
|
3142
|
+
/* ========================================= */
|
|
3143
|
+
/** Block level API (DEPRECATED) */
|
|
3144
|
+
/* ========================================= */
|
|
2536
3145
|
|
|
2537
3146
|
/*!
|
|
3147
|
+
|
|
3148
|
+
This API is deprecated in favor of the regular compression API.
|
|
3149
|
+
You can get the frame header down to 2 bytes by setting:
|
|
3150
|
+
- ZSTD_c_format = ZSTD_f_zstd1_magicless
|
|
3151
|
+
- ZSTD_c_contentSizeFlag = 0
|
|
3152
|
+
- ZSTD_c_checksumFlag = 0
|
|
3153
|
+
- ZSTD_c_dictIDFlag = 0
|
|
3154
|
+
|
|
3155
|
+
This API is not as well tested as our normal API, so we recommend not using it.
|
|
3156
|
+
We will be removing it in a future version. If the normal API doesn't provide
|
|
3157
|
+
the functionality you need, please open a GitHub issue.
|
|
3158
|
+
|
|
2538
3159
|
Block functions produce and decode raw zstd blocks, without frame metadata.
|
|
2539
3160
|
Frame metadata cost is typically ~12 bytes, which can be non-negligible for very small blocks (< 100 bytes).
|
|
2540
3161
|
But users will have to take in charge needed metadata to regenerate data, such as compressed and content sizes.
|
|
@@ -2545,7 +3166,6 @@ ZSTDLIB_STATIC_API ZSTD_nextInputType_e ZSTD_nextInputType(ZSTD_DCtx* dctx);
|
|
|
2545
3166
|
- It is necessary to init context before starting
|
|
2546
3167
|
+ compression : any ZSTD_compressBegin*() variant, including with dictionary
|
|
2547
3168
|
+ decompression : any ZSTD_decompressBegin*() variant, including with dictionary
|
|
2548
|
-
+ copyCCtx() and copyDCtx() can be used too
|
|
2549
3169
|
- Block size is limited, it must be <= ZSTD_getBlockSize() <= ZSTD_BLOCKSIZE_MAX == 128 KB
|
|
2550
3170
|
+ If input is larger than a block size, it's necessary to split input data into multiple blocks
|
|
2551
3171
|
+ For inputs larger than a single block, consider using regular ZSTD_compress() instead.
|
|
@@ -2562,14 +3182,17 @@ ZSTDLIB_STATIC_API ZSTD_nextInputType_e ZSTD_nextInputType(ZSTD_DCtx* dctx);
|
|
|
2562
3182
|
*/
|
|
2563
3183
|
|
|
2564
3184
|
/*===== Raw zstd block functions =====*/
|
|
3185
|
+
ZSTD_DEPRECATED("The block API is deprecated in favor of the normal compression API. See docs.")
|
|
2565
3186
|
ZSTDLIB_STATIC_API size_t ZSTD_getBlockSize (const ZSTD_CCtx* cctx);
|
|
3187
|
+
ZSTD_DEPRECATED("The block API is deprecated in favor of the normal compression API. See docs.")
|
|
2566
3188
|
ZSTDLIB_STATIC_API size_t ZSTD_compressBlock (ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize);
|
|
3189
|
+
ZSTD_DEPRECATED("The block API is deprecated in favor of the normal compression API. See docs.")
|
|
2567
3190
|
ZSTDLIB_STATIC_API size_t ZSTD_decompressBlock(ZSTD_DCtx* dctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize);
|
|
3191
|
+
ZSTD_DEPRECATED("The block API is deprecated in favor of the normal compression API. See docs.")
|
|
2568
3192
|
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
3193
|
|
|
2570
|
-
|
|
2571
|
-
#endif /* ZSTD_H_ZSTD_STATIC_LINKING_ONLY */
|
|
2572
|
-
|
|
2573
3194
|
#if defined (__cplusplus)
|
|
2574
3195
|
}
|
|
2575
3196
|
#endif
|
|
3197
|
+
|
|
3198
|
+
#endif /* ZSTD_H_ZSTD_STATIC_LINKING_ONLY */
|