diff options
Diffstat (limited to 'lz4.h')
-rw-r--r-- | lz4.h | 69 |
1 files changed, 48 insertions, 21 deletions
@@ -50,8 +50,8 @@ extern "C" { // Simple Functions
//****************************
-int LZ4_compress (const char* source, char* dest, int inputSize);
-int LZ4_uncompress (const char* source, char* dest, int outputSize);
+int LZ4_compress (const char* source, char* dest, int inputSize);
+int LZ4_decompress_safe (const char* source, char* dest, int inputSize, int maxOutputSize);
/*
LZ4_compress() :
@@ -63,13 +63,11 @@ LZ4_compress() : return : the number of bytes written in buffer dest
or 0 if the compression fails
-LZ4_uncompress() :
- outputSize : is the original (uncompressed) size
- return : the number of bytes read in the source buffer (in other words, the compressed size)
- If the source stream is malformed, the function will stop decoding and return a negative result, indicating the byte position of the faulty instruction.
- note : This function never writes outside of provided buffers, and never modifies input buffer.
- Destination buffer must be already allocated.
- Its size must be a minimum of 'output_size' bytes.
+LZ4_decompress_safe() :
+ maxOutputSize : is the size of the destination buffer (which must be already allocated)
+ return : the number of bytes decoded in the destination buffer (necessarily <= maxOutputSize)
+ If the source stream is malformed, the function will stop decoding and return a negative result.
+ This function never writes outside of output buffer, and never reads outside of input buffer. It is therefore protected against malicious data packets
*/
@@ -85,7 +83,7 @@ LZ4_compressBound() : Provides the maximum size that LZ4 may output in a "worst case" scenario (input data not compressible)
primarily useful for memory allocation of output buffer.
inline function is recommended for the general case,
- but macro is also provided when results need to be evaluated at compile time (such as table size allocation).
+ macro is also provided when result needs to be evaluated at compile time (such as table size allocation).
isize : is the input size. Max supported value is ~1.9GB
return : maximum output size in a "worst case" scenario
@@ -93,35 +91,64 @@ LZ4_compressBound() : */
-int LZ4_compress_limitedOutput (const char* source, char* dest, int isize, int maxOutputSize);
+int LZ4_compress_limitedOutput (const char* source, char* dest, int inputSize, int maxOutputSize);
/*
LZ4_compress_limitedOutput() :
- Compress 'isize' bytes from 'source' into an output buffer 'dest' of maximum size 'maxOutputSize'.
+ Compress 'inputSize' bytes from 'source' into an output buffer 'dest' of maximum size 'maxOutputSize'.
If it cannot achieve it, compression will stop, and result of the function will be zero.
This function never writes outside of provided output buffer.
- isize : is the input size. Max supported value is ~1.9GB
+ inputSize : Max supported value is ~1.9GB
maxOutputSize : is the size of the destination buffer (which must be already allocated)
return : the number of bytes written in buffer 'dest'
or 0 if the compression fails
*/
-int LZ4_uncompress_unknownOutputSize (const char* source, char* dest, int isize, int maxOutputSize);
+int LZ4_decompress_fast (const char* source, char* dest, int outputSize);
/*
-LZ4_uncompress_unknownOutputSize() :
- isize : is the input size, therefore the compressed size
- maxOutputSize : is the size of the destination buffer (which must be already allocated)
+LZ4_decompress_fast() :
+ outputSize : is the original (uncompressed) size
+ return : the number of bytes read from the source buffer (in other words, the compressed size)
+ If the source stream is malformed, the function will stop decoding and return a negative result.
+ note : This function is a bit faster than LZ4_decompress_safe()
+ This function never writes outside of output buffers, and never read before input buffer, but may read beyond input buffer (since it doesn't know its size) in case of malicious data packet.
+ Use this function preferably into a trusted environment (data to decode comes from a trusted source).
+ Destination buffer must be already allocated. Its size must be a minimum of 'outputSize' bytes.
+*/
+
+int LZ4_decompress_safe_partial (const char* source, char* dest, int inputSize, int targetOutputSize, int maxOutputSize);
+
+/*
+LZ4_decompress_safe_partial() :
+ This function decompress a compressed block of size 'inputSize' at position 'source'
+ into output buffer 'dest' of size 'maxOutputSize'.
+ The function stops decompressing operation as soon as 'targetOutputSize' has been reached,
+ reducing decompression time.
return : the number of bytes decoded in the destination buffer (necessarily <= maxOutputSize)
- If the source stream is malformed, the function will stop decoding and return a negative result, indicating the byte position of the faulty instruction
- This function never writes beyond dest + maxOutputSize, and is therefore protected against malicious data packets
- note : Destination buffer must be already allocated.
- This version is slightly slower than LZ4_uncompress()
+ Note : this number might be < 'targetOutputSize' if the number of bytes to decode into the compressed block is not enough.
+ Always control how many bytes were decoded.
+ If the source stream is malformed, the function will stop decoding and return a negative result.
+ This function never writes outside of output buffer, and never reads outside of input buffer. It is therefore protected against malicious data packets
*/
+//****************************
+// Obsolete Functions
+//****************************
+
+inline int LZ4_uncompress (const char* source, char* dest, int outputSize) { return LZ4_decompress_fast(source, dest, outputSize); }
+inline int LZ4_uncompress_unknownOutputSize (const char* source, char* dest, int isize, int maxOutputSize) { return LZ4_decompress_safe(source, dest, isize, maxOutputSize); }
+
+/*
+These functions are deprecated and should no longer be used.
+They are provided here for compatibility with existing user programs.
+*/
+
+
+
#if defined (__cplusplus)
}
#endif
|