extzstd 0.0.3.CONCEPT → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/HISTORY.ja.md +39 -0
- data/LICENSE +6 -6
- data/README.md +26 -45
- data/contrib/zstd/CHANGELOG +555 -0
- data/contrib/zstd/CODE_OF_CONDUCT.md +5 -0
- data/contrib/zstd/CONTRIBUTING.md +392 -0
- data/contrib/zstd/COPYING +339 -0
- data/contrib/zstd/LICENSE +13 -9
- data/contrib/zstd/Makefile +414 -0
- data/contrib/zstd/README.md +170 -45
- data/contrib/zstd/TESTING.md +44 -0
- data/contrib/zstd/appveyor.yml +289 -0
- data/contrib/zstd/lib/BUCK +234 -0
- data/contrib/zstd/lib/Makefile +354 -0
- data/contrib/zstd/lib/README.md +179 -0
- data/contrib/zstd/{common → lib/common}/bitstream.h +170 -130
- data/contrib/zstd/lib/common/compiler.h +175 -0
- data/contrib/zstd/lib/common/cpu.h +215 -0
- data/contrib/zstd/lib/common/debug.c +24 -0
- data/contrib/zstd/lib/common/debug.h +114 -0
- data/contrib/zstd/{common → lib/common}/entropy_common.c +79 -94
- data/contrib/zstd/lib/common/error_private.c +55 -0
- data/contrib/zstd/lib/common/error_private.h +80 -0
- data/contrib/zstd/{common → lib/common}/fse.h +153 -93
- data/contrib/zstd/{common → lib/common}/fse_decompress.c +37 -82
- data/contrib/zstd/lib/common/huf.h +340 -0
- data/contrib/zstd/{common → lib/common}/mem.h +154 -78
- data/contrib/zstd/lib/common/pool.c +344 -0
- data/contrib/zstd/lib/common/pool.h +84 -0
- data/contrib/zstd/lib/common/threading.c +121 -0
- data/contrib/zstd/lib/common/threading.h +155 -0
- data/contrib/zstd/{common → lib/common}/xxhash.c +85 -75
- data/contrib/zstd/{common → lib/common}/xxhash.h +85 -73
- data/contrib/zstd/lib/common/zstd_common.c +83 -0
- data/contrib/zstd/lib/common/zstd_errors.h +94 -0
- data/contrib/zstd/lib/common/zstd_internal.h +447 -0
- data/contrib/zstd/{compress → lib/compress}/fse_compress.c +194 -303
- data/contrib/zstd/lib/compress/hist.c +183 -0
- data/contrib/zstd/lib/compress/hist.h +75 -0
- data/contrib/zstd/lib/compress/huf_compress.c +798 -0
- data/contrib/zstd/lib/compress/zstd_compress.c +4278 -0
- data/contrib/zstd/lib/compress/zstd_compress_internal.h +1125 -0
- data/contrib/zstd/lib/compress/zstd_compress_literals.c +158 -0
- data/contrib/zstd/lib/compress/zstd_compress_literals.h +29 -0
- data/contrib/zstd/lib/compress/zstd_compress_sequences.c +419 -0
- data/contrib/zstd/lib/compress/zstd_compress_sequences.h +54 -0
- data/contrib/zstd/lib/compress/zstd_compress_superblock.c +845 -0
- data/contrib/zstd/lib/compress/zstd_compress_superblock.h +32 -0
- data/contrib/zstd/lib/compress/zstd_cwksp.h +525 -0
- data/contrib/zstd/lib/compress/zstd_double_fast.c +521 -0
- data/contrib/zstd/lib/compress/zstd_double_fast.h +38 -0
- data/contrib/zstd/lib/compress/zstd_fast.c +496 -0
- data/contrib/zstd/lib/compress/zstd_fast.h +37 -0
- data/contrib/zstd/lib/compress/zstd_lazy.c +1138 -0
- data/contrib/zstd/lib/compress/zstd_lazy.h +67 -0
- data/contrib/zstd/lib/compress/zstd_ldm.c +619 -0
- data/contrib/zstd/lib/compress/zstd_ldm.h +110 -0
- data/contrib/zstd/lib/compress/zstd_opt.c +1200 -0
- data/contrib/zstd/lib/compress/zstd_opt.h +56 -0
- data/contrib/zstd/lib/compress/zstdmt_compress.c +2143 -0
- data/contrib/zstd/lib/compress/zstdmt_compress.h +192 -0
- data/contrib/zstd/lib/decompress/huf_decompress.c +1248 -0
- data/contrib/zstd/lib/decompress/zstd_ddict.c +244 -0
- data/contrib/zstd/lib/decompress/zstd_ddict.h +44 -0
- data/contrib/zstd/lib/decompress/zstd_decompress.c +1885 -0
- data/contrib/zstd/lib/decompress/zstd_decompress_block.c +1432 -0
- data/contrib/zstd/lib/decompress/zstd_decompress_block.h +59 -0
- data/contrib/zstd/lib/decompress/zstd_decompress_internal.h +189 -0
- data/contrib/zstd/{common → lib/deprecated}/zbuff.h +86 -69
- data/contrib/zstd/lib/deprecated/zbuff_common.c +26 -0
- data/contrib/zstd/lib/deprecated/zbuff_compress.c +147 -0
- data/contrib/zstd/lib/deprecated/zbuff_decompress.c +75 -0
- data/contrib/zstd/lib/dictBuilder/cover.c +1236 -0
- data/contrib/zstd/lib/dictBuilder/cover.h +157 -0
- data/contrib/zstd/{dictBuilder → lib/dictBuilder}/divsufsort.c +3 -3
- data/contrib/zstd/{dictBuilder → lib/dictBuilder}/divsufsort.h +5 -5
- data/contrib/zstd/lib/dictBuilder/fastcover.c +757 -0
- data/contrib/zstd/{dictBuilder → lib/dictBuilder}/zdict.c +437 -347
- data/contrib/zstd/lib/dictBuilder/zdict.h +305 -0
- data/contrib/zstd/lib/legacy/zstd_legacy.h +415 -0
- data/contrib/zstd/{legacy → lib/legacy}/zstd_v01.c +272 -292
- data/contrib/zstd/{legacy → lib/legacy}/zstd_v01.h +26 -32
- data/contrib/zstd/{legacy → lib/legacy}/zstd_v02.c +162 -392
- data/contrib/zstd/{legacy → lib/legacy}/zstd_v02.h +26 -32
- data/contrib/zstd/{legacy → lib/legacy}/zstd_v03.c +162 -391
- data/contrib/zstd/{legacy → lib/legacy}/zstd_v03.h +27 -33
- data/contrib/zstd/{legacy → lib/legacy}/zstd_v04.c +195 -604
- data/contrib/zstd/{legacy → lib/legacy}/zstd_v04.h +26 -32
- data/contrib/zstd/{legacy → lib/legacy}/zstd_v05.c +300 -575
- data/contrib/zstd/{legacy → lib/legacy}/zstd_v05.h +22 -31
- data/contrib/zstd/{legacy → lib/legacy}/zstd_v06.c +165 -592
- data/contrib/zstd/{legacy → lib/legacy}/zstd_v06.h +54 -67
- data/contrib/zstd/lib/legacy/zstd_v07.c +4541 -0
- data/contrib/zstd/lib/legacy/zstd_v07.h +187 -0
- data/contrib/zstd/lib/libzstd.pc.in +15 -0
- data/contrib/zstd/lib/zstd.h +2090 -0
- data/ext/depend +2 -0
- data/ext/extconf.rb +18 -5
- data/ext/extzstd.c +296 -214
- data/ext/extzstd.h +81 -36
- data/ext/extzstd_nogvls.h +0 -117
- data/ext/extzstd_stream.c +622 -0
- data/ext/libzstd_conf.h +8 -0
- data/ext/zstd_common.c +11 -0
- data/ext/zstd_compress.c +15 -0
- data/ext/zstd_decompress.c +6 -0
- data/ext/zstd_dictbuilder.c +10 -0
- data/ext/zstd_dictbuilder_fastcover.c +3 -0
- data/ext/zstd_legacy_v01.c +3 -1
- data/ext/zstd_legacy_v02.c +3 -1
- data/ext/zstd_legacy_v03.c +3 -1
- data/ext/zstd_legacy_v04.c +3 -1
- data/ext/zstd_legacy_v05.c +3 -1
- data/ext/zstd_legacy_v06.c +3 -1
- data/ext/zstd_legacy_v07.c +3 -0
- data/gemstub.rb +27 -21
- data/lib/extzstd.rb +82 -161
- data/lib/extzstd/version.rb +1 -1
- data/test/test_basic.rb +19 -6
- metadata +127 -59
- data/contrib/zstd/common/error_private.h +0 -125
- data/contrib/zstd/common/error_public.h +0 -77
- data/contrib/zstd/common/huf.h +0 -228
- data/contrib/zstd/common/zstd.h +0 -475
- data/contrib/zstd/common/zstd_common.c +0 -91
- data/contrib/zstd/common/zstd_internal.h +0 -238
- data/contrib/zstd/compress/huf_compress.c +0 -577
- data/contrib/zstd/compress/zbuff_compress.c +0 -327
- data/contrib/zstd/compress/zstd_compress.c +0 -3074
- data/contrib/zstd/compress/zstd_opt.h +0 -1046
- data/contrib/zstd/decompress/huf_decompress.c +0 -894
- data/contrib/zstd/decompress/zbuff_decompress.c +0 -294
- data/contrib/zstd/decompress/zstd_decompress.c +0 -1362
- data/contrib/zstd/dictBuilder/zdict.h +0 -113
- data/contrib/zstd/legacy/zstd_legacy.h +0 -140
- data/ext/extzstd_buffered.c +0 -265
- data/ext/zstd_amalgam.c +0 -18
data/contrib/zstd/common/huf.h
DELETED
@@ -1,228 +0,0 @@
|
|
1
|
-
/* ******************************************************************
|
2
|
-
Huffman coder, part of New Generation Entropy library
|
3
|
-
header file
|
4
|
-
Copyright (C) 2013-2016, Yann Collet.
|
5
|
-
|
6
|
-
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
7
|
-
|
8
|
-
Redistribution and use in source and binary forms, with or without
|
9
|
-
modification, are permitted provided that the following conditions are
|
10
|
-
met:
|
11
|
-
|
12
|
-
* Redistributions of source code must retain the above copyright
|
13
|
-
notice, this list of conditions and the following disclaimer.
|
14
|
-
* Redistributions in binary form must reproduce the above
|
15
|
-
copyright notice, this list of conditions and the following disclaimer
|
16
|
-
in the documentation and/or other materials provided with the
|
17
|
-
distribution.
|
18
|
-
|
19
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
20
|
-
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
21
|
-
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
22
|
-
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
23
|
-
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
24
|
-
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
25
|
-
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
26
|
-
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
27
|
-
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
28
|
-
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
29
|
-
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30
|
-
|
31
|
-
You can contact the author at :
|
32
|
-
- Source repository : https://github.com/Cyan4973/FiniteStateEntropy
|
33
|
-
****************************************************************** */
|
34
|
-
#ifndef HUF_H_298734234
|
35
|
-
#define HUF_H_298734234
|
36
|
-
|
37
|
-
#if defined (__cplusplus)
|
38
|
-
extern "C" {
|
39
|
-
#endif
|
40
|
-
|
41
|
-
|
42
|
-
/* *** Dependencies *** */
|
43
|
-
#include <stddef.h> /* size_t */
|
44
|
-
|
45
|
-
|
46
|
-
/* *** simple functions *** */
|
47
|
-
/**
|
48
|
-
HUF_compress() :
|
49
|
-
Compress content from buffer 'src', of size 'srcSize', into buffer 'dst'.
|
50
|
-
'dst' buffer must be already allocated.
|
51
|
-
Compression runs faster if `dstCapacity` >= HUF_compressBound(srcSize).
|
52
|
-
`srcSize` must be <= `HUF_BLOCKSIZE_MAX` == 128 KB.
|
53
|
-
@return : size of compressed data (<= `dstCapacity`).
|
54
|
-
Special values : if return == 0, srcData is not compressible => Nothing is stored within dst !!!
|
55
|
-
if return == 1, srcData is a single repeated byte symbol (RLE compression).
|
56
|
-
if HUF_isError(return), compression failed (more details using HUF_getErrorName())
|
57
|
-
*/
|
58
|
-
size_t HUF_compress(void* dst, size_t dstCapacity,
|
59
|
-
const void* src, size_t srcSize);
|
60
|
-
|
61
|
-
/**
|
62
|
-
HUF_decompress() :
|
63
|
-
Decompress HUF data from buffer 'cSrc', of size 'cSrcSize',
|
64
|
-
into already allocated buffer 'dst', of minimum size 'dstSize'.
|
65
|
-
`dstSize` : **must** be the ***exact*** size of original (uncompressed) data.
|
66
|
-
Note : in contrast with FSE, HUF_decompress can regenerate
|
67
|
-
RLE (cSrcSize==1) and uncompressed (cSrcSize==dstSize) data,
|
68
|
-
because it knows size to regenerate.
|
69
|
-
@return : size of regenerated data (== dstSize),
|
70
|
-
or an error code, which can be tested using HUF_isError()
|
71
|
-
*/
|
72
|
-
size_t HUF_decompress(void* dst, size_t dstSize,
|
73
|
-
const void* cSrc, size_t cSrcSize);
|
74
|
-
|
75
|
-
|
76
|
-
/* ****************************************
|
77
|
-
* Tool functions
|
78
|
-
******************************************/
|
79
|
-
#define HUF_BLOCKSIZE_MAX (128 * 1024)
|
80
|
-
size_t HUF_compressBound(size_t size); /**< maximum compressed size (worst case) */
|
81
|
-
|
82
|
-
/* Error Management */
|
83
|
-
unsigned HUF_isError(size_t code); /**< tells if a return value is an error code */
|
84
|
-
const char* HUF_getErrorName(size_t code); /**< provides error code string (useful for debugging) */
|
85
|
-
|
86
|
-
|
87
|
-
/* *** Advanced function *** */
|
88
|
-
|
89
|
-
/** HUF_compress2() :
|
90
|
-
* Same as HUF_compress(), but offers direct control over `maxSymbolValue` and `tableLog` */
|
91
|
-
size_t HUF_compress2 (void* dst, size_t dstSize, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog);
|
92
|
-
|
93
|
-
|
94
|
-
#ifdef HUF_STATIC_LINKING_ONLY
|
95
|
-
|
96
|
-
/* *** Dependencies *** */
|
97
|
-
#include "mem.h" /* U32 */
|
98
|
-
|
99
|
-
|
100
|
-
/* *** Constants *** */
|
101
|
-
#define HUF_TABLELOG_ABSOLUTEMAX 16 /* absolute limit of HUF_MAX_TABLELOG. Beyond that value, code does not work */
|
102
|
-
#define HUF_TABLELOG_MAX 12 /* max configured tableLog (for static allocation); can be modified up to HUF_ABSOLUTEMAX_TABLELOG */
|
103
|
-
#define HUF_TABLELOG_DEFAULT HUF_TABLELOG_MAX /* tableLog by default, when not specified */
|
104
|
-
#define HUF_SYMBOLVALUE_MAX 255
|
105
|
-
#if (HUF_TABLELOG_MAX > HUF_TABLELOG_ABSOLUTEMAX)
|
106
|
-
# error "HUF_TABLELOG_MAX is too large !"
|
107
|
-
#endif
|
108
|
-
|
109
|
-
|
110
|
-
/* ****************************************
|
111
|
-
* Static allocation
|
112
|
-
******************************************/
|
113
|
-
/* HUF buffer bounds */
|
114
|
-
#define HUF_CTABLEBOUND 129
|
115
|
-
#define HUF_BLOCKBOUND(size) (size + (size>>8) + 8) /* only true if incompressible pre-filtered with fast heuristic */
|
116
|
-
#define HUF_COMPRESSBOUND(size) (HUF_CTABLEBOUND + HUF_BLOCKBOUND(size)) /* Macro version, useful for static allocation */
|
117
|
-
|
118
|
-
/* static allocation of HUF's Compression Table */
|
119
|
-
#define HUF_CREATE_STATIC_CTABLE(name, maxSymbolValue) \
|
120
|
-
U32 name##hb[maxSymbolValue+1]; \
|
121
|
-
void* name##hv = &(name##hb); \
|
122
|
-
HUF_CElt* name = (HUF_CElt*)(name##hv) /* no final ; */
|
123
|
-
|
124
|
-
/* static allocation of HUF's DTable */
|
125
|
-
typedef U32 HUF_DTable;
|
126
|
-
#define HUF_DTABLE_SIZE(maxTableLog) (1 + (1<<(maxTableLog)))
|
127
|
-
#define HUF_CREATE_STATIC_DTABLEX2(DTable, maxTableLog) \
|
128
|
-
HUF_DTable DTable[HUF_DTABLE_SIZE((maxTableLog)-1)] = { ((U32)((maxTableLog)-1)*0x1000001) }
|
129
|
-
#define HUF_CREATE_STATIC_DTABLEX4(DTable, maxTableLog) \
|
130
|
-
HUF_DTable DTable[HUF_DTABLE_SIZE(maxTableLog)] = { ((U32)(maxTableLog)*0x1000001) }
|
131
|
-
|
132
|
-
|
133
|
-
/* ****************************************
|
134
|
-
* Advanced decompression functions
|
135
|
-
******************************************/
|
136
|
-
size_t HUF_decompress4X2 (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< single-symbol decoder */
|
137
|
-
size_t HUF_decompress4X4 (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< double-symbols decoder */
|
138
|
-
|
139
|
-
size_t HUF_decompress4X_DCtx (HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< decodes RLE and uncompressed */
|
140
|
-
size_t HUF_decompress4X_hufOnly(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< considers RLE and uncompressed as errors */
|
141
|
-
size_t HUF_decompress4X2_DCtx(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< single-symbol decoder */
|
142
|
-
size_t HUF_decompress4X4_DCtx(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< double-symbols decoder */
|
143
|
-
|
144
|
-
size_t HUF_decompress1X_DCtx (HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize);
|
145
|
-
size_t HUF_decompress1X2_DCtx(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< single-symbol decoder */
|
146
|
-
size_t HUF_decompress1X4_DCtx(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< double-symbols decoder */
|
147
|
-
|
148
|
-
|
149
|
-
/* ****************************************
|
150
|
-
* HUF detailed API
|
151
|
-
******************************************/
|
152
|
-
/*!
|
153
|
-
HUF_compress() does the following:
|
154
|
-
1. count symbol occurrence from source[] into table count[] using FSE_count()
|
155
|
-
2. (optional) refine tableLog using HUF_optimalTableLog()
|
156
|
-
3. build Huffman table from count using HUF_buildCTable()
|
157
|
-
4. save Huffman table to memory buffer using HUF_writeCTable()
|
158
|
-
5. encode the data stream using HUF_compress4X_usingCTable()
|
159
|
-
|
160
|
-
The following API allows targeting specific sub-functions for advanced tasks.
|
161
|
-
For example, it's possible to compress several blocks using the same 'CTable',
|
162
|
-
or to save and regenerate 'CTable' using external methods.
|
163
|
-
*/
|
164
|
-
/* FSE_count() : find it within "fse.h" */
|
165
|
-
unsigned HUF_optimalTableLog(unsigned maxTableLog, size_t srcSize, unsigned maxSymbolValue);
|
166
|
-
typedef struct HUF_CElt_s HUF_CElt; /* incomplete type */
|
167
|
-
size_t HUF_buildCTable (HUF_CElt* CTable, const unsigned* count, unsigned maxSymbolValue, unsigned maxNbBits);
|
168
|
-
size_t HUF_writeCTable (void* dst, size_t maxDstSize, const HUF_CElt* CTable, unsigned maxSymbolValue, unsigned huffLog);
|
169
|
-
size_t HUF_compress4X_usingCTable(void* dst, size_t dstSize, const void* src, size_t srcSize, const HUF_CElt* CTable);
|
170
|
-
|
171
|
-
|
172
|
-
/*! HUF_readStats() :
|
173
|
-
Read compact Huffman tree, saved by HUF_writeCTable().
|
174
|
-
`huffWeight` is destination buffer.
|
175
|
-
@return : size read from `src` , or an error Code .
|
176
|
-
Note : Needed by HUF_readCTable() and HUF_readDTableXn() . */
|
177
|
-
size_t HUF_readStats(BYTE* huffWeight, size_t hwSize, U32* rankStats,
|
178
|
-
U32* nbSymbolsPtr, U32* tableLogPtr,
|
179
|
-
const void* src, size_t srcSize);
|
180
|
-
|
181
|
-
/** HUF_readCTable() :
|
182
|
-
* Loading a CTable saved with HUF_writeCTable() */
|
183
|
-
size_t HUF_readCTable (HUF_CElt* CTable, unsigned maxSymbolValue, const void* src, size_t srcSize);
|
184
|
-
|
185
|
-
|
186
|
-
/*
|
187
|
-
HUF_decompress() does the following:
|
188
|
-
1. select the decompression algorithm (X2, X4) based on pre-computed heuristics
|
189
|
-
2. build Huffman table from save, using HUF_readDTableXn()
|
190
|
-
3. decode 1 or 4 segments in parallel using HUF_decompressSXn_usingDTable
|
191
|
-
*/
|
192
|
-
|
193
|
-
/** HUF_selectDecoder() :
|
194
|
-
* Tells which decoder is likely to decode faster,
|
195
|
-
* based on a set of pre-determined metrics.
|
196
|
-
* @return : 0==HUF_decompress4X2, 1==HUF_decompress4X4 .
|
197
|
-
* Assumption : 0 < cSrcSize < dstSize <= 128 KB */
|
198
|
-
U32 HUF_selectDecoder (size_t dstSize, size_t cSrcSize);
|
199
|
-
|
200
|
-
size_t HUF_readDTableX2 (HUF_DTable* DTable, const void* src, size_t srcSize);
|
201
|
-
size_t HUF_readDTableX4 (HUF_DTable* DTable, const void* src, size_t srcSize);
|
202
|
-
|
203
|
-
size_t HUF_decompress4X_usingDTable(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable);
|
204
|
-
size_t HUF_decompress4X2_usingDTable(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable);
|
205
|
-
size_t HUF_decompress4X4_usingDTable(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable);
|
206
|
-
|
207
|
-
|
208
|
-
/* single stream variants */
|
209
|
-
|
210
|
-
size_t HUF_compress1X (void* dst, size_t dstSize, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog);
|
211
|
-
size_t HUF_compress1X_usingCTable(void* dst, size_t dstSize, const void* src, size_t srcSize, const HUF_CElt* CTable);
|
212
|
-
|
213
|
-
size_t HUF_decompress1X2 (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /* single-symbol decoder */
|
214
|
-
size_t HUF_decompress1X4 (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /* double-symbol decoder */
|
215
|
-
|
216
|
-
size_t HUF_decompress1X_usingDTable(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable);
|
217
|
-
size_t HUF_decompress1X2_usingDTable(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable);
|
218
|
-
size_t HUF_decompress1X4_usingDTable(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable);
|
219
|
-
|
220
|
-
|
221
|
-
#endif /* HUF_STATIC_LINKING_ONLY */
|
222
|
-
|
223
|
-
|
224
|
-
#if defined (__cplusplus)
|
225
|
-
}
|
226
|
-
#endif
|
227
|
-
|
228
|
-
#endif /* HUF_H_298734234 */
|
data/contrib/zstd/common/zstd.h
DELETED
@@ -1,475 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
zstd - standard compression library
|
3
|
-
Header File
|
4
|
-
Copyright (C) 2014-2016, Yann Collet.
|
5
|
-
|
6
|
-
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
7
|
-
|
8
|
-
Redistribution and use in source and binary forms, with or without
|
9
|
-
modification, are permitted provided that the following conditions are
|
10
|
-
met:
|
11
|
-
* Redistributions of source code must retain the above copyright
|
12
|
-
notice, this list of conditions and the following disclaimer.
|
13
|
-
* Redistributions in binary form must reproduce the above
|
14
|
-
copyright notice, this list of conditions and the following disclaimer
|
15
|
-
in the documentation and/or other materials provided with the
|
16
|
-
distribution.
|
17
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
18
|
-
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
19
|
-
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
20
|
-
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
21
|
-
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
22
|
-
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
23
|
-
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
24
|
-
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
25
|
-
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
26
|
-
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
27
|
-
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
28
|
-
|
29
|
-
You can contact the author at :
|
30
|
-
- zstd source repository : https://github.com/Cyan4973/zstd
|
31
|
-
*/
|
32
|
-
#ifndef ZSTD_H_235446
|
33
|
-
#define ZSTD_H_235446
|
34
|
-
|
35
|
-
#if defined (__cplusplus)
|
36
|
-
extern "C" {
|
37
|
-
#endif
|
38
|
-
|
39
|
-
/*-*************************************
|
40
|
-
* Dependencies
|
41
|
-
***************************************/
|
42
|
-
#include <stddef.h> /* size_t */
|
43
|
-
|
44
|
-
|
45
|
-
/*-***************************************************************
|
46
|
-
* Export parameters
|
47
|
-
*****************************************************************/
|
48
|
-
/*!
|
49
|
-
* ZSTD_DLL_EXPORT :
|
50
|
-
* Enable exporting of functions when building a Windows DLL
|
51
|
-
*/
|
52
|
-
#if defined(_WIN32) && defined(ZSTD_DLL_EXPORT) && (ZSTD_DLL_EXPORT==1)
|
53
|
-
# define ZSTDLIB_API __declspec(dllexport)
|
54
|
-
#else
|
55
|
-
# define ZSTDLIB_API
|
56
|
-
#endif
|
57
|
-
|
58
|
-
|
59
|
-
/* *************************************
|
60
|
-
* Version
|
61
|
-
***************************************/
|
62
|
-
#define ZSTD_VERSION_MAJOR 0
|
63
|
-
#define ZSTD_VERSION_MINOR 7
|
64
|
-
#define ZSTD_VERSION_RELEASE 4
|
65
|
-
|
66
|
-
#define ZSTD_LIB_VERSION ZSTD_VERSION_MAJOR.ZSTD_VERSION_MINOR.ZSTD_VERSION_RELEASE
|
67
|
-
#define ZSTD_QUOTE(str) #str
|
68
|
-
#define ZSTD_EXPAND_AND_QUOTE(str) ZSTD_QUOTE(str)
|
69
|
-
#define ZSTD_VERSION_STRING ZSTD_EXPAND_AND_QUOTE(ZSTD_LIB_VERSION)
|
70
|
-
|
71
|
-
#define ZSTD_VERSION_NUMBER (ZSTD_VERSION_MAJOR *100*100 + ZSTD_VERSION_MINOR *100 + ZSTD_VERSION_RELEASE)
|
72
|
-
ZSTDLIB_API unsigned ZSTD_versionNumber (void);
|
73
|
-
|
74
|
-
|
75
|
-
/* *************************************
|
76
|
-
* Simple functions
|
77
|
-
***************************************/
|
78
|
-
/*! ZSTD_compress() :
|
79
|
-
Compresses `srcSize` bytes from buffer `src` into buffer `dst` of size `dstCapacity`.
|
80
|
-
Destination buffer must be already allocated.
|
81
|
-
Compression runs faster if `dstCapacity` >= `ZSTD_compressBound(srcSize)`.
|
82
|
-
@return : the number of bytes written into `dst`,
|
83
|
-
or an error code if it fails (which can be tested using ZSTD_isError()) */
|
84
|
-
ZSTDLIB_API size_t ZSTD_compress( void* dst, size_t dstCapacity,
|
85
|
-
const void* src, size_t srcSize,
|
86
|
-
int compressionLevel);
|
87
|
-
|
88
|
-
/** ZSTD_getDecompressedSize() :
|
89
|
-
* @return : decompressed size if known, 0 otherwise.
|
90
|
-
note : to know precise reason why result is `0`, follow up with ZSTD_getFrameParams() */
|
91
|
-
unsigned long long ZSTD_getDecompressedSize(const void* src, size_t srcSize);
|
92
|
-
|
93
|
-
/*! ZSTD_decompress() :
|
94
|
-
`compressedSize` : is the _exact_ size of compressed input, otherwise decompression will fail.
|
95
|
-
`dstCapacity` must be equal or larger than originalSize.
|
96
|
-
@return : the number of bytes decompressed into `dst` (<= `dstCapacity`),
|
97
|
-
or an errorCode if it fails (which can be tested using ZSTD_isError()) */
|
98
|
-
ZSTDLIB_API size_t ZSTD_decompress( void* dst, size_t dstCapacity,
|
99
|
-
const void* src, size_t compressedSize);
|
100
|
-
|
101
|
-
|
102
|
-
/* *************************************
|
103
|
-
* Helper functions
|
104
|
-
***************************************/
|
105
|
-
ZSTDLIB_API size_t ZSTD_compressBound(size_t srcSize); /*!< maximum compressed size (worst case scenario) */
|
106
|
-
|
107
|
-
/* Error Management */
|
108
|
-
ZSTDLIB_API unsigned ZSTD_isError(size_t code); /*!< tells if a `size_t` function result is an error code */
|
109
|
-
ZSTDLIB_API const char* ZSTD_getErrorName(size_t code); /*!< provides readable string for an error code */
|
110
|
-
|
111
|
-
|
112
|
-
/* *************************************
|
113
|
-
* Explicit memory management
|
114
|
-
***************************************/
|
115
|
-
/** Compression context */
|
116
|
-
typedef struct ZSTD_CCtx_s ZSTD_CCtx; /*< incomplete type */
|
117
|
-
ZSTDLIB_API ZSTD_CCtx* ZSTD_createCCtx(void);
|
118
|
-
ZSTDLIB_API size_t ZSTD_freeCCtx(ZSTD_CCtx* cctx); /*!< @return : errorCode */
|
119
|
-
|
120
|
-
/** ZSTD_compressCCtx() :
|
121
|
-
Same as ZSTD_compress(), but requires an already allocated ZSTD_CCtx (see ZSTD_createCCtx()) */
|
122
|
-
ZSTDLIB_API size_t ZSTD_compressCCtx(ZSTD_CCtx* ctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize, int compressionLevel);
|
123
|
-
|
124
|
-
/** Decompression context */
|
125
|
-
typedef struct ZSTD_DCtx_s ZSTD_DCtx;
|
126
|
-
ZSTDLIB_API ZSTD_DCtx* ZSTD_createDCtx(void);
|
127
|
-
ZSTDLIB_API size_t ZSTD_freeDCtx(ZSTD_DCtx* dctx); /*!< @return : errorCode */
|
128
|
-
|
129
|
-
/** ZSTD_decompressDCtx() :
|
130
|
-
* Same as ZSTD_decompress(), but requires an already allocated ZSTD_DCtx (see ZSTD_createDCtx()) */
|
131
|
-
ZSTDLIB_API size_t ZSTD_decompressDCtx(ZSTD_DCtx* ctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize);
|
132
|
-
|
133
|
-
|
134
|
-
/*-************************
|
135
|
-
* Simple dictionary API
|
136
|
-
***************************/
|
137
|
-
/*! ZSTD_compress_usingDict() :
|
138
|
-
* Compression using a pre-defined Dictionary content (see dictBuilder).
|
139
|
-
* Note 1 : This function load the dictionary, resulting in a significant startup time.
|
140
|
-
* Note 2 : `dict` must remain accessible and unmodified during compression operation.
|
141
|
-
* Note 3 : `dict` can be `NULL`, in which case, it's equivalent to ZSTD_compressCCtx() */
|
142
|
-
ZSTDLIB_API size_t ZSTD_compress_usingDict(ZSTD_CCtx* ctx,
|
143
|
-
void* dst, size_t dstCapacity,
|
144
|
-
const void* src, size_t srcSize,
|
145
|
-
const void* dict,size_t dictSize,
|
146
|
-
int compressionLevel);
|
147
|
-
|
148
|
-
/*! ZSTD_decompress_usingDict() :
|
149
|
-
* Decompression using a pre-defined Dictionary content (see dictBuilder).
|
150
|
-
* Dictionary must be identical to the one used during compression.
|
151
|
-
* Note 1 : This function load the dictionary, resulting in a significant startup time
|
152
|
-
* Note 2 : `dict` must remain accessible and unmodified during compression operation.
|
153
|
-
* Note 3 : `dict` can be `NULL`, in which case, it's equivalent to ZSTD_decompressDCtx() */
|
154
|
-
ZSTDLIB_API size_t ZSTD_decompress_usingDict(ZSTD_DCtx* dctx,
|
155
|
-
void* dst, size_t dstCapacity,
|
156
|
-
const void* src, size_t srcSize,
|
157
|
-
const void* dict,size_t dictSize);
|
158
|
-
|
159
|
-
|
160
|
-
/*-**************************
|
161
|
-
* Advanced Dictionary API
|
162
|
-
****************************/
|
163
|
-
/*! ZSTD_createCDict() :
|
164
|
-
* Create a digested dictionary, ready to start compression operation without startup delay.
|
165
|
-
* `dict` can be released after creation */
|
166
|
-
typedef struct ZSTD_CDict_s ZSTD_CDict;
|
167
|
-
ZSTDLIB_API ZSTD_CDict* ZSTD_createCDict(const void* dict, size_t dictSize, int compressionLevel);
|
168
|
-
ZSTDLIB_API size_t ZSTD_freeCDict(ZSTD_CDict* CDict);
|
169
|
-
|
170
|
-
/*! ZSTD_compress_usingCDict() :
|
171
|
-
* Compression using a pre-digested Dictionary.
|
172
|
-
* Much faster than ZSTD_compress_usingDict() when same dictionary is used multiple times.
|
173
|
-
* Note that compression level is decided during dictionary creation */
|
174
|
-
ZSTDLIB_API size_t ZSTD_compress_usingCDict(ZSTD_CCtx* cctx,
|
175
|
-
void* dst, size_t dstCapacity,
|
176
|
-
const void* src, size_t srcSize,
|
177
|
-
const ZSTD_CDict* cdict);
|
178
|
-
|
179
|
-
/*! ZSTD_createDDict() :
|
180
|
-
* Create a digested dictionary, ready to start decompression operation without startup delay.
|
181
|
-
* `dict` can be released after creation */
|
182
|
-
typedef struct ZSTD_DDict_s ZSTD_DDict;
|
183
|
-
ZSTDLIB_API ZSTD_DDict* ZSTD_createDDict(const void* dict, size_t dictSize);
|
184
|
-
ZSTDLIB_API size_t ZSTD_freeDDict(ZSTD_DDict* ddict);
|
185
|
-
|
186
|
-
/*! ZSTD_decompress_usingDDict() :
|
187
|
-
* Decompression using a pre-digested Dictionary
|
188
|
-
* Much faster than ZSTD_decompress_usingDict() when same dictionary is used multiple times. */
|
189
|
-
ZSTDLIB_API size_t ZSTD_decompress_usingDDict(ZSTD_DCtx* dctx,
|
190
|
-
void* dst, size_t dstCapacity,
|
191
|
-
const void* src, size_t srcSize,
|
192
|
-
const ZSTD_DDict* ddict);
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
#ifdef ZSTD_STATIC_LINKING_ONLY
|
197
|
-
|
198
|
-
/* ====================================================================================
|
199
|
-
* The definitions in this section are considered experimental.
|
200
|
-
* They should never be used with a dynamic library, as they may change in the future.
|
201
|
-
* They are provided for advanced usages.
|
202
|
-
* Use them only in association with static linking.
|
203
|
-
* ==================================================================================== */
|
204
|
-
|
205
|
-
/*--- Constants ---*/
|
206
|
-
#define ZSTD_MAGICNUMBER 0xFD2FB527 /* v0.7 */
|
207
|
-
#define ZSTD_MAGIC_SKIPPABLE_START 0x184D2A50U
|
208
|
-
|
209
|
-
#define ZSTD_WINDOWLOG_MAX_32 25
|
210
|
-
#define ZSTD_WINDOWLOG_MAX_64 27
|
211
|
-
#define ZSTD_WINDOWLOG_MAX ((U32)(MEM_32bits() ? ZSTD_WINDOWLOG_MAX_32 : ZSTD_WINDOWLOG_MAX_64))
|
212
|
-
#define ZSTD_WINDOWLOG_MIN 18
|
213
|
-
#define ZSTD_CHAINLOG_MAX (ZSTD_WINDOWLOG_MAX+1)
|
214
|
-
#define ZSTD_CHAINLOG_MIN 4
|
215
|
-
#define ZSTD_HASHLOG_MAX ZSTD_WINDOWLOG_MAX
|
216
|
-
#define ZSTD_HASHLOG_MIN 12
|
217
|
-
#define ZSTD_HASHLOG3_MAX 17
|
218
|
-
//#define ZSTD_HASHLOG3_MIN 15
|
219
|
-
#define ZSTD_SEARCHLOG_MAX (ZSTD_WINDOWLOG_MAX-1)
|
220
|
-
#define ZSTD_SEARCHLOG_MIN 1
|
221
|
-
#define ZSTD_SEARCHLENGTH_MAX 7
|
222
|
-
#define ZSTD_SEARCHLENGTH_MIN 3
|
223
|
-
#define ZSTD_TARGETLENGTH_MIN 4
|
224
|
-
#define ZSTD_TARGETLENGTH_MAX 999
|
225
|
-
|
226
|
-
#define ZSTD_FRAMEHEADERSIZE_MAX 18 /* for static allocation */
|
227
|
-
static const size_t ZSTD_frameHeaderSize_min = 5;
|
228
|
-
static const size_t ZSTD_frameHeaderSize_max = ZSTD_FRAMEHEADERSIZE_MAX;
|
229
|
-
static const size_t ZSTD_skippableHeaderSize = 8; /* magic number + skippable frame length */
|
230
|
-
|
231
|
-
|
232
|
-
/*--- Types ---*/
|
233
|
-
typedef enum { ZSTD_fast, ZSTD_dfast, ZSTD_greedy, ZSTD_lazy, ZSTD_lazy2, ZSTD_btlazy2, ZSTD_btopt } ZSTD_strategy; /*< from faster to stronger */
|
234
|
-
|
235
|
-
typedef struct {
|
236
|
-
unsigned windowLog; /*< largest match distance : larger == more compression, more memory needed during decompression */
|
237
|
-
unsigned chainLog; /*< fully searched segment : larger == more compression, slower, more memory (useless for fast) */
|
238
|
-
unsigned hashLog; /*< dispatch table : larger == faster, more memory */
|
239
|
-
unsigned searchLog; /*< nb of searches : larger == more compression, slower */
|
240
|
-
unsigned searchLength; /*< match length searched : larger == faster decompression, sometimes less compression */
|
241
|
-
unsigned targetLength; /*< acceptable match size for optimal parser (only) : larger == more compression, slower */
|
242
|
-
ZSTD_strategy strategy;
|
243
|
-
} ZSTD_compressionParameters;
|
244
|
-
|
245
|
-
typedef struct {
|
246
|
-
unsigned contentSizeFlag; /*< 1: content size will be in frame header (if known). */
|
247
|
-
unsigned checksumFlag; /*< 1: will generate a 22-bits checksum at end of frame, to be used for error detection by decompressor */
|
248
|
-
unsigned noDictIDFlag; /*< 1: no dict ID will be saved into frame header (if dictionary compression) */
|
249
|
-
} ZSTD_frameParameters;
|
250
|
-
|
251
|
-
typedef struct {
|
252
|
-
ZSTD_compressionParameters cParams;
|
253
|
-
ZSTD_frameParameters fParams;
|
254
|
-
} ZSTD_parameters;
|
255
|
-
|
256
|
-
/* custom memory allocation functions */
|
257
|
-
typedef void* (*ZSTD_allocFunction) (void* opaque, size_t size);
|
258
|
-
typedef void (*ZSTD_freeFunction) (void* opaque, void* address);
|
259
|
-
typedef struct { ZSTD_allocFunction customAlloc; ZSTD_freeFunction customFree; void* opaque; } ZSTD_customMem;
|
260
|
-
|
261
|
-
|
262
|
-
/*-*************************************
|
263
|
-
* Advanced compression functions
|
264
|
-
***************************************/
|
265
|
-
/*! ZSTD_estimateCCtxSize() :
|
266
|
-
* Gives the amount of memory allocated for a ZSTD_CCtx given a set of compression parameters.
|
267
|
-
* `frameContentSize` is an optional parameter, provide `0` if unknown */
|
268
|
-
ZSTDLIB_API size_t ZSTD_estimateCCtxSize(ZSTD_compressionParameters cParams);
|
269
|
-
|
270
|
-
/*! ZSTD_createCCtx_advanced() :
|
271
|
-
* Create a ZSTD compression context using external alloc and free functions */
|
272
|
-
ZSTDLIB_API ZSTD_CCtx* ZSTD_createCCtx_advanced(ZSTD_customMem customMem);
|
273
|
-
|
274
|
-
/*! ZSTD_createCDict_advanced() :
|
275
|
-
* Create a ZSTD_CDict using external alloc and free, and customized compression parameters */
|
276
|
-
ZSTDLIB_API ZSTD_CDict* ZSTD_createCDict_advanced(const void* dict, size_t dictSize,
|
277
|
-
ZSTD_parameters params, ZSTD_customMem customMem);
|
278
|
-
|
279
|
-
/*! ZSTD_sizeofCCtx() :
|
280
|
-
* Gives the amount of memory used by a given ZSTD_CCtx */
|
281
|
-
ZSTDLIB_API size_t ZSTD_sizeofCCtx(const ZSTD_CCtx* cctx);
|
282
|
-
|
283
|
-
ZSTDLIB_API unsigned ZSTD_maxCLevel (void);
|
284
|
-
|
285
|
-
/*! ZSTD_getParams() :
|
286
|
-
* same as ZSTD_getCParams(), but @return a full `ZSTD_parameters` object instead of a `ZSTD_compressionParameters`.
|
287
|
-
* All fields of `ZSTD_frameParameters` are set to default (0) */
|
288
|
-
ZSTD_parameters ZSTD_getParams(int compressionLevel, unsigned long long srcSize, size_t dictSize);
|
289
|
-
|
290
|
-
/*! ZSTD_getCParams() :
|
291
|
-
* @return ZSTD_compressionParameters structure for a selected compression level and srcSize.
|
292
|
-
* `srcSize` value is optional, select 0 if not known */
|
293
|
-
ZSTDLIB_API ZSTD_compressionParameters ZSTD_getCParams(int compressionLevel, unsigned long long srcSize, size_t dictSize);
|
294
|
-
|
295
|
-
/*! ZSTD_checkCParams() :
|
296
|
-
* Ensure param values remain within authorized range */
|
297
|
-
ZSTDLIB_API size_t ZSTD_checkCParams(ZSTD_compressionParameters params);
|
298
|
-
|
299
|
-
/*! ZSTD_adjustCParams() :
|
300
|
-
* optimize params for a given `srcSize` and `dictSize`.
|
301
|
-
* both values are optional, select `0` if unknown. */
|
302
|
-
ZSTDLIB_API ZSTD_compressionParameters ZSTD_adjustCParams(ZSTD_compressionParameters cPar, unsigned long long srcSize, size_t dictSize);
|
303
|
-
|
304
|
-
/*! ZSTD_compress_advanced() :
|
305
|
-
* Same as ZSTD_compress_usingDict(), with fine-tune control of each compression parameter */
|
306
|
-
ZSTDLIB_API size_t ZSTD_compress_advanced (ZSTD_CCtx* ctx,
|
307
|
-
void* dst, size_t dstCapacity,
|
308
|
-
const void* src, size_t srcSize,
|
309
|
-
const void* dict,size_t dictSize,
|
310
|
-
ZSTD_parameters params);
|
311
|
-
|
312
|
-
|
313
|
-
/*--- Advanced Decompression functions ---*/
|
314
|
-
|
315
|
-
/*! ZSTD_estimateDCtxSize() :
|
316
|
-
* Gives the potential amount of memory allocated to create a ZSTD_DCtx */
|
317
|
-
ZSTDLIB_API size_t ZSTD_estimateDCtxSize(void);
|
318
|
-
|
319
|
-
/*! ZSTD_createDCtx_advanced() :
|
320
|
-
* Create a ZSTD decompression context using external alloc and free functions */
|
321
|
-
ZSTDLIB_API ZSTD_DCtx* ZSTD_createDCtx_advanced(ZSTD_customMem customMem);
|
322
|
-
|
323
|
-
/*! ZSTD_sizeofDCtx() :
|
324
|
-
* Gives the amount of memory used by a given ZSTD_DCtx */
|
325
|
-
ZSTDLIB_API size_t ZSTD_sizeofDCtx(const ZSTD_DCtx* dctx);
|
326
|
-
|
327
|
-
|
328
|
-
/* ******************************************************************
|
329
|
-
* Streaming functions (direct mode - synchronous and buffer-less)
|
330
|
-
********************************************************************/
|
331
|
-
ZSTDLIB_API size_t ZSTD_compressBegin(ZSTD_CCtx* cctx, int compressionLevel);
|
332
|
-
ZSTDLIB_API size_t ZSTD_compressBegin_usingDict(ZSTD_CCtx* cctx, const void* dict, size_t dictSize, int compressionLevel);
|
333
|
-
ZSTDLIB_API size_t ZSTD_compressBegin_advanced(ZSTD_CCtx* cctx, const void* dict, size_t dictSize, ZSTD_parameters params, unsigned long long pledgedSrcSize);
|
334
|
-
ZSTDLIB_API size_t ZSTD_copyCCtx(ZSTD_CCtx* cctx, const ZSTD_CCtx* preparedCCtx);
|
335
|
-
|
336
|
-
ZSTDLIB_API size_t ZSTD_compressContinue(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize);
|
337
|
-
ZSTDLIB_API size_t ZSTD_compressEnd(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity);
|
338
|
-
|
339
|
-
/*
|
340
|
-
A ZSTD_CCtx object is required to track streaming operations.
|
341
|
-
Use ZSTD_createCCtx() / ZSTD_freeCCtx() to manage resource.
|
342
|
-
ZSTD_CCtx object can be re-used multiple times within successive compression operations.
|
343
|
-
|
344
|
-
Start by initializing a context.
|
345
|
-
Use ZSTD_compressBegin(), or ZSTD_compressBegin_usingDict() for dictionary compression,
|
346
|
-
or ZSTD_compressBegin_advanced(), for finer parameter control.
|
347
|
-
It's also possible to duplicate a reference context which has already been initialized, using ZSTD_copyCCtx()
|
348
|
-
|
349
|
-
Then, consume your input using ZSTD_compressContinue().
|
350
|
-
There are some important considerations to keep in mind when using this advanced function :
|
351
|
-
- ZSTD_compressContinue() has no internal buffer. It uses externally provided buffer only.
|
352
|
-
- Interface is synchronous : input is consumed entirely and produce 1 (or more) compressed blocks.
|
353
|
-
- Caller must ensure there is enough space in `dst` to store compressed data under worst case scenario.
|
354
|
-
Worst case evaluation is provided by ZSTD_compressBound().
|
355
|
-
ZSTD_compressContinue() doesn't guarantee recover after a failed compression.
|
356
|
-
- ZSTD_compressContinue() presumes prior input ***is still accessible and unmodified*** (up to maximum distance size, see WindowLog).
|
357
|
-
It remembers all previous contiguous blocks, plus one separated memory segment (which can itself consists of multiple contiguous blocks)
|
358
|
-
- ZSTD_compressContinue() detects that prior input has been overwritten when `src` buffer overlaps.
|
359
|
-
In which case, it will "discard" the relevant memory section from its history.
|
360
|
-
|
361
|
-
|
362
|
-
Finish a frame with ZSTD_compressEnd(), which will write the epilogue.
|
363
|
-
Without epilogue, frames will be considered unfinished (broken) by decoders.
|
364
|
-
|
365
|
-
You can then reuse `ZSTD_CCtx` (ZSTD_compressBegin()) to compress some new frame.
|
366
|
-
*/
|
367
|
-
|
368
|
-
typedef struct {
|
369
|
-
unsigned long long frameContentSize;
|
370
|
-
unsigned windowSize;
|
371
|
-
unsigned dictID;
|
372
|
-
unsigned checksumFlag;
|
373
|
-
} ZSTD_frameParams;
|
374
|
-
|
375
|
-
ZSTDLIB_API size_t ZSTD_getFrameParams(ZSTD_frameParams* fparamsPtr, const void* src, size_t srcSize); /**< doesn't consume input */
|
376
|
-
|
377
|
-
ZSTDLIB_API size_t ZSTD_decompressBegin(ZSTD_DCtx* dctx);
|
378
|
-
ZSTDLIB_API size_t ZSTD_decompressBegin_usingDict(ZSTD_DCtx* dctx, const void* dict, size_t dictSize);
|
379
|
-
ZSTDLIB_API void ZSTD_copyDCtx(ZSTD_DCtx* dctx, const ZSTD_DCtx* preparedDCtx);
|
380
|
-
|
381
|
-
ZSTDLIB_API size_t ZSTD_nextSrcSizeToDecompress(ZSTD_DCtx* dctx);
|
382
|
-
ZSTDLIB_API size_t ZSTD_decompressContinue(ZSTD_DCtx* dctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize);
|
383
|
-
|
384
|
-
/*
|
385
|
-
Streaming decompression, direct mode (bufferless)
|
386
|
-
|
387
|
-
A ZSTD_DCtx object is required to track streaming operations.
|
388
|
-
Use ZSTD_createDCtx() / ZSTD_freeDCtx() to manage it.
|
389
|
-
A ZSTD_DCtx object can be re-used multiple times.
|
390
|
-
|
391
|
-
First optional operation is to retrieve frame parameters, using ZSTD_getFrameParams(), which doesn't consume the input.
|
392
|
-
It can provide the minimum size of rolling buffer required to properly decompress data (`windowSize`),
|
393
|
-
and optionally the final size of uncompressed content.
|
394
|
-
(Note : content size is an optional info that may not be present. 0 means : content size unknown)
|
395
|
-
Frame parameters are extracted from the beginning of compressed frame.
|
396
|
-
The amount of data to read is variable, from ZSTD_frameHeaderSize_min to ZSTD_frameHeaderSize_max (so if `srcSize` >= ZSTD_frameHeaderSize_max, it will always work)
|
397
|
-
If `srcSize` is too small for operation to succeed, function will return the minimum size it requires to produce a result.
|
398
|
-
Result : 0 when successful, it means the ZSTD_frameParams structure has been filled.
|
399
|
-
>0 : means there is not enough data into `src`. Provides the expected size to successfully decode header.
|
400
|
-
errorCode, which can be tested using ZSTD_isError()
|
401
|
-
|
402
|
-
Start decompression, with ZSTD_decompressBegin() or ZSTD_decompressBegin_usingDict().
|
403
|
-
Alternatively, you can copy a prepared context, using ZSTD_copyDCtx().
|
404
|
-
|
405
|
-
Then use ZSTD_nextSrcSizeToDecompress() and ZSTD_decompressContinue() alternatively.
|
406
|
-
ZSTD_nextSrcSizeToDecompress() tells how much bytes to provide as 'srcSize' to ZSTD_decompressContinue().
|
407
|
-
ZSTD_decompressContinue() requires this exact amount of bytes, or it will fail.
|
408
|
-
|
409
|
-
@result of ZSTD_decompressContinue() is the number of bytes regenerated within 'dst' (necessarily <= dstCapacity).
|
410
|
-
It can be zero, which is not an error; it just means ZSTD_decompressContinue() has decoded some header.
|
411
|
-
|
412
|
-
ZSTD_decompressContinue() needs previous data blocks during decompression, up to `windowSize`.
|
413
|
-
They should preferably be located contiguously, prior to current block.
|
414
|
-
Alternatively, a round buffer of sufficient size is also possible. Sufficient size is determined by frame parameters.
|
415
|
-
ZSTD_decompressContinue() is very sensitive to contiguity,
|
416
|
-
if 2 blocks don't follow each other, make sure that either the compressor breaks contiguity at the same place,
|
417
|
-
or that previous contiguous segment is large enough to properly handle maximum back-reference.
|
418
|
-
|
419
|
-
A frame is fully decoded when ZSTD_nextSrcSizeToDecompress() returns zero.
|
420
|
-
Context can then be reset to start a new decompression.
|
421
|
-
|
422
|
-
|
423
|
-
== Special case : skippable frames ==
|
424
|
-
|
425
|
-
Skippable frames allow the integration of user-defined data into a flow of concatenated frames.
|
426
|
-
Skippable frames will be ignored (skipped) by a decompressor. The format of skippable frame is following:
|
427
|
-
a) Skippable frame ID - 4 Bytes, Little endian format, any value from 0x184D2A50 to 0x184D2A5F
|
428
|
-
b) Frame Size - 4 Bytes, Little endian format, unsigned 32-bits
|
429
|
-
c) Frame Content - any content (User Data) of length equal to Frame Size
|
430
|
-
For skippable frames ZSTD_decompressContinue() always returns 0.
|
431
|
-
For skippable frames ZSTD_getFrameParams() returns fparamsPtr->windowLog==0 what means that a frame is skippable.
|
432
|
-
It also returns Frame Size as fparamsPtr->frameContentSize.
|
433
|
-
*/
|
434
|
-
|
435
|
-
|
436
|
-
/* **************************************
|
437
|
-
* Block functions
|
438
|
-
****************************************/
|
439
|
-
/*! Block functions produce and decode raw zstd blocks, without frame metadata.
|
440
|
-
Frame metadata cost is typically ~18 bytes, which is non-negligible on very small blocks.
|
441
|
-
User will have to take in charge required information to regenerate data, such as compressed and content sizes.
|
442
|
-
|
443
|
-
A few rules to respect :
|
444
|
-
- Uncompressed block size must be <= MIN (128 KB, 1 << windowLog)
|
445
|
-
+ If you need to compress more, cut data into multiple blocks
|
446
|
-
+ Consider using the regular ZSTD_compress() instead, as frame metadata costs become negligible when source size is large.
|
447
|
-
- Compressing and decompressing require a context structure
|
448
|
-
+ Use ZSTD_createCCtx() and ZSTD_createDCtx()
|
449
|
-
- It is necessary to init context before starting
|
450
|
-
+ compression : ZSTD_compressBegin()
|
451
|
-
+ decompression : ZSTD_decompressBegin()
|
452
|
-
+ variants _usingDict() are also allowed
|
453
|
-
+ copyCCtx() and copyDCtx() work too
|
454
|
-
- When a block is considered not compressible enough, ZSTD_compressBlock() result will be zero.
|
455
|
-
In which case, nothing is produced into `dst`.
|
456
|
-
+ User must test for such outcome and deal directly with uncompressed data
|
457
|
-
+ ZSTD_decompressBlock() doesn't accept uncompressed data as input !!!
|
458
|
-
+ In case of multiple successive blocks, decoder must be informed of uncompressed block existence to follow proper history.
|
459
|
-
Use ZSTD_insertBlock() in such a case.
|
460
|
-
Insert block once it's copied into its final position.
|
461
|
-
*/
|
462
|
-
|
463
|
-
#define ZSTD_BLOCKSIZE_MAX (128 * 1024) /* define, for static allocation */
|
464
|
-
ZSTDLIB_API size_t ZSTD_compressBlock (ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize);
|
465
|
-
ZSTDLIB_API size_t ZSTD_decompressBlock(ZSTD_DCtx* dctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize);
|
466
|
-
ZSTDLIB_API size_t ZSTD_insertBlock(ZSTD_DCtx* dctx, const void* blockStart, size_t blockSize); /**< insert block into `dctx` history. Useful to track uncompressed blocks */
|
467
|
-
|
468
|
-
|
469
|
-
#endif /* ZSTD_STATIC_LINKING_ONLY */
|
470
|
-
|
471
|
-
#if defined (__cplusplus)
|
472
|
-
}
|
473
|
-
#endif
|
474
|
-
|
475
|
-
#endif /* ZSTD_H_235446 */
|