extzstd 0.0.2.CONCEPT → 0.0.3.CONCEPT
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +72 -22
- data/Rakefile +73 -19
- data/contrib/zstd/README.md +68 -0
- data/contrib/zstd/common/bitstream.h +414 -0
- data/contrib/zstd/common/entropy_common.c +231 -0
- data/contrib/zstd/common/error_private.h +125 -0
- data/contrib/zstd/common/error_public.h +77 -0
- data/contrib/zstd/common/fse.h +628 -0
- data/contrib/zstd/common/fse_decompress.c +331 -0
- data/contrib/zstd/common/huf.h +228 -0
- data/contrib/zstd/common/mem.h +377 -0
- data/contrib/zstd/common/xxhash.c +854 -0
- data/contrib/zstd/common/xxhash.h +273 -0
- data/contrib/zstd/common/zbuff.h +197 -0
- data/contrib/zstd/common/zstd.h +475 -0
- data/contrib/zstd/common/zstd_common.c +91 -0
- data/contrib/zstd/common/zstd_internal.h +238 -0
- data/contrib/zstd/compress/fse_compress.c +807 -0
- data/contrib/zstd/compress/huf_compress.c +577 -0
- data/contrib/zstd/compress/zbuff_compress.c +327 -0
- data/contrib/zstd/compress/zstd_compress.c +3074 -0
- data/contrib/zstd/compress/zstd_opt.h +1046 -0
- data/contrib/zstd/decompress/huf_decompress.c +894 -0
- data/contrib/zstd/decompress/zbuff_decompress.c +294 -0
- data/contrib/zstd/decompress/zstd_decompress.c +1362 -0
- data/contrib/zstd/dictBuilder/divsufsort.c +1913 -0
- data/contrib/zstd/dictBuilder/divsufsort.h +67 -0
- data/contrib/zstd/dictBuilder/zdict.c +1045 -0
- data/contrib/zstd/dictBuilder/zdict.h +113 -0
- data/contrib/zstd/legacy/zstd_legacy.h +140 -0
- data/contrib/zstd/legacy/zstd_v01.c +2178 -0
- data/contrib/zstd/{zstd.h → legacy/zstd_v01.h} +46 -39
- data/contrib/zstd/legacy/zstd_v02.c +3748 -0
- data/contrib/zstd/legacy/zstd_v02.h +99 -0
- data/contrib/zstd/legacy/zstd_v03.c +3389 -0
- data/contrib/zstd/legacy/zstd_v03.h +99 -0
- data/contrib/zstd/legacy/zstd_v04.c +4056 -0
- data/contrib/zstd/legacy/zstd_v04.h +148 -0
- data/contrib/zstd/legacy/zstd_v05.c +4325 -0
- data/contrib/zstd/legacy/zstd_v05.h +171 -0
- data/contrib/zstd/legacy/zstd_v06.c +4581 -0
- data/contrib/zstd/legacy/zstd_v06.h +185 -0
- data/ext/extconf.rb +10 -12
- data/ext/extzstd.c +497 -144
- data/ext/extzstd.h +127 -22
- data/ext/extzstd_buffered.c +265 -0
- data/ext/extzstd_nogvls.h +174 -0
- data/ext/zstd_amalgam.c +18 -0
- data/ext/zstd_legacy_v01.c +1 -0
- data/ext/zstd_legacy_v02.c +1 -0
- data/ext/zstd_legacy_v03.c +1 -0
- data/ext/zstd_legacy_v04.c +1 -0
- data/ext/zstd_legacy_v05.c +1 -0
- data/ext/zstd_legacy_v06.c +1 -0
- data/gemstub.rb +17 -1
- data/lib/extzstd.rb +197 -77
- data/lib/extzstd/version.rb +1 -1
- data/test/test_basic.rb +41 -0
- metadata +70 -20
- data/contrib/zstd/Makefile +0 -115
- data/contrib/zstd/fse.c +0 -2466
- data/contrib/zstd/fse.h +0 -320
- data/contrib/zstd/fse_static.h +0 -282
- data/contrib/zstd/libzstd.pc.in +0 -14
- data/contrib/zstd/zstd.c +0 -1768
- data/contrib/zstd/zstd_static.h +0 -89
- data/ext/extzstd-stream.c +0 -398
@@ -0,0 +1,273 @@
|
|
1
|
+
/*
|
2
|
+
xxHash - Extremely Fast Hash algorithm
|
3
|
+
Header File
|
4
|
+
Copyright (C) 2012-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
|
+
- xxHash source repository : https://github.com/Cyan4973/xxHash
|
33
|
+
*/
|
34
|
+
|
35
|
+
/* Notice extracted from xxHash homepage :
|
36
|
+
|
37
|
+
xxHash is an extremely fast Hash algorithm, running at RAM speed limits.
|
38
|
+
It also successfully passes all tests from the SMHasher suite.
|
39
|
+
|
40
|
+
Comparison (single thread, Windows Seven 32 bits, using SMHasher on a Core 2 Duo @3GHz)
|
41
|
+
|
42
|
+
Name Speed Q.Score Author
|
43
|
+
xxHash 5.4 GB/s 10
|
44
|
+
CrapWow 3.2 GB/s 2 Andrew
|
45
|
+
MumurHash 3a 2.7 GB/s 10 Austin Appleby
|
46
|
+
SpookyHash 2.0 GB/s 10 Bob Jenkins
|
47
|
+
SBox 1.4 GB/s 9 Bret Mulvey
|
48
|
+
Lookup3 1.2 GB/s 9 Bob Jenkins
|
49
|
+
SuperFastHash 1.2 GB/s 1 Paul Hsieh
|
50
|
+
CityHash64 1.05 GB/s 10 Pike & Alakuijala
|
51
|
+
FNV 0.55 GB/s 5 Fowler, Noll, Vo
|
52
|
+
CRC32 0.43 GB/s 9
|
53
|
+
MD5-32 0.33 GB/s 10 Ronald L. Rivest
|
54
|
+
SHA1-32 0.28 GB/s 10
|
55
|
+
|
56
|
+
Q.Score is a measure of quality of the hash function.
|
57
|
+
It depends on successfully passing SMHasher test set.
|
58
|
+
10 is a perfect score.
|
59
|
+
|
60
|
+
A 64-bits version, named XXH64, is available since r35.
|
61
|
+
It offers much better speed, but for 64-bits applications only.
|
62
|
+
Name Speed on 64 bits Speed on 32 bits
|
63
|
+
XXH64 13.8 GB/s 1.9 GB/s
|
64
|
+
XXH32 6.8 GB/s 6.0 GB/s
|
65
|
+
*/
|
66
|
+
|
67
|
+
#ifndef XXHASH_H_5627135585666179
|
68
|
+
#define XXHASH_H_5627135585666179 1
|
69
|
+
|
70
|
+
#if defined (__cplusplus)
|
71
|
+
extern "C" {
|
72
|
+
#endif
|
73
|
+
|
74
|
+
|
75
|
+
/* ****************************
|
76
|
+
* Definitions
|
77
|
+
******************************/
|
78
|
+
#include <stddef.h> /* size_t */
|
79
|
+
typedef enum { XXH_OK=0, XXH_ERROR } XXH_errorcode;
|
80
|
+
|
81
|
+
|
82
|
+
/* ****************************
|
83
|
+
* API modifier
|
84
|
+
******************************/
|
85
|
+
/*!XXH_PRIVATE_API
|
86
|
+
* Transforms all publics symbols within `xxhash.c` into private ones.
|
87
|
+
* Methodology :
|
88
|
+
* instead of : #include "xxhash.h"
|
89
|
+
* do :
|
90
|
+
* #define XXH_PRIVATE_API
|
91
|
+
* #include "xxhash.c" // note the .c , instead of .h
|
92
|
+
* also : don't compile and link xxhash.c separately
|
93
|
+
*/
|
94
|
+
#ifdef XXH_PRIVATE_API
|
95
|
+
# if defined(__GNUC__)
|
96
|
+
# define XXH_PUBLIC_API static __attribute__((unused))
|
97
|
+
# elif defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
|
98
|
+
# define XXH_PUBLIC_API static inline
|
99
|
+
# elif defined(_MSC_VER)
|
100
|
+
# define XXH_PUBLIC_API static __inline
|
101
|
+
# else
|
102
|
+
# define XXH_PUBLIC_API static /* this version may generate warnings for unused static functions; disable the relevant warning */
|
103
|
+
# endif
|
104
|
+
#else
|
105
|
+
# define XXH_PUBLIC_API /* do nothing */
|
106
|
+
#endif
|
107
|
+
|
108
|
+
/*!XXH_NAMESPACE, aka Namespace Emulation :
|
109
|
+
|
110
|
+
If you want to include _and expose_ xxHash functions from within your own library,
|
111
|
+
but also want to avoid symbol collisions with another library which also includes xxHash,
|
112
|
+
|
113
|
+
you can use XXH_NAMESPACE, to automatically prefix any public symbol from `xxhash.c`
|
114
|
+
with the value of XXH_NAMESPACE (so avoid to keep it NULL and avoid numeric values).
|
115
|
+
|
116
|
+
Note that no change is required within the calling program as long as it also includes `xxhash.h` :
|
117
|
+
regular symbol name will be automatically translated by this header.
|
118
|
+
*/
|
119
|
+
#ifdef XXH_NAMESPACE
|
120
|
+
# define XXH_CAT(A,B) A##B
|
121
|
+
# define XXH_NAME2(A,B) XXH_CAT(A,B)
|
122
|
+
# define XXH32 XXH_NAME2(XXH_NAMESPACE, XXH32)
|
123
|
+
# define XXH64 XXH_NAME2(XXH_NAMESPACE, XXH64)
|
124
|
+
# define XXH_versionNumber XXH_NAME2(XXH_NAMESPACE, XXH_versionNumber)
|
125
|
+
# define XXH32_createState XXH_NAME2(XXH_NAMESPACE, XXH32_createState)
|
126
|
+
# define XXH64_createState XXH_NAME2(XXH_NAMESPACE, XXH64_createState)
|
127
|
+
# define XXH32_freeState XXH_NAME2(XXH_NAMESPACE, XXH32_freeState)
|
128
|
+
# define XXH64_freeState XXH_NAME2(XXH_NAMESPACE, XXH64_freeState)
|
129
|
+
# define XXH32_reset XXH_NAME2(XXH_NAMESPACE, XXH32_reset)
|
130
|
+
# define XXH64_reset XXH_NAME2(XXH_NAMESPACE, XXH64_reset)
|
131
|
+
# define XXH32_update XXH_NAME2(XXH_NAMESPACE, XXH32_update)
|
132
|
+
# define XXH64_update XXH_NAME2(XXH_NAMESPACE, XXH64_update)
|
133
|
+
# define XXH32_digest XXH_NAME2(XXH_NAMESPACE, XXH32_digest)
|
134
|
+
# define XXH64_digest XXH_NAME2(XXH_NAMESPACE, XXH64_digest)
|
135
|
+
#endif
|
136
|
+
|
137
|
+
|
138
|
+
/* *************************************
|
139
|
+
* Version
|
140
|
+
***************************************/
|
141
|
+
#define XXH_VERSION_MAJOR 0
|
142
|
+
#define XXH_VERSION_MINOR 6
|
143
|
+
#define XXH_VERSION_RELEASE 0
|
144
|
+
#define XXH_VERSION_NUMBER (XXH_VERSION_MAJOR *100*100 + XXH_VERSION_MINOR *100 + XXH_VERSION_RELEASE)
|
145
|
+
XXH_PUBLIC_API unsigned XXH_versionNumber (void);
|
146
|
+
|
147
|
+
|
148
|
+
/* ****************************
|
149
|
+
* Simple Hash Functions
|
150
|
+
******************************/
|
151
|
+
typedef unsigned int XXH32_hash_t;
|
152
|
+
typedef unsigned long long XXH64_hash_t;
|
153
|
+
|
154
|
+
XXH_PUBLIC_API XXH32_hash_t XXH32 (const void* input, size_t length, unsigned int seed);
|
155
|
+
XXH_PUBLIC_API XXH64_hash_t XXH64 (const void* input, size_t length, unsigned long long seed);
|
156
|
+
|
157
|
+
/*!
|
158
|
+
XXH32() :
|
159
|
+
Calculate the 32-bits hash of sequence "length" bytes stored at memory address "input".
|
160
|
+
The memory between input & input+length must be valid (allocated and read-accessible).
|
161
|
+
"seed" can be used to alter the result predictably.
|
162
|
+
Speed on Core 2 Duo @ 3 GHz (single thread, SMHasher benchmark) : 5.4 GB/s
|
163
|
+
XXH64() :
|
164
|
+
Calculate the 64-bits hash of sequence of length "len" stored at memory address "input".
|
165
|
+
"seed" can be used to alter the result predictably.
|
166
|
+
This function runs faster on 64-bits systems, but slower on 32-bits systems (see benchmark).
|
167
|
+
*/
|
168
|
+
|
169
|
+
|
170
|
+
/* ****************************
|
171
|
+
* Streaming Hash Functions
|
172
|
+
******************************/
|
173
|
+
typedef struct XXH32_state_s XXH32_state_t; /* incomplete type */
|
174
|
+
typedef struct XXH64_state_s XXH64_state_t; /* incomplete type */
|
175
|
+
|
176
|
+
/*! Dynamic allocation of states
|
177
|
+
Compatible with dynamic libraries */
|
178
|
+
|
179
|
+
XXH_PUBLIC_API XXH32_state_t* XXH32_createState(void);
|
180
|
+
XXH_PUBLIC_API XXH_errorcode XXH32_freeState(XXH32_state_t* statePtr);
|
181
|
+
|
182
|
+
XXH_PUBLIC_API XXH64_state_t* XXH64_createState(void);
|
183
|
+
XXH_PUBLIC_API XXH_errorcode XXH64_freeState(XXH64_state_t* statePtr);
|
184
|
+
|
185
|
+
|
186
|
+
/* hash streaming */
|
187
|
+
|
188
|
+
XXH_PUBLIC_API XXH_errorcode XXH32_reset (XXH32_state_t* statePtr, unsigned int seed);
|
189
|
+
XXH_PUBLIC_API XXH_errorcode XXH32_update (XXH32_state_t* statePtr, const void* input, size_t length);
|
190
|
+
XXH_PUBLIC_API XXH32_hash_t XXH32_digest (const XXH32_state_t* statePtr);
|
191
|
+
|
192
|
+
XXH_PUBLIC_API XXH_errorcode XXH64_reset (XXH64_state_t* statePtr, unsigned long long seed);
|
193
|
+
XXH_PUBLIC_API XXH_errorcode XXH64_update (XXH64_state_t* statePtr, const void* input, size_t length);
|
194
|
+
XXH_PUBLIC_API XXH64_hash_t XXH64_digest (const XXH64_state_t* statePtr);
|
195
|
+
|
196
|
+
/*!
|
197
|
+
These functions generate the xxHash of an input provided in multiple segments,
|
198
|
+
as opposed to provided as a single block.
|
199
|
+
|
200
|
+
XXH state must first be allocated, using either static or dynamic method provided above.
|
201
|
+
|
202
|
+
Start a new hash by initializing state with a seed, using XXHnn_reset().
|
203
|
+
|
204
|
+
Then, feed the hash state by calling XXHnn_update() as many times as necessary.
|
205
|
+
Obviously, input must be valid, hence allocated and read accessible.
|
206
|
+
The function returns an error code, with 0 meaning OK, and any other value meaning there is an error.
|
207
|
+
|
208
|
+
Finally, a hash value can be produced anytime, by using XXHnn_digest().
|
209
|
+
This function returns the nn-bits hash as an int or long long.
|
210
|
+
|
211
|
+
It's still possible to continue inserting input into the hash state after a digest,
|
212
|
+
and later on generate some new hashes, by calling again XXHnn_digest().
|
213
|
+
|
214
|
+
When done, free XXH state space if it was allocated dynamically.
|
215
|
+
*/
|
216
|
+
|
217
|
+
|
218
|
+
/* **************************
|
219
|
+
* Canonical representation
|
220
|
+
****************************/
|
221
|
+
typedef struct { unsigned char digest[4]; } XXH32_canonical_t;
|
222
|
+
typedef struct { unsigned char digest[8]; } XXH64_canonical_t;
|
223
|
+
|
224
|
+
XXH_PUBLIC_API void XXH32_canonicalFromHash(XXH32_canonical_t* dst, XXH32_hash_t hash);
|
225
|
+
XXH_PUBLIC_API void XXH64_canonicalFromHash(XXH64_canonical_t* dst, XXH64_hash_t hash);
|
226
|
+
|
227
|
+
XXH_PUBLIC_API XXH32_hash_t XXH32_hashFromCanonical(const XXH32_canonical_t* src);
|
228
|
+
XXH_PUBLIC_API XXH64_hash_t XXH64_hashFromCanonical(const XXH64_canonical_t* src);
|
229
|
+
|
230
|
+
/*! Default result type for XXH functions are primitive unsigned 32 and 64 bits.
|
231
|
+
* The canonical representation uses human-readable write convention, aka big-endian (large digits first).
|
232
|
+
* These functions allow transformation of hash result into and from its canonical format.
|
233
|
+
* This way, hash values can be written into a file / memory, and remain comparable on different systems and programs.
|
234
|
+
*/
|
235
|
+
|
236
|
+
|
237
|
+
#ifdef XXH_STATIC_LINKING_ONLY
|
238
|
+
|
239
|
+
/* This part contains definition which shall only be used with static linking.
|
240
|
+
The prototypes / types defined here are not guaranteed to remain stable.
|
241
|
+
They could change in a future version, becoming incompatible with a different version of the library */
|
242
|
+
|
243
|
+
struct XXH32_state_s {
|
244
|
+
unsigned long long total_len;
|
245
|
+
unsigned seed;
|
246
|
+
unsigned v1;
|
247
|
+
unsigned v2;
|
248
|
+
unsigned v3;
|
249
|
+
unsigned v4;
|
250
|
+
unsigned mem32[4]; /* buffer defined as U32 for alignment */
|
251
|
+
unsigned memsize;
|
252
|
+
}; /* typedef'd to XXH32_state_t */
|
253
|
+
|
254
|
+
struct XXH64_state_s {
|
255
|
+
unsigned long long total_len;
|
256
|
+
unsigned long long seed;
|
257
|
+
unsigned long long v1;
|
258
|
+
unsigned long long v2;
|
259
|
+
unsigned long long v3;
|
260
|
+
unsigned long long v4;
|
261
|
+
unsigned long long mem64[4]; /* buffer defined as U64 for alignment */
|
262
|
+
unsigned memsize;
|
263
|
+
}; /* typedef'd to XXH64_state_t */
|
264
|
+
|
265
|
+
|
266
|
+
#endif
|
267
|
+
|
268
|
+
|
269
|
+
#if defined (__cplusplus)
|
270
|
+
}
|
271
|
+
#endif
|
272
|
+
|
273
|
+
#endif /* XXHASH_H_5627135585666179 */
|
@@ -0,0 +1,197 @@
|
|
1
|
+
/*
|
2
|
+
Buffered version of Zstd compression library
|
3
|
+
Copyright (C) 2015-2016, Yann Collet.
|
4
|
+
|
5
|
+
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
6
|
+
|
7
|
+
Redistribution and use in source and binary forms, with or without
|
8
|
+
modification, are permitted provided that the following conditions are
|
9
|
+
met:
|
10
|
+
* Redistributions of source code must retain the above copyright
|
11
|
+
notice, this list of conditions and the following disclaimer.
|
12
|
+
* Redistributions in binary form must reproduce the above
|
13
|
+
copyright notice, this list of conditions and the following disclaimer
|
14
|
+
in the documentation and/or other materials provided with the
|
15
|
+
distribution.
|
16
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
17
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
18
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
19
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
20
|
+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
21
|
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
22
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
23
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
24
|
+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
25
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
26
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27
|
+
|
28
|
+
You can contact the author at :
|
29
|
+
- zstd homepage : http://www.zstd.net/
|
30
|
+
*/
|
31
|
+
#ifndef ZSTD_BUFFERED_H_23987
|
32
|
+
#define ZSTD_BUFFERED_H_23987
|
33
|
+
|
34
|
+
#if defined (__cplusplus)
|
35
|
+
extern "C" {
|
36
|
+
#endif
|
37
|
+
|
38
|
+
/* *************************************
|
39
|
+
* Dependencies
|
40
|
+
***************************************/
|
41
|
+
#include <stddef.h> /* size_t */
|
42
|
+
|
43
|
+
|
44
|
+
/* ***************************************************************
|
45
|
+
* Compiler specifics
|
46
|
+
*****************************************************************/
|
47
|
+
/* ZSTD_DLL_EXPORT :
|
48
|
+
* Enable exporting of functions when building a Windows DLL */
|
49
|
+
#if defined(_WIN32) && defined(ZSTD_DLL_EXPORT) && (ZSTD_DLL_EXPORT==1)
|
50
|
+
# define ZSTDLIB_API __declspec(dllexport)
|
51
|
+
#else
|
52
|
+
# define ZSTDLIB_API
|
53
|
+
#endif
|
54
|
+
|
55
|
+
|
56
|
+
/* *************************************
|
57
|
+
* Streaming functions
|
58
|
+
***************************************/
|
59
|
+
typedef struct ZBUFF_CCtx_s ZBUFF_CCtx;
|
60
|
+
ZSTDLIB_API ZBUFF_CCtx* ZBUFF_createCCtx(void);
|
61
|
+
ZSTDLIB_API size_t ZBUFF_freeCCtx(ZBUFF_CCtx* cctx);
|
62
|
+
|
63
|
+
ZSTDLIB_API size_t ZBUFF_compressInit(ZBUFF_CCtx* cctx, int compressionLevel);
|
64
|
+
ZSTDLIB_API size_t ZBUFF_compressInitDictionary(ZBUFF_CCtx* cctx, const void* dict, size_t dictSize, int compressionLevel);
|
65
|
+
|
66
|
+
ZSTDLIB_API size_t ZBUFF_compressContinue(ZBUFF_CCtx* cctx, void* dst, size_t* dstCapacityPtr, const void* src, size_t* srcSizePtr);
|
67
|
+
ZSTDLIB_API size_t ZBUFF_compressFlush(ZBUFF_CCtx* cctx, void* dst, size_t* dstCapacityPtr);
|
68
|
+
ZSTDLIB_API size_t ZBUFF_compressEnd(ZBUFF_CCtx* cctx, void* dst, size_t* dstCapacityPtr);
|
69
|
+
|
70
|
+
/*-*************************************************
|
71
|
+
* Streaming compression - howto
|
72
|
+
*
|
73
|
+
* A ZBUFF_CCtx object is required to track streaming operation.
|
74
|
+
* Use ZBUFF_createCCtx() and ZBUFF_freeCCtx() to create/release resources.
|
75
|
+
* ZBUFF_CCtx objects can be reused multiple times.
|
76
|
+
*
|
77
|
+
* Start by initializing ZBUF_CCtx.
|
78
|
+
* Use ZBUFF_compressInit() to start a new compression operation.
|
79
|
+
* Use ZBUFF_compressInitDictionary() for a compression which requires a dictionary.
|
80
|
+
*
|
81
|
+
* Use ZBUFF_compressContinue() repetitively to consume input stream.
|
82
|
+
* *srcSizePtr and *dstCapacityPtr can be any size.
|
83
|
+
* The function will report how many bytes were read or written within *srcSizePtr and *dstCapacityPtr.
|
84
|
+
* Note that it may not consume the entire input, in which case it's up to the caller to present again remaining data.
|
85
|
+
* The content of `dst` will be overwritten (up to *dstCapacityPtr) at each call, so save its content if it matters or change @dst .
|
86
|
+
* @return : a hint to preferred nb of bytes to use as input for next function call (it's just a hint, to improve latency)
|
87
|
+
* or an error code, which can be tested using ZBUFF_isError().
|
88
|
+
*
|
89
|
+
* At any moment, it's possible to flush whatever data remains within buffer, using ZBUFF_compressFlush().
|
90
|
+
* The nb of bytes written into `dst` will be reported into *dstCapacityPtr.
|
91
|
+
* Note that the function cannot output more than *dstCapacityPtr,
|
92
|
+
* therefore, some content might still be left into internal buffer if *dstCapacityPtr is too small.
|
93
|
+
* @return : nb of bytes still present into internal buffer (0 if it's empty)
|
94
|
+
* or an error code, which can be tested using ZBUFF_isError().
|
95
|
+
*
|
96
|
+
* ZBUFF_compressEnd() instructs to finish a frame.
|
97
|
+
* It will perform a flush and write frame epilogue.
|
98
|
+
* The epilogue is required for decoders to consider a frame completed.
|
99
|
+
* Similar to ZBUFF_compressFlush(), it may not be able to output the entire internal buffer content if *dstCapacityPtr is too small.
|
100
|
+
* In which case, call again ZBUFF_compressFlush() to complete the flush.
|
101
|
+
* @return : nb of bytes still present into internal buffer (0 if it's empty)
|
102
|
+
* or an error code, which can be tested using ZBUFF_isError().
|
103
|
+
*
|
104
|
+
* Hint : _recommended buffer_ sizes (not compulsory) : ZBUFF_recommendedCInSize() / ZBUFF_recommendedCOutSize()
|
105
|
+
* input : ZBUFF_recommendedCInSize==128 KB block size is the internal unit, use this value to reduce intermediate stages (better latency)
|
106
|
+
* output : ZBUFF_recommendedCOutSize==ZSTD_compressBound(128 KB) + 3 + 3 : ensures it's always possible to write/flush/end a full block. Skip some buffering.
|
107
|
+
* By using both, it ensures that input will be entirely consumed, and output will always contain the result, reducing intermediate buffering.
|
108
|
+
* **************************************************/
|
109
|
+
|
110
|
+
|
111
|
+
typedef struct ZBUFF_DCtx_s ZBUFF_DCtx;
|
112
|
+
ZSTDLIB_API ZBUFF_DCtx* ZBUFF_createDCtx(void);
|
113
|
+
ZSTDLIB_API size_t ZBUFF_freeDCtx(ZBUFF_DCtx* dctx);
|
114
|
+
|
115
|
+
ZSTDLIB_API size_t ZBUFF_decompressInit(ZBUFF_DCtx* dctx);
|
116
|
+
ZSTDLIB_API size_t ZBUFF_decompressInitDictionary(ZBUFF_DCtx* dctx, const void* dict, size_t dictSize);
|
117
|
+
|
118
|
+
ZSTDLIB_API size_t ZBUFF_decompressContinue(ZBUFF_DCtx* dctx,
|
119
|
+
void* dst, size_t* dstCapacityPtr,
|
120
|
+
const void* src, size_t* srcSizePtr);
|
121
|
+
|
122
|
+
/*-***************************************************************************
|
123
|
+
* Streaming decompression howto
|
124
|
+
*
|
125
|
+
* A ZBUFF_DCtx object is required to track streaming operations.
|
126
|
+
* Use ZBUFF_createDCtx() and ZBUFF_freeDCtx() to create/release resources.
|
127
|
+
* Use ZBUFF_decompressInit() to start a new decompression operation,
|
128
|
+
* or ZBUFF_decompressInitDictionary() if decompression requires a dictionary.
|
129
|
+
* Note that ZBUFF_DCtx objects can be re-init multiple times.
|
130
|
+
*
|
131
|
+
* Use ZBUFF_decompressContinue() repetitively to consume your input.
|
132
|
+
* *srcSizePtr and *dstCapacityPtr can be any size.
|
133
|
+
* The function will report how many bytes were read or written by modifying *srcSizePtr and *dstCapacityPtr.
|
134
|
+
* Note that it may not consume the entire input, in which case it's up to the caller to present remaining input again.
|
135
|
+
* The content of `dst` will be overwritten (up to *dstCapacityPtr) at each function call, so save its content if it matters, or change `dst`.
|
136
|
+
* @return : a hint to preferred nb of bytes to use as input for next function call (it's only a hint, to help latency),
|
137
|
+
* or 0 when a frame is completely decoded,
|
138
|
+
* or an error code, which can be tested using ZBUFF_isError().
|
139
|
+
*
|
140
|
+
* Hint : recommended buffer sizes (not compulsory) : ZBUFF_recommendedDInSize() and ZBUFF_recommendedDOutSize()
|
141
|
+
* output : ZBUFF_recommendedDOutSize== 128 KB block size is the internal unit, it ensures it's always possible to write a full block when decoded.
|
142
|
+
* input : ZBUFF_recommendedDInSize == 128KB + 3;
|
143
|
+
* just follow indications from ZBUFF_decompressContinue() to minimize latency. It should always be <= 128 KB + 3 .
|
144
|
+
* *******************************************************************************/
|
145
|
+
|
146
|
+
|
147
|
+
/* *************************************
|
148
|
+
* Tool functions
|
149
|
+
***************************************/
|
150
|
+
ZSTDLIB_API unsigned ZBUFF_isError(size_t errorCode);
|
151
|
+
ZSTDLIB_API const char* ZBUFF_getErrorName(size_t errorCode);
|
152
|
+
|
153
|
+
/** Functions below provide recommended buffer sizes for Compression or Decompression operations.
|
154
|
+
* These sizes are just hints, they tend to offer better latency */
|
155
|
+
ZSTDLIB_API size_t ZBUFF_recommendedCInSize(void);
|
156
|
+
ZSTDLIB_API size_t ZBUFF_recommendedCOutSize(void);
|
157
|
+
ZSTDLIB_API size_t ZBUFF_recommendedDInSize(void);
|
158
|
+
ZSTDLIB_API size_t ZBUFF_recommendedDOutSize(void);
|
159
|
+
|
160
|
+
|
161
|
+
#ifdef ZBUFF_STATIC_LINKING_ONLY
|
162
|
+
|
163
|
+
/* ====================================================================================
|
164
|
+
* The definitions in this section are considered experimental.
|
165
|
+
* They should never be used in association with a dynamic library, as they may change in the future.
|
166
|
+
* They are provided for advanced usages.
|
167
|
+
* Use them only in association with static linking.
|
168
|
+
* ==================================================================================== */
|
169
|
+
|
170
|
+
/*--- Dependency ---*/
|
171
|
+
#define ZSTD_STATIC_LINKING_ONLY /* ZSTD_parameters */
|
172
|
+
#include "zstd.h"
|
173
|
+
|
174
|
+
|
175
|
+
/*--- External memory ---*/
|
176
|
+
/*! ZBUFF_createCCtx_advanced() :
|
177
|
+
* Create a ZBUFF compression context using external alloc and free functions */
|
178
|
+
ZSTDLIB_API ZBUFF_CCtx* ZBUFF_createCCtx_advanced(ZSTD_customMem customMem);
|
179
|
+
|
180
|
+
/*! ZBUFF_createDCtx_advanced() :
|
181
|
+
* Create a ZBUFF decompression context using external alloc and free functions */
|
182
|
+
ZSTDLIB_API ZBUFF_DCtx* ZBUFF_createDCtx_advanced(ZSTD_customMem customMem);
|
183
|
+
|
184
|
+
|
185
|
+
/*--- Advanced Streaming function ---*/
|
186
|
+
ZSTDLIB_API size_t ZBUFF_compressInit_advanced(ZBUFF_CCtx* zbc,
|
187
|
+
const void* dict, size_t dictSize,
|
188
|
+
ZSTD_parameters params, unsigned long long pledgedSrcSize);
|
189
|
+
|
190
|
+
#endif /* ZBUFF_STATIC_LINKING_ONLY */
|
191
|
+
|
192
|
+
|
193
|
+
#if defined (__cplusplus)
|
194
|
+
}
|
195
|
+
#endif
|
196
|
+
|
197
|
+
#endif /* ZSTD_BUFFERED_H_23987 */
|