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-11-19 21:38:27 +00:00
|
|
|
#pragma once
|
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
|
|
|
|
|
|
|
//****************************
|
|
|
|
// Simple Functions
|
|
|
|
//****************************
|
|
|
|
|
2012-02-01 20:16:10 +00:00
|
|
|
int LZ4_compress (const char* source, char* dest, int isize);
|
|
|
|
int LZ4_uncompress (const char* source, char* dest, int osize);
|
2011-04-24 14:16:00 +00:00
|
|
|
|
|
|
|
/*
|
2011-11-15 22:06:33 +00:00
|
|
|
LZ4_compress() :
|
2012-04-03 19:34:15 +00:00
|
|
|
isize : is the input size. Max supported value is ~1.9GB
|
2012-02-25 19:13:16 +00:00
|
|
|
return : the number of bytes written in buffer dest
|
|
|
|
or 0 if the compression fails (if LZ4_COMPRESSMIN is set)
|
2011-05-21 07:18:49 +00:00
|
|
|
note : destination buffer must be already allocated.
|
2012-02-25 19:13:16 +00:00
|
|
|
destination buffer must be sized to handle worst cases situations (input data not compressible)
|
|
|
|
worst case size evaluation is provided by function LZ4_compressBound()
|
2011-04-24 14:16:00 +00:00
|
|
|
|
2011-11-15 22:06:33 +00:00
|
|
|
LZ4_uncompress() :
|
2011-09-25 21:34:35 +00:00
|
|
|
osize : is the output size, therefore the original size
|
2011-06-04 17:15:43 +00:00
|
|
|
return : the number of bytes read in the source buffer
|
|
|
|
If the source stream is malformed, the function will stop decoding and return a negative result, indicating the byte position of the faulty instruction
|
2012-02-25 19:13:16 +00:00
|
|
|
This function never writes beyond dest + osize, and is therefore protected against malicious data packets
|
|
|
|
note : destination buffer must be already allocated
|
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
|
|
|
|
2012-02-16 18:39:50 +00:00
|
|
|
int LZ4_compressBound(int isize);
|
|
|
|
|
|
|
|
/*
|
|
|
|
LZ4_compressBound() :
|
2012-02-25 19:13:16 +00:00
|
|
|
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.
|
2012-02-16 18:39:50 +00:00
|
|
|
|
2012-04-03 19:34:15 +00:00
|
|
|
isize : is the input size. Max supported value is ~1.9GB
|
2012-02-25 19:13:16 +00:00
|
|
|
return : maximum output size in a "worst case" scenario
|
|
|
|
note : this function is limited by "int" range (2^31-1)
|
2012-02-16 18:39:50 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2012-02-01 20:16:10 +00:00
|
|
|
int LZ4_uncompress_unknownOutputSize (const char* source, char* dest, int isize, int maxOutputSize);
|
2011-06-04 17:15:43 +00:00
|
|
|
|
|
|
|
/*
|
2011-11-15 22:06:33 +00:00
|
|
|
LZ4_uncompress_unknownOutputSize() :
|
2011-09-25 21:34:35 +00:00
|
|
|
isize : is the input size, therefore the compressed size
|
|
|
|
maxOutputSize : is the size of the destination buffer (which must be already allocated)
|
2011-06-04 17:15:43 +00:00
|
|
|
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
|
2012-02-25 19:13:16 +00:00
|
|
|
This function never writes beyond dest + maxOutputSize, and is therefore protected against malicious data packets
|
|
|
|
note : This version is slightly slower than LZ4_uncompress()
|
2011-06-04 17:15:43 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2012-02-01 20:16:10 +00:00
|
|
|
int LZ4_compressCtx(void** ctx, const char* source, char* dest, int isize);
|
2012-02-25 19:13:16 +00:00
|
|
|
int LZ4_compress64kCtx(void** ctx, const char* source, char* dest, int isize);
|
2011-04-24 14:16:00 +00:00
|
|
|
|
|
|
|
/*
|
2011-11-15 22:06:33 +00:00
|
|
|
LZ4_compressCtx() :
|
2011-05-20 19:54:28 +00:00
|
|
|
This function explicitly handles the CTX memory structure.
|
2012-02-25 19:13:16 +00:00
|
|
|
It avoids allocating/deallocating memory between each call, improving performance when malloc is heavily invoked.
|
|
|
|
This function is only useful when memory is allocated into the heap (HASH_LOG value beyond STACK_LIMIT)
|
|
|
|
Performance difference will be noticeable only when repetitively calling the compression function over many small segments.
|
|
|
|
Note : by default, memory is allocated into the stack, therefore "malloc" is not invoked.
|
|
|
|
LZ4_compress64kCtx() :
|
|
|
|
Same as LZ4_compressCtx(), but specific to small inputs (<64KB).
|
|
|
|
isize *Must* be <64KB, otherwise the output will be corrupted.
|
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-04-24 14:16:00 +00:00
|
|
|
*/
|
|
|
|
|
2011-04-25 08:24:43 +00:00
|
|
|
|
|
|
|
#if defined (__cplusplus)
|
|
|
|
}
|
|
|
|
#endif
|