lzma12.h File Reference

LZMA1 and LZMA2 filters. More...

## Data Structures

struct | lzma_options_lzma
| Options specific to the LZMA1 and LZMA2 filters. More...

## Macros

#define | LZMA_FILTER_LZMA1 LZMA_VLI_C(0x4000000000000001)
| LZMA1 Filter ID. More...
#define | LZMA_FILTER_LZMA2 LZMA_VLI_C(0x21)
| LZMA2 Filter ID. More...
#define | LZMA_DICT_SIZE_MIN UINT32_C(4096)
#define | LZMA_DICT_SIZE_DEFAULT (UINT32_C(1) << 23)
#define | LZMA_LCLP_MIN 0
#define | LZMA_LCLP_MAX 4
#define | LZMA_LC_DEFAULT 3
#define | LZMA_LP_DEFAULT 0
#define | LZMA_PB_MIN 0
#define | LZMA_PB_MAX 4
#define | LZMA_PB_DEFAULT 2

## Enumerations

enum | lzma_match_finder { LZMA_MF_HC3 = 0x03 , LZMA_MF_HC4 = 0x04 , LZMA_MF_BT2 = 0x12 , LZMA_MF_BT3 = 0x13 , LZMA_MF_BT4 = 0x14 }
| Match finders. More...
enum | lzma_mode { LZMA_MODE_FAST = 1 , LZMA_MODE_NORMAL = 2 }
| Compression modes. More...

## Functions

lzma_bool | lzma_mf_is_supported (lzma_match_finder match_finder) lzma_nothrow lzma_attr_const
| Test if given match finder is supported. More...
lzma_bool | lzma_mode_is_supported (lzma_mode mode) lzma_nothrow lzma_attr_const
| Test if given compression mode is supported. More...
lzma_bool | lzma_lzma_preset (lzma_options_lzma *options, uint32_t preset) lzma_nothrow
| Set a compression preset to lzma_options_lzma structure. More...

## Detailed Description

LZMA1 and LZMA2 filters.

## Macro Definition Documentation

## LZMA_FILTER_LZMA1

#define LZMA_FILTER_LZMA1 LZMA_VLI_C(0x4000000000000001)

LZMA1 Filter ID.

LZMA1 is the very same thing as what was called just LZMA in LZMA Utils, 7-Zip, and LZMA SDK. It's called LZMA1 here to prevent developers from accidentally using LZMA when they actually want LZMA2.

LZMA1 shouldn't be used for new applications unless you really know what you are doing. LZMA2 is almost always a better choice.

## LZMA_FILTER_LZMA2

#define LZMA_FILTER_LZMA2 LZMA_VLI_C(0x21)

LZMA2 Filter ID.

Usually you want this instead of LZMA1. Compared to LZMA1, LZMA2 adds support for LZMA_SYNC_FLUSH, uncompressed chunks (smaller expansion when trying to compress uncompressible data), possibility to change lc/lp/pb in the middle of encoding, and some other internal improvements.

## Enumeration Type Documentation

## lzma_match_finder

enum lzma_match_finder

Match finders.

Match finder has major effect on both speed and compression ratio. Usually hash chains are faster than binary trees.

If you will use LZMA_SYNC_FLUSH often, the hash chains may be a better choice, because binary trees get much higher compression ratio penalty with LZMA_SYNC_FLUSH.

The memory usage formulas are only rough estimates, which are closest to reality when dict_size is a power of two. The formulas are more complex in reality, and can also change a little between liblzma versions. Use lzma_raw_encoder_memusage() to get more accurate estimate of memory usage.

Enumerator

LZMA_MF_HC3

Hash Chain with 2- and 3-byte hashing.

Minimum nice_len: 3

Memory usage:

- dict_size <= 16 MiB: dict_size * 7.5
- dict_size > 16 MiB: dict_size * 5.5 + 64 MiB

LZMA_MF_HC4

Hash Chain with 2-, 3-, and 4-byte hashing.

Minimum nice_len: 4

Memory usage:

- dict_size <= 32 MiB: dict_size * 7.5
- dict_size > 32 MiB: dict_size * 6.5

LZMA_MF_BT2 | Binary Tree with 2-byte hashing. Minimum nice_len: 2 Memory usage: dict_size * 9.5

LZMA_MF_BT3

Binary Tree with 2- and 3-byte hashing.

Minimum nice_len: 3

Memory usage:

- dict_size <= 16 MiB: dict_size * 11.5
- dict_size > 16 MiB: dict_size * 9.5 + 64 MiB

LZMA_MF_BT4

Binary Tree with 2-, 3-, and 4-byte hashing.

Minimum nice_len: 4

Memory usage:

- dict_size <= 32 MiB: dict_size * 11.5
- dict_size > 32 MiB: dict_size * 10.5

## lzma_mode

enum lzma_mode

Compression modes.

This selects the function used to analyze the data produced by the match finder.

Enumerator
LZMA_MODE_FAST | Fast compression. Fast mode is usually at its best when combined with a hash chain match finder.
LZMA_MODE_NORMAL | Normal compression. This is usually notably slower than fast mode. Use this together with binary tree match finders to expose the full potential of the LZMA1 or LZMA2 encoder.

## Function Documentation

## lzma_mf_is_supported()

lzma_bool lzma_mf_is_supported | ( | lzma_match_finder | match_finder | ) | const

Test if given match finder is supported.

Return true if the given match finder is supported by this liblzma build. Otherwise false is returned. It is safe to call this with a value that isn't listed in lzma_match_finder enumeration; the return value will be false.

There is no way to list which match finders are available in this particular liblzma version and build. It would be useless, because a new match finder, which the application developer wasn't aware, could require giving additional options to the encoder that the older match finders don't need.

References LZMA_MF_BT2, LZMA_MF_BT3, LZMA_MF_BT4, LZMA_MF_HC3, and LZMA_MF_HC4.

## lzma_mode_is_supported()

lzma_bool lzma_mode_is_supported | ( | lzma_mode | mode | ) | const

Test if given compression mode is supported.

Return true if the given compression mode is supported by this liblzma build. Otherwise false is returned. It is safe to call this with a value that isn't listed in lzma_mode enumeration; the return value will be false.

There is no way to list which modes are available in this particular liblzma version and build. It would be useless, because a new compression mode, which the application developer wasn't aware, could require giving additional options to the encoder that the older modes don't need.

References LZMA_MODE_FAST, and LZMA_MODE_NORMAL.

## lzma_lzma_preset()

lzma_bool lzma_lzma_preset | ( | lzma_options_lzma * | options,
|  | uint32_t | preset
| ) |  |

Set a compression preset to lzma_options_lzma structure.

0 is the fastest and 9 is the slowest. These match the switches -0 .. -9 of the xz command line tool. In addition, it is possible to bitwise-or flags to the preset. Currently only LZMA_PRESET_EXTREME is supported. The flags are defined in container.h, because the flags are used also with lzma_easy_encoder().

The preset values are subject to changes between liblzma versions.

This function is available only if LZMA1 or LZMA2 encoder has been enabled when building liblzma.

Returns
  On success, false is returned. If the preset is not supported, true is returned.

References LZMA_PRESET_EXTREME, and LZMA_PRESET_LEVEL_MASK.

Referenced by lzma_easy_preset().