LzmaCompress

Syntax

#include <cafe.h>
#include <lzmalib.h>

MY_STDAPI LzmaCompress(unsigned char *dest, size_t *destLen,
		       const unsigned char *src, size_t srcLen,
		       unsigned char *outProps,
		       size_t *outPropsSize, /* *outPropsSize must be = 5 */
		       int level,            /* 0 <= level <= 9, default = 5 */
		       unsigned dictSize,    /* default = (1 << 24) */
		       int lc,               /* 0 <= lc <= 8, default = 3  */
		       int lp,               /* 0 <= lp <= 4, default = 0  */
		       int pb,               /* 0 <= pb <= 4, default = 2  */
		       int fb,               /* 5 <= fb <= 273, default = 32 */
		       int numThreads        /* 1 or 2, default = 2 */
		      );

Parameters

dest In: Output data.
Out: Processed output size.
destLen In: Output data size.
Out: Processed output size.
src Input data.
srcLen Input data size.
outProps Pointer to a 5-byte buffer that receives the LZMA properties specified in this call.
Offset Size Description
0 1 lc, lb, and pb in encoded form.
1 4 dictSize (in little-endian order).
outPropsSize In: pointer to the size of outProps buffer; *outPropsSize = LZMA_PROPS_SIZE = 5.
Out: pointer to the size of written properties in outProps buffer; *outPropsSize = LZMA_PROPS_SIZE = 5.
level Compression level: 0 ≤ level ≤ 9. The default value for level is 5.
level dicSize Algorithm fb
016 KB032
164 KB032
2256 KB032
31 MB032
44 MB032
516 MB132
632 MB132
7+64 MB164
Algorithm = 0 means fast method
Algorithm = 1 means normal method
dictSize The dictionary size in bytes. The maximum value is:

128 MB = (1 << 27) bytes for 32-bit version
1 GB = (1 << 30) bytes for 64-bit version

The default value is 16 MB = (1 << 24) bytes. It is recommended to use the dictionary that is larger than 4 KB and that can be calculated as (1 << N) or (3 << N) sizes.
lc The number of literal context bits (high bits of previous literal). It can be in the range from 0 to 8. The default value is 3. Occasionally lc=4 provides the gain for big files.
lp The number of literal pos bits (low bits of current position for literals). It can be in the range from 0 to 4. The default value is 0. The lp switch is intended for periodical data when the period is equal to 2^lp. For example, for 32-bit (4 bytes) periodical data you can use lp=2. Often it is better to set lc=0, if you change lp switch.
pb The number of pos bits (low bits of current position). It can be in the range from 0 to 4. The default value is 2. The pb switch is intended for periodical data when the period is equal 2^pb.
fb Word size (the number of fast bytes). It can be in the range from 5 to 273. The default value is 32. Usually, a big number provides a little bit better compression ratio and slower compression process.
numThreads The number of threads, 1 or 2. The default value is 2. Fast mode (Algorithm = 0) can use only 1 thread.

Return Values

SZ_OK OK.
SZ_ERROR_MEM Memory allocation error.
SZ_ERROR_PARAM Incorrect parameter.
SZ_ERROR_OUTPUT_EOF Output buffer overflow.
SZ_ERROR_THREAD Errors in multithreading functions (only for Mt version).

Description

Compress the data referenced by src into the buffer referenced by dest using the LZMA compression algorithm from the public domain LZMALIB version 9.20 that is available at www.7-zip.org (http://www.7-zip.org/download.html).

The LZMA encoder uses default values for any parameter if it is -1 for any from level, loc, lp, pb, fb, numThreads; or 0 for dictSize.

Memory Requirements

For compression, (dictSize * 11.5 + 6 MB) + state_size is required, where state_size = (4 + (1.5 << (lc + lp))) KB. By default (lc=3, lp=0), state_size = 16 KB.

Demo

There is a demonstration of the usage of compression and decompression in the demo folder:

$CAFE_ROOT/system/src/demo/uselzma

A demonstration involving the parsing and extraction from a 7-Zip file created in Windows is in the demo folder:

$CAFE_ROOT/system/src/demo/szfile

Do Not Call From

None.

See Also

LzmaUncompress

Revision History

2014/11/07 Initial version.


CONFIDENTIAL