lz4-ruby 0.2.0-x86-mingw32 → 0.3.0-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
data/ext/lz4ruby/lz4.h CHANGED
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  LZ4 - Fast LZ compression algorithm
3
3
  Header File
4
- Copyright (C) 2011-2012, Yann Collet.
4
+ Copyright (C) 2011-2013, Yann Collet.
5
5
  BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
6
6
 
7
7
  Redistribution and use in source and binary forms, with or without
@@ -38,80 +38,214 @@ extern "C" {
38
38
  #endif
39
39
 
40
40
 
41
- //****************************
42
- // Simple Functions
43
- //****************************
41
+ /**************************************
42
+ Version
43
+ **************************************/
44
+ #define LZ4_VERSION_MAJOR 1 /* for major interface/format changes */
45
+ #define LZ4_VERSION_MINOR 1 /* for minor interface/format changes */
46
+ #define LZ4_VERSION_RELEASE 3 /* for tweaks, bug-fixes, or development */
44
47
 
45
- int LZ4_compress (const char* source, char* dest, int isize);
46
- int LZ4_uncompress (const char* source, char* dest, int osize);
48
+
49
+ /**************************************
50
+ Compiler Options
51
+ **************************************/
52
+ #if (defined(__GNUC__) && defined(__STRICT_ANSI__)) || (defined(_MSC_VER) && !defined(__cplusplus)) /* Visual Studio */
53
+ # define inline __inline /* Visual C is not C99, but supports some kind of inline */
54
+ #endif
55
+
56
+
57
+ /**************************************
58
+ Simple Functions
59
+ **************************************/
60
+
61
+ int LZ4_compress (const char* source, char* dest, int inputSize);
62
+ int LZ4_decompress_safe (const char* source, char* dest, int inputSize, int maxOutputSize);
47
63
 
48
64
  /*
49
65
  LZ4_compress() :
50
- Compresses 'isize' bytes from 'source' into 'dest'.
51
- Destination buffer must be already allocated,
52
- and must be sized to handle worst cases situations (input data not compressible)
53
- Worst case size evaluation is provided by macro LZ4_compressBound()
54
-
55
- isize : is the input size. Max supported value is ~1.9GB
56
- return : the number of bytes written in buffer dest
57
-
58
-
59
- LZ4_uncompress() :
60
- osize : is the output size, therefore the original size
61
- return : the number of bytes read in the source buffer
62
- If the source stream is malformed, the function will stop decoding and return a negative result, indicating the byte position of the faulty instruction
63
- This function never writes beyond dest + osize, and is therefore protected against malicious data packets
64
- note : destination buffer must be already allocated.
65
- its size must be a minimum of 'osize' bytes.
66
+ Compresses 'inputSize' bytes from 'source' into 'dest'.
67
+ Destination buffer must be already allocated,
68
+ and must be sized to handle worst cases situations (input data not compressible)
69
+ Worst case size evaluation is provided by function LZ4_compressBound()
70
+ inputSize : Max supported value is LZ4_MAX_INPUT_VALUE
71
+ return : the number of bytes written in buffer dest
72
+ or 0 if the compression fails
73
+
74
+ LZ4_decompress_safe() :
75
+ maxOutputSize : is the size of the destination buffer (which must be already allocated)
76
+ return : the number of bytes decoded in the destination buffer (necessarily <= maxOutputSize)
77
+ If the source stream is detected malformed, the function will stop decoding and return a negative result.
78
+ This function is protected against buffer overflow exploits (never writes outside of output buffer, and never reads outside of input buffer). Therefore, it is protected against malicious data packets
66
79
  */
67
80
 
68
81
 
69
- //****************************
70
- // Advanced Functions
71
- //****************************
72
-
73
- #define LZ4_compressBound(isize) (isize + (isize/255) + 16)
82
+ /**************************************
83
+ Advanced Functions
84
+ **************************************/
85
+ #define LZ4_MAX_INPUT_SIZE 0x7E000000 /* 2 113 929 216 bytes */
86
+ #define LZ4_COMPRESSBOUND(isize) ((unsigned int)(isize) > (unsigned int)LZ4_MAX_INPUT_SIZE ? 0 : (isize) + ((isize)/255) + 16)
87
+ static inline int LZ4_compressBound(int isize) { return LZ4_COMPRESSBOUND(isize); }
74
88
 
75
89
  /*
76
90
  LZ4_compressBound() :
77
- Provides the maximum size that LZ4 may output in a "worst case" scenario (input data not compressible)
78
- primarily useful for memory allocation of output buffer.
79
-
80
- isize : is the input size. Max supported value is ~1.9GB
81
- return : maximum output size in a "worst case" scenario
82
- note : this function is limited by "int" range (2^31-1)
91
+ Provides the maximum size that LZ4 may output in a "worst case" scenario (input data not compressible)
92
+ primarily useful for memory allocation of output buffer.
93
+ inline function is recommended for the general case,
94
+ macro is also provided when result needs to be evaluated at compilation (such as stack memory allocation).
95
+
96
+ isize : is the input size. Max supported value is LZ4_MAX_INPUT_SIZE
97
+ return : maximum output size in a "worst case" scenario
98
+ or 0, if input size is too large ( > LZ4_MAX_INPUT_SIZE)
83
99
  */
84
100
 
85
101
 
86
- int LZ4_compress_limitedOutput (const char* source, char* dest, int isize, int maxOutputSize);
102
+ int LZ4_compress_limitedOutput (const char* source, char* dest, int inputSize, int maxOutputSize);
87
103
 
88
104
  /*
89
105
  LZ4_compress_limitedOutput() :
90
- Compress 'isize' bytes from 'source' into an output buffer 'dest' of maximum size 'maxOutputSize'.
91
- If it cannot achieve it, compression will stop, and result of the function will be zero.
92
- This function never writes outside of provided output buffer.
93
-
94
- isize : is the input size. Max supported value is ~1.9GB
95
- maxOutputSize : is the size of the destination buffer (which must be already allocated)
96
- return : the number of bytes written in buffer 'dest'
97
- or 0 if the compression fails
106
+ Compress 'inputSize' bytes from 'source' into an output buffer 'dest' of maximum size 'maxOutputSize'.
107
+ If it cannot achieve it, compression will stop, and result of the function will be zero.
108
+ This function never writes outside of provided output buffer.
109
+
110
+ inputSize : Max supported value is LZ4_MAX_INPUT_VALUE
111
+ maxOutputSize : is the size of the destination buffer (which must be already allocated)
112
+ return : the number of bytes written in buffer 'dest'
113
+ or 0 if the compression fails
98
114
  */
99
115
 
100
116
 
101
- int LZ4_uncompress_unknownOutputSize (const char* source, char* dest, int isize, int maxOutputSize);
117
+ int LZ4_decompress_fast (const char* source, char* dest, int outputSize);
118
+
119
+ /*
120
+ LZ4_decompress_fast() :
121
+ outputSize : is the original (uncompressed) size
122
+ return : the number of bytes read from the source buffer (in other words, the compressed size)
123
+ If the source stream is malformed, the function will stop decoding and return a negative result.
124
+ note : This function is a bit faster than LZ4_decompress_safe()
125
+ This function never writes outside of output buffers, but may read beyond input buffer in case of malicious data packet.
126
+ Use this function preferably into a trusted environment (data to decode comes from a trusted source).
127
+ Destination buffer must be already allocated. Its size must be a minimum of 'outputSize' bytes.
128
+ */
129
+
130
+ int LZ4_decompress_safe_partial (const char* source, char* dest, int inputSize, int targetOutputSize, int maxOutputSize);
102
131
 
103
132
  /*
104
- LZ4_uncompress_unknownOutputSize() :
105
- isize : is the input size, therefore the compressed size
106
- maxOutputSize : is the size of the destination buffer (which must be already allocated)
107
- return : the number of bytes decoded in the destination buffer (necessarily <= maxOutputSize)
108
- If the source stream is malformed, the function will stop decoding and return a negative result, indicating the byte position of the faulty instruction
109
- This function never writes beyond dest + maxOutputSize, and is therefore protected against malicious data packets
110
- note : Destination buffer must be already allocated.
111
- This version is slightly slower than LZ4_uncompress()
133
+ LZ4_decompress_safe_partial() :
134
+ This function decompress a compressed block of size 'inputSize' at position 'source'
135
+ into output buffer 'dest' of size 'maxOutputSize'.
136
+ The function tries to stop decompressing operation as soon as 'targetOutputSize' has been reached,
137
+ reducing decompression time.
138
+ return : the number of bytes decoded in the destination buffer (necessarily <= maxOutputSize)
139
+ Note : this number can be < 'targetOutputSize' should the compressed block to decode be smaller.
140
+ Always control how many bytes were decoded.
141
+ If the source stream is detected malformed, the function will stop decoding and return a negative result.
142
+ This function never writes outside of output buffer, and never reads outside of input buffer. It is therefore protected against malicious data packets
112
143
  */
113
144
 
114
145
 
146
+ int LZ4_sizeofState();
147
+ int LZ4_compress_withState (void* state, const char* source, char* dest, int inputSize);
148
+ int LZ4_compress_limitedOutput_withState (void* state, const char* source, char* dest, int inputSize, int maxOutputSize);
149
+
150
+ /*
151
+ These functions are provided should you prefer to allocate memory for compression tables with your own allocation methods.
152
+ To know how much memory must be allocated for the compression tables, use :
153
+ int LZ4_sizeofState();
154
+
155
+ Note that tables must be aligned on 4-bytes boundaries, otherwise compression will fail (return code 0).
156
+
157
+ The allocated memory can be provided to the compressions functions using 'void* state' parameter.
158
+ LZ4_compress_withState() and LZ4_compress_limitedOutput_withState() are equivalent to previously described functions.
159
+ They just use the externally allocated memory area instead of allocating their own (on stack, or on heap).
160
+ */
161
+
162
+
163
+ /**************************************
164
+ Streaming Functions
165
+ **************************************/
166
+ void* LZ4_create (const char* inputBuffer);
167
+ int LZ4_compress_continue (void* LZ4_Data, const char* source, char* dest, int inputSize);
168
+ int LZ4_compress_limitedOutput_continue (void* LZ4_Data, const char* source, char* dest, int inputSize, int maxOutputSize);
169
+ char* LZ4_slideInputBuffer (void* LZ4_Data);
170
+ int LZ4_free (void* LZ4_Data);
171
+
172
+ /*
173
+ These functions allow the compression of dependent blocks, where each block benefits from prior 64 KB within preceding blocks.
174
+ In order to achieve this, it is necessary to start creating the LZ4 Data Structure, thanks to the function :
175
+
176
+ void* LZ4_create (const char* inputBuffer);
177
+ The result of the function is the (void*) pointer on the LZ4 Data Structure.
178
+ This pointer will be needed in all other functions.
179
+ If the pointer returned is NULL, then the allocation has failed, and compression must be aborted.
180
+ The only parameter 'const char* inputBuffer' must, obviously, point at the beginning of input buffer.
181
+ The input buffer must be already allocated, and size at least 192KB.
182
+ 'inputBuffer' will also be the 'const char* source' of the first block.
183
+
184
+ All blocks are expected to lay next to each other within the input buffer, starting from 'inputBuffer'.
185
+ To compress each block, use either LZ4_compress_continue() or LZ4_compress_limitedOutput_continue().
186
+ Their behavior are identical to LZ4_compress() or LZ4_compress_limitedOutput(),
187
+ but require the LZ4 Data Structure as their first argument, and check that each block starts right after the previous one.
188
+ If next block does not begin immediately after the previous one, the compression will fail (return 0).
189
+
190
+ When it's no longer possible to lay the next block after the previous one (not enough space left into input buffer), a call to :
191
+ char* LZ4_slideInputBuffer(void* LZ4_Data);
192
+ must be performed. It will typically copy the latest 64KB of input at the beginning of input buffer.
193
+ Note that, for this function to work properly, minimum size of an input buffer must be 192KB.
194
+ ==> The memory position where the next input data block must start is provided as the result of the function.
195
+
196
+ Compression can then resume, using LZ4_compress_continue() or LZ4_compress_limitedOutput_continue(), as usual.
197
+
198
+ When compression is completed, a call to LZ4_free() will release the memory used by the LZ4 Data Structure.
199
+ */
200
+
201
+ int LZ4_sizeofStreamState();
202
+ int LZ4_resetStreamState(void* state, const char* inputBuffer);
203
+
204
+ /*
205
+ These functions achieve the same result as :
206
+ void* LZ4_create (const char* inputBuffer);
207
+
208
+ They are provided here to allow the user program to allocate memory using its own routines.
209
+
210
+ To know how much space must be allocated, use LZ4_sizeofStreamState();
211
+ Note also that space must be 4-bytes aligned.
212
+
213
+ Once space is allocated, you must initialize it using : LZ4_resetStreamState(void* state, const char* inputBuffer);
214
+ void* state is a pointer to the space allocated.
215
+ It must be aligned on 4-bytes boundaries, and be large enough.
216
+ The parameter 'const char* inputBuffer' must, obviously, point at the beginning of input buffer.
217
+ The input buffer must be already allocated, and size at least 192KB.
218
+ 'inputBuffer' will also be the 'const char* source' of the first block.
219
+
220
+ The same space can be re-used multiple times, just by initializing it each time with LZ4_resetStreamState().
221
+ return value of LZ4_resetStreamState() must be 0 is OK.
222
+ Any other value means there was an error (typically, pointer is not aligned on 4-bytes boundaries).
223
+ */
224
+
225
+
226
+ int LZ4_decompress_safe_withPrefix64k (const char* source, char* dest, int inputSize, int maxOutputSize);
227
+ int LZ4_decompress_fast_withPrefix64k (const char* source, char* dest, int outputSize);
228
+
229
+ /*
230
+ *_withPrefix64k() :
231
+ These decoding functions work the same as their "normal name" versions,
232
+ but can use up to 64KB of data in front of 'char* dest'.
233
+ These functions are necessary to decode inter-dependant blocks.
234
+ */
235
+
236
+
237
+ /**************************************
238
+ Obsolete Functions
239
+ **************************************/
240
+ /*
241
+ These functions are deprecated and should no longer be used.
242
+ They are provided here for compatibility with existing user programs.
243
+ */
244
+ static inline int LZ4_uncompress (const char* source, char* dest, int outputSize) { return LZ4_decompress_fast(source, dest, outputSize); }
245
+ static inline int LZ4_uncompress_unknownOutputSize (const char* source, char* dest, int isize, int maxOutputSize) { return LZ4_decompress_safe(source, dest, isize, maxOutputSize); }
246
+
247
+
248
+
115
249
  #if defined (__cplusplus)
116
250
  }
117
251
  #endif