extlz4 0.2.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/HISTORY.ja.md +116 -0
- data/LICENSE +24 -0
- data/README.md +203 -0
- data/Rakefile +212 -0
- data/bin/extlz4 +220 -0
- data/contrib/lz4/INSTALL +15 -0
- data/contrib/lz4/LICENSE +11 -0
- data/contrib/lz4/NEWS +231 -0
- data/contrib/lz4/README.md +114 -0
- data/contrib/lz4/circle.yml +39 -0
- data/contrib/lz4/lib/LICENSE +24 -0
- data/contrib/lz4/lib/README.md +73 -0
- data/contrib/lz4/lib/liblz4.pc.in +14 -0
- data/contrib/lz4/lib/lz4.c +1478 -0
- data/contrib/lz4/lib/lz4.h +463 -0
- data/contrib/lz4/lib/lz4frame.c +1669 -0
- data/contrib/lz4/lib/lz4frame.h +391 -0
- data/contrib/lz4/lib/lz4frame_static.h +143 -0
- data/contrib/lz4/lib/lz4hc.c +807 -0
- data/contrib/lz4/lib/lz4hc.h +278 -0
- data/contrib/lz4/lib/lz4opt.h +366 -0
- data/contrib/lz4/lib/xxhash.c +894 -0
- data/contrib/lz4/lib/xxhash.h +293 -0
- data/examples/frameapi.rb +43 -0
- data/ext/blockapi.c +1046 -0
- data/ext/depend +4 -0
- data/ext/extconf.rb +60 -0
- data/ext/extlz4.c +69 -0
- data/ext/extlz4.h +109 -0
- data/ext/frameapi.c +780 -0
- data/ext/hashargs.c +151 -0
- data/ext/hashargs.h +110 -0
- data/ext/lz4_amalgam.c +31 -0
- data/gemstub.rb +40 -0
- data/lib/extlz4.rb +327 -0
- data/lib/extlz4/compat.rb +12 -0
- data/lib/extlz4/fix-0.1bug.rb +96 -0
- data/lib/extlz4/oldstream.rb +529 -0
- data/lib/extlz4/version.rb +3 -0
- data/test/common.rb +18 -0
- data/test/test_blockapi.rb +105 -0
- data/test/test_frameapi.rb +59 -0
- metadata +126 -0
@@ -0,0 +1,391 @@
|
|
1
|
+
/*
|
2
|
+
LZ4 auto-framing library
|
3
|
+
Header File
|
4
|
+
Copyright (C) 2011-2017, Yann Collet.
|
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
|
+
|
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
|
+
|
18
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
19
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
20
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
21
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
22
|
+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
23
|
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
24
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
25
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
26
|
+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
27
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
28
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
29
|
+
|
30
|
+
You can contact the author at :
|
31
|
+
- LZ4 source repository : https://github.com/lz4/lz4
|
32
|
+
- LZ4 public forum : https://groups.google.com/forum/#!forum/lz4c
|
33
|
+
*/
|
34
|
+
|
35
|
+
/* LZ4F is a stand-alone API to create LZ4-compressed frames
|
36
|
+
* conformant with specification v1.5.1.
|
37
|
+
* It also offers streaming capabilities.
|
38
|
+
* lz4.h is not required when using lz4frame.h.
|
39
|
+
* */
|
40
|
+
|
41
|
+
#ifndef LZ4F_H_09782039843
|
42
|
+
#define LZ4F_H_09782039843
|
43
|
+
|
44
|
+
#if defined (__cplusplus)
|
45
|
+
extern "C" {
|
46
|
+
#endif
|
47
|
+
|
48
|
+
/* --- Dependency --- */
|
49
|
+
#include <stddef.h> /* size_t */
|
50
|
+
|
51
|
+
|
52
|
+
/**
|
53
|
+
Introduction
|
54
|
+
|
55
|
+
lz4frame.h implements LZ4 frame specification (doc/lz4_Frame_format.md).
|
56
|
+
lz4frame.h provides frame compression functions that take care
|
57
|
+
of encoding standard metadata alongside LZ4-compressed blocks.
|
58
|
+
*/
|
59
|
+
|
60
|
+
/*-***************************************************************
|
61
|
+
* Compiler specifics
|
62
|
+
*****************************************************************/
|
63
|
+
/* LZ4_DLL_EXPORT :
|
64
|
+
* Enable exporting of functions when building a Windows DLL
|
65
|
+
* LZ4FLIB_API :
|
66
|
+
* Control library symbols visibility.
|
67
|
+
*/
|
68
|
+
#if defined(LZ4_DLL_EXPORT) && (LZ4_DLL_EXPORT==1)
|
69
|
+
# define LZ4FLIB_API __declspec(dllexport)
|
70
|
+
#elif defined(LZ4_DLL_IMPORT) && (LZ4_DLL_IMPORT==1)
|
71
|
+
# define LZ4FLIB_API __declspec(dllimport)
|
72
|
+
#elif defined(__GNUC__) && (__GNUC__ >= 4)
|
73
|
+
# define LZ4FLIB_API __attribute__ ((__visibility__ ("default")))
|
74
|
+
#else
|
75
|
+
# define LZ4FLIB_API
|
76
|
+
#endif
|
77
|
+
|
78
|
+
#ifdef LZ4F_DISABLE_DEPRECATE_WARNINGS
|
79
|
+
# define LZ4F_DEPRECATE(x) x
|
80
|
+
#else
|
81
|
+
# if defined(_MSC_VER)
|
82
|
+
# define LZ4F_DEPRECATE(x) x /* __declspec(deprecated) x - only works with C++ */
|
83
|
+
# elif defined(__clang__) || (defined(__GNUC__) && (__GNUC__ >= 6))
|
84
|
+
# define LZ4F_DEPRECATE(x) x __attribute__((deprecated))
|
85
|
+
# else
|
86
|
+
# define LZ4F_DEPRECATE(x) x /* no deprecation warning for this compiler */
|
87
|
+
# endif
|
88
|
+
#endif
|
89
|
+
|
90
|
+
|
91
|
+
/*-************************************
|
92
|
+
* Error management
|
93
|
+
**************************************/
|
94
|
+
typedef size_t LZ4F_errorCode_t;
|
95
|
+
|
96
|
+
LZ4FLIB_API unsigned LZ4F_isError(LZ4F_errorCode_t code); /**< tells if a `LZ4F_errorCode_t` function result is an error code */
|
97
|
+
LZ4FLIB_API const char* LZ4F_getErrorName(LZ4F_errorCode_t code); /**< return error code string; useful for debugging */
|
98
|
+
|
99
|
+
|
100
|
+
/*-************************************
|
101
|
+
* Frame compression types
|
102
|
+
**************************************/
|
103
|
+
/* #define LZ4F_ENABLE_OBSOLETE_ENUMS // uncomment to enable obsolete enums */
|
104
|
+
#ifdef LZ4F_ENABLE_OBSOLETE_ENUMS
|
105
|
+
# define LZ4F_OBSOLETE_ENUM(x) , LZ4F_DEPRECATE(x) = LZ4F_##x
|
106
|
+
#else
|
107
|
+
# define LZ4F_OBSOLETE_ENUM(x)
|
108
|
+
#endif
|
109
|
+
|
110
|
+
/* The larger the block size, the (slightly) better the compression ratio,
|
111
|
+
* though there are diminishing returns.
|
112
|
+
* Larger blocks also increase memory usage on both compression and decompression sides. */
|
113
|
+
typedef enum {
|
114
|
+
LZ4F_default=0,
|
115
|
+
LZ4F_max64KB=4,
|
116
|
+
LZ4F_max256KB=5,
|
117
|
+
LZ4F_max1MB=6,
|
118
|
+
LZ4F_max4MB=7
|
119
|
+
LZ4F_OBSOLETE_ENUM(max64KB)
|
120
|
+
LZ4F_OBSOLETE_ENUM(max256KB)
|
121
|
+
LZ4F_OBSOLETE_ENUM(max1MB)
|
122
|
+
LZ4F_OBSOLETE_ENUM(max4MB)
|
123
|
+
} LZ4F_blockSizeID_t;
|
124
|
+
|
125
|
+
/* Linked blocks sharply reduce inefficiencies when using small blocks,
|
126
|
+
* they compress better.
|
127
|
+
* However, some LZ4 decoders are only compatible with independent blocks */
|
128
|
+
typedef enum {
|
129
|
+
LZ4F_blockLinked=0,
|
130
|
+
LZ4F_blockIndependent
|
131
|
+
LZ4F_OBSOLETE_ENUM(blockLinked)
|
132
|
+
LZ4F_OBSOLETE_ENUM(blockIndependent)
|
133
|
+
} LZ4F_blockMode_t;
|
134
|
+
|
135
|
+
typedef enum {
|
136
|
+
LZ4F_noContentChecksum=0,
|
137
|
+
LZ4F_contentChecksumEnabled
|
138
|
+
LZ4F_OBSOLETE_ENUM(noContentChecksum)
|
139
|
+
LZ4F_OBSOLETE_ENUM(contentChecksumEnabled)
|
140
|
+
} LZ4F_contentChecksum_t;
|
141
|
+
|
142
|
+
typedef enum {
|
143
|
+
LZ4F_noBlockChecksum=0,
|
144
|
+
LZ4F_blockChecksumEnabled
|
145
|
+
} LZ4F_blockChecksum_t;
|
146
|
+
|
147
|
+
typedef enum {
|
148
|
+
LZ4F_frame=0,
|
149
|
+
LZ4F_skippableFrame
|
150
|
+
LZ4F_OBSOLETE_ENUM(skippableFrame)
|
151
|
+
} LZ4F_frameType_t;
|
152
|
+
|
153
|
+
#ifdef LZ4F_ENABLE_OBSOLETE_ENUMS
|
154
|
+
typedef LZ4F_blockSizeID_t blockSizeID_t;
|
155
|
+
typedef LZ4F_blockMode_t blockMode_t;
|
156
|
+
typedef LZ4F_frameType_t frameType_t;
|
157
|
+
typedef LZ4F_contentChecksum_t contentChecksum_t;
|
158
|
+
#endif
|
159
|
+
|
160
|
+
/*! LZ4F_frameInfo_t :
|
161
|
+
* makes it possible to set or read frame parameters.
|
162
|
+
* It's not required to set all fields, as long as the structure was initially memset() to zero.
|
163
|
+
* For all fields, 0 sets it to default value */
|
164
|
+
typedef struct {
|
165
|
+
LZ4F_blockSizeID_t blockSizeID; /* max64KB, max256KB, max1MB, max4MB ; 0 == default */
|
166
|
+
LZ4F_blockMode_t blockMode; /* LZ4F_blockLinked, LZ4F_blockIndependent ; 0 == default */
|
167
|
+
LZ4F_contentChecksum_t contentChecksumFlag; /* if enabled, frame is terminated with a 32-bits checksum of decompressed data ; 0 == disabled (default) */
|
168
|
+
LZ4F_frameType_t frameType; /* read-only field : LZ4F_frame or LZ4F_skippableFrame */
|
169
|
+
unsigned long long contentSize; /* Size of uncompressed content ; 0 == unknown */
|
170
|
+
unsigned dictID; /* Dictionary ID, sent by the compressor to help decoder select the correct dictionary; 0 == no dictID provided */
|
171
|
+
LZ4F_blockChecksum_t blockChecksumFlag; /* if enabled, each block is followed by a checksum of block's compressed data ; 0 == disabled (default) */
|
172
|
+
} LZ4F_frameInfo_t;
|
173
|
+
|
174
|
+
/*! LZ4F_preferences_t :
|
175
|
+
* makes it possible to supply detailed compression parameters to the stream interface.
|
176
|
+
* It's not required to set all fields, as long as the structure was initially memset() to zero.
|
177
|
+
* All reserved fields must be set to zero. */
|
178
|
+
typedef struct {
|
179
|
+
LZ4F_frameInfo_t frameInfo;
|
180
|
+
int compressionLevel; /* 0 == default (fast mode); values above LZ4HC_CLEVEL_MAX count as LZ4HC_CLEVEL_MAX; values below 0 trigger "fast acceleration", proportional to value */
|
181
|
+
unsigned autoFlush; /* 1 == always flush, to reduce usage of internal buffers */
|
182
|
+
unsigned reserved[4]; /* must be zero for forward compatibility */
|
183
|
+
} LZ4F_preferences_t;
|
184
|
+
|
185
|
+
LZ4FLIB_API int LZ4F_compressionLevel_max(void);
|
186
|
+
|
187
|
+
|
188
|
+
/*-*********************************
|
189
|
+
* Simple compression function
|
190
|
+
***********************************/
|
191
|
+
/*! LZ4F_compressFrameBound() :
|
192
|
+
* Returns the maximum possible size of a frame compressed with LZ4F_compressFrame() given srcSize content and preferences.
|
193
|
+
* Note : this result is only usable with LZ4F_compressFrame(), not with multi-segments compression.
|
194
|
+
*/
|
195
|
+
LZ4FLIB_API size_t LZ4F_compressFrameBound(size_t srcSize, const LZ4F_preferences_t* preferencesPtr);
|
196
|
+
|
197
|
+
/*! LZ4F_compressFrame() :
|
198
|
+
* Compress an entire srcBuffer into a valid LZ4 frame.
|
199
|
+
* dstCapacity MUST be >= LZ4F_compressFrameBound(srcSize, preferencesPtr).
|
200
|
+
* The LZ4F_preferences_t structure is optional : you can provide NULL as argument. All preferences will be set to default.
|
201
|
+
* @return : number of bytes written into dstBuffer.
|
202
|
+
* or an error code if it fails (can be tested using LZ4F_isError())
|
203
|
+
*/
|
204
|
+
LZ4FLIB_API size_t LZ4F_compressFrame(void* dstBuffer, size_t dstCapacity,
|
205
|
+
const void* srcBuffer, size_t srcSize,
|
206
|
+
const LZ4F_preferences_t* preferencesPtr);
|
207
|
+
|
208
|
+
|
209
|
+
/*-***********************************
|
210
|
+
* Advanced compression functions
|
211
|
+
*************************************/
|
212
|
+
typedef struct LZ4F_cctx_s LZ4F_cctx; /* incomplete type */
|
213
|
+
typedef LZ4F_cctx* LZ4F_compressionContext_t; /* for compatibility with previous API version */
|
214
|
+
|
215
|
+
typedef struct {
|
216
|
+
unsigned stableSrc; /* 1 == src content will remain present on future calls to LZ4F_compress(); skip copying src content within tmp buffer */
|
217
|
+
unsigned reserved[3];
|
218
|
+
} LZ4F_compressOptions_t;
|
219
|
+
|
220
|
+
/*--- Resource Management ---*/
|
221
|
+
|
222
|
+
#define LZ4F_VERSION 100
|
223
|
+
LZ4FLIB_API unsigned LZ4F_getVersion(void);
|
224
|
+
/*! LZ4F_createCompressionContext() :
|
225
|
+
* The first thing to do is to create a compressionContext object, which will be used in all compression operations.
|
226
|
+
* This is achieved using LZ4F_createCompressionContext(), which takes as argument a version.
|
227
|
+
* The version provided MUST be LZ4F_VERSION. It is intended to track potential version mismatch, notably when using DLL.
|
228
|
+
* The function will provide a pointer to a fully allocated LZ4F_cctx object.
|
229
|
+
* If @return != zero, there was an error during context creation.
|
230
|
+
* Object can release its memory using LZ4F_freeCompressionContext();
|
231
|
+
*/
|
232
|
+
LZ4FLIB_API LZ4F_errorCode_t LZ4F_createCompressionContext(LZ4F_cctx** cctxPtr, unsigned version);
|
233
|
+
LZ4FLIB_API LZ4F_errorCode_t LZ4F_freeCompressionContext(LZ4F_cctx* cctx);
|
234
|
+
|
235
|
+
|
236
|
+
/*---- Compression ----*/
|
237
|
+
|
238
|
+
#define LZ4F_HEADER_SIZE_MAX 19
|
239
|
+
/*! LZ4F_compressBegin() :
|
240
|
+
* will write the frame header into dstBuffer.
|
241
|
+
* dstCapacity must be >= LZ4F_HEADER_SIZE_MAX bytes.
|
242
|
+
* `prefsPtr` is optional : you can provide NULL as argument, all preferences will then be set to default.
|
243
|
+
* @return : number of bytes written into dstBuffer for the header
|
244
|
+
* or an error code (which can be tested using LZ4F_isError())
|
245
|
+
*/
|
246
|
+
LZ4FLIB_API size_t LZ4F_compressBegin(LZ4F_cctx* cctx,
|
247
|
+
void* dstBuffer, size_t dstCapacity,
|
248
|
+
const LZ4F_preferences_t* prefsPtr);
|
249
|
+
|
250
|
+
/*! LZ4F_compressBound() :
|
251
|
+
* Provides dstCapacity given a srcSize to guarantee operation success in worst case situations.
|
252
|
+
* prefsPtr is optional : you can provide NULL as argument, preferences will be set to cover worst case scenario.
|
253
|
+
* Result is always the same for a srcSize and prefsPtr, so it can be trusted to size reusable buffers.
|
254
|
+
* When srcSize==0, LZ4F_compressBound() provides an upper bound for LZ4F_flush() and LZ4F_compressEnd() operations.
|
255
|
+
*/
|
256
|
+
LZ4FLIB_API size_t LZ4F_compressBound(size_t srcSize, const LZ4F_preferences_t* prefsPtr);
|
257
|
+
|
258
|
+
/*! LZ4F_compressUpdate() :
|
259
|
+
* LZ4F_compressUpdate() can be called repetitively to compress as much data as necessary.
|
260
|
+
* An important rule is that dstCapacity MUST be large enough to ensure operation success even in worst case situations.
|
261
|
+
* This value is provided by LZ4F_compressBound().
|
262
|
+
* If this condition is not respected, LZ4F_compress() will fail (result is an errorCode).
|
263
|
+
* LZ4F_compressUpdate() doesn't guarantee error recovery. When an error occurs, compression context must be freed or resized.
|
264
|
+
* `cOptPtr` is optional : NULL can be provided, in which case all options are set to default.
|
265
|
+
* @return : number of bytes written into `dstBuffer` (it can be zero, meaning input data was just buffered).
|
266
|
+
* or an error code if it fails (which can be tested using LZ4F_isError())
|
267
|
+
*/
|
268
|
+
LZ4FLIB_API size_t LZ4F_compressUpdate(LZ4F_cctx* cctx, void* dstBuffer, size_t dstCapacity, const void* srcBuffer, size_t srcSize, const LZ4F_compressOptions_t* cOptPtr);
|
269
|
+
|
270
|
+
/*! LZ4F_flush() :
|
271
|
+
* When data must be generated and sent immediately, without waiting for a block to be completely filled,
|
272
|
+
* it's possible to call LZ4_flush(). It will immediately compress any data buffered within cctx.
|
273
|
+
* `dstCapacity` must be large enough to ensure the operation will be successful.
|
274
|
+
* `cOptPtr` is optional : it's possible to provide NULL, all options will be set to default.
|
275
|
+
* @return : number of bytes written into dstBuffer (it can be zero, which means there was no data stored within cctx)
|
276
|
+
* or an error code if it fails (which can be tested using LZ4F_isError())
|
277
|
+
*/
|
278
|
+
LZ4FLIB_API size_t LZ4F_flush(LZ4F_cctx* cctx, void* dstBuffer, size_t dstCapacity, const LZ4F_compressOptions_t* cOptPtr);
|
279
|
+
|
280
|
+
/*! LZ4F_compressEnd() :
|
281
|
+
* To properly finish an LZ4 frame, invoke LZ4F_compressEnd().
|
282
|
+
* It will flush whatever data remained within `cctx` (like LZ4_flush())
|
283
|
+
* and properly finalize the frame, with an endMark and a checksum.
|
284
|
+
* `cOptPtr` is optional : NULL can be provided, in which case all options will be set to default.
|
285
|
+
* @return : number of bytes written into dstBuffer (necessarily >= 4 (endMark), or 8 if optional frame checksum is enabled)
|
286
|
+
* or an error code if it fails (which can be tested using LZ4F_isError())
|
287
|
+
* A successful call to LZ4F_compressEnd() makes `cctx` available again for another compression task.
|
288
|
+
*/
|
289
|
+
LZ4FLIB_API size_t LZ4F_compressEnd(LZ4F_cctx* cctx, void* dstBuffer, size_t dstCapacity, const LZ4F_compressOptions_t* cOptPtr);
|
290
|
+
|
291
|
+
|
292
|
+
/*-*********************************
|
293
|
+
* Decompression functions
|
294
|
+
***********************************/
|
295
|
+
typedef struct LZ4F_dctx_s LZ4F_dctx; /* incomplete type */
|
296
|
+
typedef LZ4F_dctx* LZ4F_decompressionContext_t; /* compatibility with previous API versions */
|
297
|
+
|
298
|
+
typedef struct {
|
299
|
+
unsigned stableDst; /* pledge that at least 64KB+64Bytes of previously decompressed data remain unmodifed where it was decoded. This optimization skips storage operations in tmp buffers */
|
300
|
+
unsigned reserved[3]; /* must be set to zero for forward compatibility */
|
301
|
+
} LZ4F_decompressOptions_t;
|
302
|
+
|
303
|
+
|
304
|
+
/* Resource management */
|
305
|
+
|
306
|
+
/*!LZ4F_createDecompressionContext() :
|
307
|
+
* Create an LZ4F_dctx object, to track all decompression operations.
|
308
|
+
* The version provided MUST be LZ4F_VERSION.
|
309
|
+
* The function provides a pointer to an allocated and initialized LZ4F_dctx object.
|
310
|
+
* The result is an errorCode, which can be tested using LZ4F_isError().
|
311
|
+
* dctx memory can be released using LZ4F_freeDecompressionContext();
|
312
|
+
* The result of LZ4F_freeDecompressionContext() is indicative of the current state of decompressionContext when being released.
|
313
|
+
* That is, it should be == 0 if decompression has been completed fully and correctly.
|
314
|
+
*/
|
315
|
+
LZ4FLIB_API LZ4F_errorCode_t LZ4F_createDecompressionContext(LZ4F_dctx** dctxPtr, unsigned version);
|
316
|
+
LZ4FLIB_API LZ4F_errorCode_t LZ4F_freeDecompressionContext(LZ4F_dctx* dctx);
|
317
|
+
|
318
|
+
|
319
|
+
/*-***********************************
|
320
|
+
* Streaming decompression functions
|
321
|
+
*************************************/
|
322
|
+
|
323
|
+
/*! LZ4F_getFrameInfo() :
|
324
|
+
* This function extracts frame parameters (max blockSize, dictID, etc.).
|
325
|
+
* Its usage is optional.
|
326
|
+
* Extracted information is typically useful for allocation and dictionary.
|
327
|
+
* This function works in 2 situations :
|
328
|
+
* - At the beginning of a new frame, in which case
|
329
|
+
* it will decode information from `srcBuffer`, starting the decoding process.
|
330
|
+
* Input size must be large enough to successfully decode the entire frame header.
|
331
|
+
* Frame header size is variable, but is guaranteed to be <= LZ4F_HEADER_SIZE_MAX bytes.
|
332
|
+
* It's allowed to provide more input data than this minimum.
|
333
|
+
* - After decoding has been started.
|
334
|
+
* In which case, no input is read, frame parameters are extracted from dctx.
|
335
|
+
* - If decoding has barely started, but not yet extracted information from header,
|
336
|
+
* LZ4F_getFrameInfo() will fail.
|
337
|
+
* The number of bytes consumed from srcBuffer will be updated within *srcSizePtr (necessarily <= original value).
|
338
|
+
* Decompression must resume from (srcBuffer + *srcSizePtr).
|
339
|
+
* @return : an hint about how many srcSize bytes LZ4F_decompress() expects for next call,
|
340
|
+
* or an error code which can be tested using LZ4F_isError().
|
341
|
+
* note 1 : in case of error, dctx is not modified. Decoding operation can resume from beginning safely.
|
342
|
+
* note 2 : frame parameters are *copied into* an already allocated LZ4F_frameInfo_t structure.
|
343
|
+
*/
|
344
|
+
LZ4FLIB_API size_t LZ4F_getFrameInfo(LZ4F_dctx* dctx,
|
345
|
+
LZ4F_frameInfo_t* frameInfoPtr,
|
346
|
+
const void* srcBuffer, size_t* srcSizePtr);
|
347
|
+
|
348
|
+
/*! LZ4F_decompress() :
|
349
|
+
* Call this function repetitively to regenerate compressed data from `srcBuffer`.
|
350
|
+
* The function will attempt to decode up to *srcSizePtr bytes from srcBuffer, into dstBuffer of capacity *dstSizePtr.
|
351
|
+
*
|
352
|
+
* The number of bytes regenerated into dstBuffer is provided within *dstSizePtr (necessarily <= original value).
|
353
|
+
*
|
354
|
+
* The number of bytes consumed from srcBuffer is provided within *srcSizePtr (necessarily <= original value).
|
355
|
+
* Number of bytes consumed can be < number of bytes provided.
|
356
|
+
* It typically happens when dstBuffer is not large enough to contain all decoded data.
|
357
|
+
* Unconsumed source data must be presented again in subsequent invocations.
|
358
|
+
*
|
359
|
+
* `dstBuffer` content is expected to be flushed between each invocation, as its content will be overwritten.
|
360
|
+
* `dstBuffer` itself can be changed at will between each consecutive function invocation.
|
361
|
+
*
|
362
|
+
* @return : an hint of how many `srcSize` bytes LZ4F_decompress() expects for next call.
|
363
|
+
* Schematically, it's the size of the current (or remaining) compressed block + header of next block.
|
364
|
+
* Respecting the hint provides some small speed benefit, because it skips intermediate buffers.
|
365
|
+
* This is just a hint though, it's always possible to provide any srcSize.
|
366
|
+
* When a frame is fully decoded, @return will be 0 (no more data expected).
|
367
|
+
* If decompression failed, @return is an error code, which can be tested using LZ4F_isError().
|
368
|
+
*
|
369
|
+
* After a frame is fully decoded, dctx can be used again to decompress another frame.
|
370
|
+
* After a decompression error, use LZ4F_resetDecompressionContext() before re-using dctx, to return to clean state.
|
371
|
+
*/
|
372
|
+
LZ4FLIB_API size_t LZ4F_decompress(LZ4F_dctx* dctx,
|
373
|
+
void* dstBuffer, size_t* dstSizePtr,
|
374
|
+
const void* srcBuffer, size_t* srcSizePtr,
|
375
|
+
const LZ4F_decompressOptions_t* dOptPtr);
|
376
|
+
|
377
|
+
|
378
|
+
/*! LZ4F_resetDecompressionContext() : v1.8.0
|
379
|
+
* In case of an error, the context is left in "undefined" state.
|
380
|
+
* In which case, it's necessary to reset it, before re-using it.
|
381
|
+
* This method can also be used to abruptly stop an unfinished decompression,
|
382
|
+
* and start a new one using the same context. */
|
383
|
+
LZ4FLIB_API void LZ4F_resetDecompressionContext(LZ4F_dctx* dctx); /* always successful */
|
384
|
+
|
385
|
+
|
386
|
+
|
387
|
+
#if defined (__cplusplus)
|
388
|
+
}
|
389
|
+
#endif
|
390
|
+
|
391
|
+
#endif /* LZ4F_H_09782039843 */
|
@@ -0,0 +1,143 @@
|
|
1
|
+
/*
|
2
|
+
LZ4 auto-framing library
|
3
|
+
Header File for static linking only
|
4
|
+
Copyright (C) 2011-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
|
+
- LZ4 source repository : https://github.com/lz4/lz4
|
33
|
+
- LZ4 public forum : https://groups.google.com/forum/#!forum/lz4c
|
34
|
+
*/
|
35
|
+
|
36
|
+
#ifndef LZ4FRAME_STATIC_H_0398209384
|
37
|
+
#define LZ4FRAME_STATIC_H_0398209384
|
38
|
+
|
39
|
+
#if defined (__cplusplus)
|
40
|
+
extern "C" {
|
41
|
+
#endif
|
42
|
+
|
43
|
+
/* lz4frame_static.h should be used solely in the context of static linking.
|
44
|
+
* It contains definitions which are not stable and may change in the future.
|
45
|
+
* Never use it in the context of DLL linking.
|
46
|
+
*/
|
47
|
+
|
48
|
+
|
49
|
+
/* --- Dependency --- */
|
50
|
+
#include "lz4frame.h"
|
51
|
+
|
52
|
+
|
53
|
+
/* --- Error List --- */
|
54
|
+
#define LZ4F_LIST_ERRORS(ITEM) \
|
55
|
+
ITEM(OK_NoError) \
|
56
|
+
ITEM(ERROR_GENERIC) \
|
57
|
+
ITEM(ERROR_maxBlockSize_invalid) \
|
58
|
+
ITEM(ERROR_blockMode_invalid) \
|
59
|
+
ITEM(ERROR_contentChecksumFlag_invalid) \
|
60
|
+
ITEM(ERROR_compressionLevel_invalid) \
|
61
|
+
ITEM(ERROR_headerVersion_wrong) \
|
62
|
+
ITEM(ERROR_blockChecksum_invalid) \
|
63
|
+
ITEM(ERROR_reservedFlag_set) \
|
64
|
+
ITEM(ERROR_allocation_failed) \
|
65
|
+
ITEM(ERROR_srcSize_tooLarge) \
|
66
|
+
ITEM(ERROR_dstMaxSize_tooSmall) \
|
67
|
+
ITEM(ERROR_frameHeader_incomplete) \
|
68
|
+
ITEM(ERROR_frameType_unknown) \
|
69
|
+
ITEM(ERROR_frameSize_wrong) \
|
70
|
+
ITEM(ERROR_srcPtr_wrong) \
|
71
|
+
ITEM(ERROR_decompressionFailed) \
|
72
|
+
ITEM(ERROR_headerChecksum_invalid) \
|
73
|
+
ITEM(ERROR_contentChecksum_invalid) \
|
74
|
+
ITEM(ERROR_frameDecoding_alreadyStarted) \
|
75
|
+
ITEM(ERROR_maxCode)
|
76
|
+
|
77
|
+
#define LZ4F_GENERATE_ENUM(ENUM) LZ4F_##ENUM,
|
78
|
+
|
79
|
+
/* enum list is exposed, to handle specific errors */
|
80
|
+
typedef enum { LZ4F_LIST_ERRORS(LZ4F_GENERATE_ENUM) } LZ4F_errorCodes;
|
81
|
+
|
82
|
+
LZ4F_errorCodes LZ4F_getErrorCode(size_t functionResult);
|
83
|
+
|
84
|
+
|
85
|
+
|
86
|
+
/**********************************
|
87
|
+
* Bulk processing dictionary API
|
88
|
+
*********************************/
|
89
|
+
typedef struct LZ4F_CDict_s LZ4F_CDict;
|
90
|
+
|
91
|
+
/*! LZ4_createCDict() :
|
92
|
+
* When compressing multiple messages / blocks with the same dictionary, it's recommended to load it just once.
|
93
|
+
* LZ4_createCDict() will create a digested dictionary, ready to start future compression operations without startup delay.
|
94
|
+
* LZ4_CDict can be created once and shared by multiple threads concurrently, since its usage is read-only.
|
95
|
+
* `dictBuffer` can be released after LZ4_CDict creation, since its content is copied within CDict */
|
96
|
+
LZ4F_CDict* LZ4F_createCDict(const void* dictBuffer, size_t dictSize);
|
97
|
+
void LZ4F_freeCDict(LZ4F_CDict* CDict);
|
98
|
+
|
99
|
+
|
100
|
+
/*! LZ4_compressFrame_usingCDict() :
|
101
|
+
* Compress an entire srcBuffer into a valid LZ4 frame using a digested Dictionary.
|
102
|
+
* If cdict==NULL, compress without a dictionary.
|
103
|
+
* dstBuffer MUST be >= LZ4F_compressFrameBound(srcSize, preferencesPtr).
|
104
|
+
* If this condition is not respected, function will fail (@return an errorCode).
|
105
|
+
* The LZ4F_preferences_t structure is optional : you may provide NULL as argument,
|
106
|
+
* but it's not recommended, as it's the only way to provide dictID in the frame header.
|
107
|
+
* @return : number of bytes written into dstBuffer.
|
108
|
+
* or an error code if it fails (can be tested using LZ4F_isError()) */
|
109
|
+
size_t LZ4F_compressFrame_usingCDict(void* dst, size_t dstCapacity,
|
110
|
+
const void* src, size_t srcSize,
|
111
|
+
const LZ4F_CDict* cdict,
|
112
|
+
const LZ4F_preferences_t* preferencesPtr);
|
113
|
+
|
114
|
+
|
115
|
+
/*! LZ4F_compressBegin_usingCDict() :
|
116
|
+
* Inits streaming dictionary compression, and writes the frame header into dstBuffer.
|
117
|
+
* dstCapacity must be >= LZ4F_HEADER_SIZE_MAX bytes.
|
118
|
+
* `prefsPtr` is optional : you may provide NULL as argument,
|
119
|
+
* however, it's the only way to provide dictID in the frame header.
|
120
|
+
* @return : number of bytes written into dstBuffer for the header,
|
121
|
+
* or an error code (which can be tested using LZ4F_isError()) */
|
122
|
+
size_t LZ4F_compressBegin_usingCDict(LZ4F_cctx* cctx,
|
123
|
+
void* dstBuffer, size_t dstCapacity,
|
124
|
+
const LZ4F_CDict* cdict,
|
125
|
+
const LZ4F_preferences_t* prefsPtr);
|
126
|
+
|
127
|
+
|
128
|
+
/*! LZ4F_decompress_usingDict() :
|
129
|
+
* Same as LZ4F_decompress(), using a predefined dictionary.
|
130
|
+
* Dictionary is used "in place", without any preprocessing.
|
131
|
+
* It must remain accessible throughout the entire frame decoding. */
|
132
|
+
size_t LZ4F_decompress_usingDict(LZ4F_dctx* dctxPtr,
|
133
|
+
void* dstBuffer, size_t* dstSizePtr,
|
134
|
+
const void* srcBuffer, size_t* srcSizePtr,
|
135
|
+
const void* dict, size_t dictSize,
|
136
|
+
const LZ4F_decompressOptions_t* decompressOptionsPtr);
|
137
|
+
|
138
|
+
|
139
|
+
#if defined (__cplusplus)
|
140
|
+
}
|
141
|
+
#endif
|
142
|
+
|
143
|
+
#endif /* LZ4FRAME_STATIC_H_0398209384 */
|