2011-04-24 14:16:00 +00:00
|
|
|
/*
|
|
|
|
LZ4 - Fast LZ compression algorithm
|
|
|
|
Header File
|
2011-04-26 23:49:24 +00:00
|
|
|
Copyright (C) 2011, Yann Collet.
|
2011-05-21 07:18:49 +00:00
|
|
|
BSD License
|
2011-04-24 14:16:00 +00:00
|
|
|
|
2011-04-26 23:49:24 +00:00
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions are
|
|
|
|
met:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
* Redistributions in binary form must reproduce the above
|
|
|
|
copyright notice, this list of conditions and the following disclaimer
|
|
|
|
in the documentation and/or other materials provided with the
|
|
|
|
distribution.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2011-04-24 14:16:00 +00:00
|
|
|
*/
|
|
|
|
|
2011-04-25 08:24:43 +00:00
|
|
|
#if defined (__cplusplus)
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2011-04-24 14:16:00 +00:00
|
|
|
|
2011-04-26 23:49:24 +00:00
|
|
|
//****************************
|
|
|
|
// Instructions
|
|
|
|
//****************************
|
|
|
|
|
2011-05-21 07:18:49 +00:00
|
|
|
// Uncomment next line to ensure that LZ4_Decode will never write in destination buffer more than "decompressedSize" bytes
|
|
|
|
// If commented, the decoder may write up to 3 bytes more than decompressedSize, so provide extra room in dest buffer for that
|
|
|
|
// Recommendation : keep commented, for improved performance; ensure that destination buffer is at least decompressedSize + 3 Bytes
|
2011-04-26 23:49:24 +00:00
|
|
|
// #define SAFEWRITEBUFFER
|
|
|
|
|
|
|
|
|
2011-04-24 14:16:00 +00:00
|
|
|
//****************************
|
|
|
|
// Simple Functions
|
|
|
|
//****************************
|
|
|
|
|
|
|
|
int LZ4_compress (char* source, char* dest, int isize);
|
|
|
|
int LZ4_decode (char* source, char* dest, int isize);
|
|
|
|
|
|
|
|
/*
|
|
|
|
LZ4_compress :
|
|
|
|
return : the number of bytes in compressed buffer dest
|
2011-05-21 07:18:49 +00:00
|
|
|
note : destination buffer must be already allocated.
|
|
|
|
To avoid any problem, size it to handle worst cases situations (input data not compressible)
|
|
|
|
Worst case size is : "inputsize + 0.4%", with "0.4%" being at least 8 bytes.
|
2011-04-24 14:16:00 +00:00
|
|
|
|
|
|
|
LZ4_decode :
|
|
|
|
return : the number of bytes in decoded buffer dest
|
2011-05-25 22:25:57 +00:00
|
|
|
note 1 : isize is the input size, therefore the compressed size
|
|
|
|
note 2 : destination buffer must be already allocated.
|
|
|
|
The program calling the decoder must know in advance the size of decoded stream to properly allocate the destination buffer
|
|
|
|
Note that, in fast mode, the destination buffer size must be at least "decompressedSize + 3 Bytes"
|
2011-04-24 14:16:00 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
//****************************
|
2011-04-26 23:49:24 +00:00
|
|
|
// Advanced Functions
|
2011-04-24 14:16:00 +00:00
|
|
|
//****************************
|
2011-05-20 19:54:28 +00:00
|
|
|
|
2011-04-24 14:16:00 +00:00
|
|
|
int LZ4_compressCtx(void** ctx, char* source, char* dest, int isize);
|
|
|
|
|
|
|
|
/*
|
|
|
|
LZ4_compressCtx :
|
2011-05-20 19:54:28 +00:00
|
|
|
This function explicitly handles the CTX memory structure.
|
|
|
|
It avoids allocating/deallocating memory between each call, improving performance when malloc is time-consuming.
|
2011-04-24 14:16:00 +00:00
|
|
|
|
|
|
|
On first call : provide a *ctx=NULL; It will be automatically allocated.
|
|
|
|
On next calls : reuse the same ctx pointer.
|
|
|
|
Use different pointers for different threads when doing multi-threading.
|
2011-04-26 23:49:24 +00:00
|
|
|
|
2011-05-20 19:54:28 +00:00
|
|
|
note : performance difference is small, mostly noticeable when repetitively calling the compression algorithm on many small segments.
|
2011-04-24 14:16:00 +00:00
|
|
|
*/
|
|
|
|
|
2011-04-25 08:24:43 +00:00
|
|
|
|
|
|
|
#if defined (__cplusplus)
|
|
|
|
}
|
|
|
|
#endif
|