precise again that LZ4 decoder needs metadata
and that such metadata must be provided / sent / saved by the application.
This commit is contained in:
parent
3a3639e32d
commit
1d759576b9
@ -21,7 +21,7 @@
|
|||||||
</ol>
|
</ol>
|
||||||
<hr>
|
<hr>
|
||||||
<a name="Chapter1"></a><h2>Introduction</h2><pre>
|
<a name="Chapter1"></a><h2>Introduction</h2><pre>
|
||||||
LZ4 is lossless compression algorithm, providing compression speed at 500 MB/s per core,
|
LZ4 is lossless compression algorithm, providing compression speed >500 MB/s per core,
|
||||||
scalable with multi-cores CPU. It features an extremely fast decoder, with speed in
|
scalable with multi-cores CPU. It features an extremely fast decoder, with speed in
|
||||||
multiple GB/s per core, typically reaching RAM speed limits on multi-core systems.
|
multiple GB/s per core, typically reaching RAM speed limits on multi-core systems.
|
||||||
|
|
||||||
@ -33,7 +33,10 @@
|
|||||||
- unbounded multiple steps (described as Streaming compression)
|
- unbounded multiple steps (described as Streaming compression)
|
||||||
|
|
||||||
lz4.h generates and decodes LZ4-compressed blocks (doc/lz4_Block_format.md).
|
lz4.h generates and decodes LZ4-compressed blocks (doc/lz4_Block_format.md).
|
||||||
Decompressing a block requires additional metadata, such as its compressed size.
|
Decompressing such a compressed block requires additional metadata.
|
||||||
|
Exact metadata depends on exact decompression function.
|
||||||
|
For the typical case of LZ4_decompress_safe(),
|
||||||
|
metadata includes block's compressed size, and maximum bound of decompressed size.
|
||||||
Each application is free to encode and pass such metadata in whichever way it wants.
|
Each application is free to encode and pass such metadata in whichever way it wants.
|
||||||
|
|
||||||
lz4.h only handle blocks, it can not generate Frames.
|
lz4.h only handle blocks, it can not generate Frames.
|
||||||
@ -66,27 +69,35 @@
|
|||||||
<a name="Chapter4"></a><h2>Simple Functions</h2><pre></pre>
|
<a name="Chapter4"></a><h2>Simple Functions</h2><pre></pre>
|
||||||
|
|
||||||
<pre><b>int LZ4_compress_default(const char* src, char* dst, int srcSize, int dstCapacity);
|
<pre><b>int LZ4_compress_default(const char* src, char* dst, int srcSize, int dstCapacity);
|
||||||
</b><p> Compresses 'srcSize' bytes from buffer 'src'
|
</b><p> Compresses 'srcSize' bytes from buffer 'src'
|
||||||
into already allocated 'dst' buffer of size 'dstCapacity'.
|
into already allocated 'dst' buffer of size 'dstCapacity'.
|
||||||
Compression is guaranteed to succeed if 'dstCapacity' >= LZ4_compressBound(srcSize).
|
Compression is guaranteed to succeed if 'dstCapacity' >= LZ4_compressBound(srcSize).
|
||||||
It also runs faster, so it's a recommended setting.
|
It also runs faster, so it's a recommended setting.
|
||||||
If the function cannot compress 'src' into a more limited 'dst' budget,
|
If the function cannot compress 'src' into a more limited 'dst' budget,
|
||||||
compression stops *immediately*, and the function result is zero.
|
compression stops *immediately*, and the function result is zero.
|
||||||
In which case, 'dst' content is undefined (invalid).
|
In which case, 'dst' content is undefined (invalid).
|
||||||
srcSize : max supported value is LZ4_MAX_INPUT_SIZE.
|
srcSize : max supported value is LZ4_MAX_INPUT_SIZE.
|
||||||
dstCapacity : size of buffer 'dst' (which must be already allocated)
|
dstCapacity : size of buffer 'dst' (which must be already allocated)
|
||||||
@return : the number of bytes written into buffer 'dst' (necessarily <= dstCapacity)
|
@return : the number of bytes written into buffer 'dst' (necessarily <= dstCapacity)
|
||||||
or 0 if compression fails
|
or 0 if compression fails
|
||||||
Note : This function is protected against buffer overflow scenarios (never writes outside 'dst' buffer, nor read outside 'source' buffer).
|
Note : This function is protected against buffer overflow scenarios (never writes outside 'dst' buffer, nor read outside 'source' buffer).
|
||||||
|
|
||||||
</p></pre><BR>
|
</p></pre><BR>
|
||||||
|
|
||||||
<pre><b>int LZ4_decompress_safe (const char* src, char* dst, int compressedSize, int dstCapacity);
|
<pre><b>int LZ4_decompress_safe (const char* src, char* dst, int compressedSize, int dstCapacity);
|
||||||
</b><p> compressedSize : is the exact complete size of the compressed block.
|
</b><p> compressedSize : is the exact complete size of the compressed block.
|
||||||
dstCapacity : is the size of destination buffer, which must be already allocated.
|
dstCapacity : is the size of destination buffer (which must be already allocated), presumed an upper bound of decompressed size.
|
||||||
@return : the number of bytes decompressed into destination buffer (necessarily <= dstCapacity)
|
@return : the number of bytes decompressed into destination buffer (necessarily <= dstCapacity)
|
||||||
If destination buffer is not large enough, decoding will stop and output an error code (negative value).
|
If destination buffer is not large enough, decoding will stop and output an error code (negative value).
|
||||||
If the source stream is detected 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.
|
||||||
Note : This function is protected against malicious data packets (never writes outside 'dst' buffer, nor read outside 'source' buffer).
|
Note 1 : This function is protected against malicious data packets :
|
||||||
|
it will never writes outside 'dst' buffer, nor read outside 'source' buffer,
|
||||||
|
even if the compressed block is maliciously modified to order the decoder to do these actions.
|
||||||
|
In such case, the decoder stops immediately, and considers the compressed block malformed.
|
||||||
|
Note 2 : compressedSize and dstCapacity must be provided to the function, the compressed block does not contain them.
|
||||||
|
The implementation is free to send / store / derive this information in whichever way is most beneficial.
|
||||||
|
If there is a need for a different format which bundles together both compressed data and its metadata, consider looking at lz4frame.h instead.
|
||||||
|
|
||||||
</p></pre><BR>
|
</p></pre><BR>
|
||||||
|
|
||||||
<a name="Chapter5"></a><h2>Advanced Functions</h2><pre></pre>
|
<a name="Chapter5"></a><h2>Advanced Functions</h2><pre></pre>
|
||||||
|
53
lib/lz4.h
53
lib/lz4.h
@ -46,7 +46,7 @@ extern "C" {
|
|||||||
/**
|
/**
|
||||||
Introduction
|
Introduction
|
||||||
|
|
||||||
LZ4 is lossless compression algorithm, providing compression speed at 500 MB/s per core,
|
LZ4 is lossless compression algorithm, providing compression speed >500 MB/s per core,
|
||||||
scalable with multi-cores CPU. It features an extremely fast decoder, with speed in
|
scalable with multi-cores CPU. It features an extremely fast decoder, with speed in
|
||||||
multiple GB/s per core, typically reaching RAM speed limits on multi-core systems.
|
multiple GB/s per core, typically reaching RAM speed limits on multi-core systems.
|
||||||
|
|
||||||
@ -58,7 +58,10 @@ extern "C" {
|
|||||||
- unbounded multiple steps (described as Streaming compression)
|
- unbounded multiple steps (described as Streaming compression)
|
||||||
|
|
||||||
lz4.h generates and decodes LZ4-compressed blocks (doc/lz4_Block_format.md).
|
lz4.h generates and decodes LZ4-compressed blocks (doc/lz4_Block_format.md).
|
||||||
Decompressing a block requires additional metadata, such as its compressed size.
|
Decompressing such a compressed block requires additional metadata.
|
||||||
|
Exact metadata depends on exact decompression function.
|
||||||
|
For the typical case of LZ4_decompress_safe(),
|
||||||
|
metadata includes block's compressed size, and maximum bound of decompressed size.
|
||||||
Each application is free to encode and pass such metadata in whichever way it wants.
|
Each application is free to encode and pass such metadata in whichever way it wants.
|
||||||
|
|
||||||
lz4.h only handle blocks, it can not generate Frames.
|
lz4.h only handle blocks, it can not generate Frames.
|
||||||
@ -129,29 +132,35 @@ LZ4LIB_API const char* LZ4_versionString (void); /**< library version string;
|
|||||||
* Simple Functions
|
* Simple Functions
|
||||||
**************************************/
|
**************************************/
|
||||||
/*! LZ4_compress_default() :
|
/*! LZ4_compress_default() :
|
||||||
Compresses 'srcSize' bytes from buffer 'src'
|
* Compresses 'srcSize' bytes from buffer 'src'
|
||||||
into already allocated 'dst' buffer of size 'dstCapacity'.
|
* into already allocated 'dst' buffer of size 'dstCapacity'.
|
||||||
Compression is guaranteed to succeed if 'dstCapacity' >= LZ4_compressBound(srcSize).
|
* Compression is guaranteed to succeed if 'dstCapacity' >= LZ4_compressBound(srcSize).
|
||||||
It also runs faster, so it's a recommended setting.
|
* It also runs faster, so it's a recommended setting.
|
||||||
If the function cannot compress 'src' into a more limited 'dst' budget,
|
* If the function cannot compress 'src' into a more limited 'dst' budget,
|
||||||
compression stops *immediately*, and the function result is zero.
|
* compression stops *immediately*, and the function result is zero.
|
||||||
In which case, 'dst' content is undefined (invalid).
|
* In which case, 'dst' content is undefined (invalid).
|
||||||
srcSize : max supported value is LZ4_MAX_INPUT_SIZE.
|
* srcSize : max supported value is LZ4_MAX_INPUT_SIZE.
|
||||||
dstCapacity : size of buffer 'dst' (which must be already allocated)
|
* dstCapacity : size of buffer 'dst' (which must be already allocated)
|
||||||
@return : the number of bytes written into buffer 'dst' (necessarily <= dstCapacity)
|
* @return : the number of bytes written into buffer 'dst' (necessarily <= dstCapacity)
|
||||||
or 0 if compression fails
|
* or 0 if compression fails
|
||||||
Note : This function is protected against buffer overflow scenarios (never writes outside 'dst' buffer, nor read outside 'source' buffer).
|
* Note : This function is protected against buffer overflow scenarios (never writes outside 'dst' buffer, nor read outside 'source' buffer).
|
||||||
*/
|
*/
|
||||||
LZ4LIB_API int LZ4_compress_default(const char* src, char* dst, int srcSize, int dstCapacity);
|
LZ4LIB_API int LZ4_compress_default(const char* src, char* dst, int srcSize, int dstCapacity);
|
||||||
|
|
||||||
/*! LZ4_decompress_safe() :
|
/*! LZ4_decompress_safe() :
|
||||||
compressedSize : is the exact complete size of the compressed block.
|
* compressedSize : is the exact complete size of the compressed block.
|
||||||
dstCapacity : is the size of destination buffer, which must be already allocated.
|
* dstCapacity : is the size of destination buffer (which must be already allocated), presumed an upper bound of decompressed size.
|
||||||
@return : the number of bytes decompressed into destination buffer (necessarily <= dstCapacity)
|
* @return : the number of bytes decompressed into destination buffer (necessarily <= dstCapacity)
|
||||||
If destination buffer is not large enough, decoding will stop and output an error code (negative value).
|
* If destination buffer is not large enough, decoding will stop and output an error code (negative value).
|
||||||
If the source stream is detected 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.
|
||||||
Note : This function is protected against malicious data packets (never writes outside 'dst' buffer, nor read outside 'source' buffer).
|
* Note 1 : This function is protected against malicious data packets :
|
||||||
*/
|
* it will never writes outside 'dst' buffer, nor read outside 'source' buffer,
|
||||||
|
* even if the compressed block is maliciously modified to order the decoder to do these actions.
|
||||||
|
* In such case, the decoder stops immediately, and considers the compressed block malformed.
|
||||||
|
* Note 2 : compressedSize and dstCapacity must be provided to the function, the compressed block does not contain them.
|
||||||
|
* The implementation is free to send / store / derive this information in whichever way is most beneficial.
|
||||||
|
* If there is a need for a different format which bundles together both compressed data and its metadata, consider looking at lz4frame.h instead.
|
||||||
|
*/
|
||||||
LZ4LIB_API int LZ4_decompress_safe (const char* src, char* dst, int compressedSize, int dstCapacity);
|
LZ4LIB_API int LZ4_decompress_safe (const char* src, char* dst, int compressedSize, int dstCapacity);
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user