summaryrefslogtreecommitdiffstats
path: root/lz4.h
diff options
context:
space:
mode:
authoryann.collet.73@gmail.com <yann.collet.73@gmail.com@650e7d94-2a16-8b24-b05c-7c0b3f6821cd>2013-04-26 14:37:46 (GMT)
committeryann.collet.73@gmail.com <yann.collet.73@gmail.com@650e7d94-2a16-8b24-b05c-7c0b3f6821cd>2013-04-26 14:37:46 (GMT)
commit40ae7043df0d78f91892d361b5e619b93c3c071d (patch)
tree0f127f7f05ea74b493c1bd034e770f2bdf4c9807 /lz4.h
parenta2e93db805918a84908373a579c44732d3e6854e (diff)
downloadlz4-40ae7043df0d78f91892d361b5e619b93c3c071d.zip
lz4-40ae7043df0d78f91892d361b5e619b93c3c071d.tar.gz
lz4-40ae7043df0d78f91892d361b5e619b93c3c071d.tar.bz2
- New naming : LZ4_decompress_safe() and LZ4_decompress_fast()
- New function : LZ4_decompress_safe_partial(), to decompress just enough data within a compressed block, saving CPU cycles - New source files : lz4_decoder.h, lz4_encoder.h, lz4hc_encoder.h - Improved speed of LZ4_decompress_fast() - Improved speed for compression of small blocks < 64KB - Improved speed for HC compression git-svn-id: https://lz4.googlecode.com/svn/trunk@94 650e7d94-2a16-8b24-b05c-7c0b3f6821cd
Diffstat (limited to 'lz4.h')
-rw-r--r--lz4.h69
1 files changed, 48 insertions, 21 deletions
diff --git a/lz4.h b/lz4.h
index 0e6a60c..e245e66 100644
--- a/lz4.h
+++ b/lz4.h
@@ -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