summaryrefslogtreecommitdiffstats
path: root/lz4.h
diff options
context:
space:
mode:
authorYann Collet <yann.collet.73@gmail.com>2014-07-14 22:04:10 (GMT)
committerYann Collet <yann.collet.73@gmail.com>2014-07-14 22:04:10 (GMT)
commitfbe14d128e881abb12aaf55d5ff31be0066b69ad (patch)
tree266adb51d292714d52eee37e794eaa2a61cd9437 /lz4.h
parentd3c43d3251057da84f036c1e43fe015d2731cdd1 (diff)
downloadlz4-fbe14d128e881abb12aaf55d5ff31be0066b69ad.zip
lz4-fbe14d128e881abb12aaf55d5ff31be0066b69ad.tar.gz
lz4-fbe14d128e881abb12aaf55d5ff31be0066b69ad.tar.bz2
Modified : lz4 streaming API, strong types
Diffstat (limited to 'lz4.h')
-rw-r--r--lz4.h83
1 files changed, 45 insertions, 38 deletions
diff --git a/lz4.h b/lz4.h
index 275655d..3a03a8e 100644
--- a/lz4.h
+++ b/lz4.h
@@ -64,7 +64,7 @@ extern "C" {
**************************************/
int LZ4_compress (const char* source, char* dest, int inputSize);
-int LZ4_decompress_safe (const char* source, char* dest, int compressedSize, int maxOutputSize);
+int LZ4_decompress_safe (const char* source, char* dest, int compressedSize, int maxDecompressedSize);
/*
LZ4_compress() :
@@ -78,8 +78,8 @@ LZ4_compress() :
LZ4_decompress_safe() :
compressedSize : is obviously the source size
- 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)
+ maxDecompressedSize : is the size of the destination buffer, which must be already allocated.
+ return : the number of bytes decompressed into the destination buffer (necessarily <= maxDecompressedSize)
If the destination buffer is not large enough, decoding will stop and output an error code (<0).
If the source stream is detected malformed, the function will stop decoding and return a negative result.
This function is protected against buffer overflow exploits :
@@ -132,12 +132,12 @@ int LZ4_compress_limitedOutput (const char* source, char* dest, int inputSize, i
LZ4_decompress_fast() :
originalSize : is the original and therefore 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.
+ If the source stream is detected malformed, the function will stop decoding and return a negative result.
Destination buffer must be already allocated. Its size must be a minimum of 'originalSize' bytes.
- note : This function is a bit faster than LZ4_decompress_safe()
- It provides fast decompression and fully respect memory boundaries for properly formed compressed data.
- It does not provide full protection against intentionnally modified data stream.
- Use this function in a trusted environment (data to decode comes from a trusted source).
+ note : This function fully respect memory boundaries for properly formed compressed data.
+ It is a bit faster than LZ4_decompress_safe().
+ However, it does not provide any protection against intentionnally modified data stream (malicious input).
+ Use this function in trusted environment only (data to decode comes from a trusted source).
*/
int LZ4_decompress_fast (const char* source, char* dest, int originalSize);
@@ -145,16 +145,16 @@ int LZ4_decompress_fast (const char* source, char* dest, int originalSize);
/*
LZ4_decompress_safe_partial() :
This function decompress a compressed block of size 'compressedSize' at position 'source'
- into output buffer 'dest' of size 'maxOutputSize'.
+ into destination buffer 'dest' of size 'maxDecompressedSize'.
The function tries to stop decompressing operation as soon as 'targetOutputSize' has been reached,
reducing decompression time.
- return : the number of bytes decoded in the destination buffer (necessarily <= maxOutputSize)
+ return : the number of bytes decoded in the destination buffer (necessarily <= maxDecompressedSize)
Note : this number can be < 'targetOutputSize' should the compressed block to decode be smaller.
Always control how many bytes were decoded.
If the source stream is detected 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
*/
-int LZ4_decompress_safe_partial (const char* source, char* dest, int compressedSize, int targetOutputSize, int maxOutputSize);
+int LZ4_decompress_safe_partial (const char* source, char* dest, int compressedSize, int targetOutputSize, int maxDecompressedSize);
/***********************************************
@@ -178,6 +178,14 @@ typedef struct { unsigned int table[LZ4_STREAMSIZE_U32]; } LZ4_stream_t;
void LZ4_resetStream (LZ4_stream_t* LZ4_stream);
/*
+ * If you prefer dynamic allocation methods,
+ * LZ4_createStream will allocate and initialize an LZ4_stream_t structure
+ * LZ4_freeStream releases its memory.
+ */
+LZ4_stream_t* LZ4_createStream(void);
+int LZ4_freeStream (LZ4_stream_t* LZ4_stream);
+
+/*
* LZ4_loadDict
* Use this function to load a static dictionary into LZ4_stream.
* Any previous data will be forgotten, only 'dictionary' will remain in memory.
@@ -221,38 +229,37 @@ int LZ4_saveDict (LZ4_stream_t* LZ4_stream, char* safeBuffer, int dictSize);
/*
* LZ4_streamDecode_t
* information structure to track an LZ4 stream.
- * important : set this structure content to zero before first use !
+ * important : init this structure content using LZ4_setStreamDecode or memset() before first use !
*/
typedef struct { unsigned int table[LZ4_STREAMDECODESIZE_U32]; } LZ4_streamDecode_t;
/*
+ * LZ4_setStreamDecode
+ * Use this function to instruct where to find the dictionary.
+ * This function can be used to specify a static dictionary,
+ * or to instruct where to find some previously decoded data saved into a different memory space.
+ * Setting a size of 0 is allowed (same effect as no dictionary).
+ * Return : 1 if OK, 0 if error
+ */
+int LZ4_setStreamDecode (LZ4_streamDecode_t* LZ4_streamDecode, const char* dictionary, int dictSize);
+
+/*
* If you prefer dynamic allocation methods,
- * LZ4_createStreamDecode()
- * provides a pointer (void*) towards an initialized LZ4_streamDecode_t structure.
- * LZ4_free just frees it.
+ * LZ4_createStreamDecode will allocate and initialize an LZ4_streamDecode_t structure
+ * LZ4_freeStreamDecode releases its memory.
*/
-void* LZ4_createStreamDecode();
-int LZ4_free (void* LZ4_stream); /* yes, it's the same one as for compression */
+LZ4_streamDecode_t* LZ4_createStreamDecode(void);
+int LZ4_freeStreamDecode (LZ4_streamDecode_t* LZ4_stream);
/*
*_continue() :
These decoding functions allow decompression of multiple blocks in "streaming" mode.
Previously decoded blocks must still be available at the memory position where they were decoded.
If it's not possible, save the relevant part of decoded data into a safe buffer,
- and indicate where it stands using LZ4_setDictDecode()
+ and indicate where its new address using LZ4_setDictDecode()
*/
-int LZ4_decompress_safe_continue (void* LZ4_streamDecode, const char* source, char* dest, int compressedSize, int maxOutputSize);
-int LZ4_decompress_fast_continue (void* LZ4_streamDecode, const char* source, char* dest, int originalSize);
-
-/*
- * LZ4_setDictDecode
- * Use this function to instruct where to find the dictionary.
- * This function can be used to specify a static dictionary,
- * or to instruct where to find some previously decoded data saved into a different memory space.
- * Setting a size of 0 is allowed (same effect as no dictionary).
- * Return : 1 if OK, 0 if error
- */
-int LZ4_setDictDecode (void* LZ4_streamDecode, const char* dictionary, int dictSize);
+int LZ4_decompress_safe_continue (LZ4_streamDecode_t* LZ4_streamDecode, const char* source, char* dest, int compressedSize, int maxOutputSize);
+int LZ4_decompress_fast_continue (LZ4_streamDecode_t* LZ4_streamDecode, const char* source, char* dest, int originalSize);
/*
@@ -268,7 +275,6 @@ int LZ4_decompress_fast_usingDict (const char* source, char* dest, int originalS
-
/**************************************
Obsolete Functions
**************************************/
@@ -278,9 +284,10 @@ These function names are deprecated and should no longer be used.
They are only provided here for compatibility with older user programs.
- LZ4_uncompress is the same as LZ4_decompress_fast
- LZ4_uncompress_unknownOutputSize is the same as LZ4_decompress_safe
-*/
-int LZ4_uncompress (const char* source, char* dest, int outputSize);
-int LZ4_uncompress_unknownOutputSize (const char* source, char* dest, int isize, int maxOutputSize);
+These function prototypes are now disabled; uncomment them if you really need them.
+It is highly recommended to stop using these functions and migrated to newer ones */
+/* int LZ4_uncompress (const char* source, char* dest, int outputSize); */
+/* int LZ4_uncompress_unknownOutputSize (const char* source, char* dest, int isize, int maxOutputSize); */
/* Obsolete functions for externally allocated state; use streaming interface instead */
int LZ4_sizeofState(void);
@@ -289,12 +296,12 @@ int LZ4_compress_limitedOutput_withState (void* state, const char* source, char*
/*
* If you prefer dynamic allocation methods,
- * LZ4_createStream
- * provides a pointer (void*) towards an initialized LZ4_stream_t structure.
+ * LZ4_createStreamDecode()
+ * provides a pointer (void*) towards an initialized LZ4_streamDecode_t structure.
* LZ4_free just frees it.
*/
-void* LZ4_createStream(void);
-int LZ4_free (void* LZ4_stream);
+/* void* LZ4_createStreamDecode(void); */
+/*int LZ4_free (void* LZ4_stream); yes, it's the same one as for compression */
/* Obsolete streaming functions; use new streaming interface whenever possible */
void* LZ4_create (const char* inputBuffer);