liblzma (XZ Utils) 5.8.1

Data Structures | Macros | Enumerations | Functions
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 (for raw encoder/decoder only, not in .xz)
#define | LZMA_FILTER_LZMA1EXT LZMA_VLI_C(0x4000000000000002)
| LZMA1 Filter ID with extended options (for raw encoder/decoder)
#define | LZMA_FILTER_LZMA2 LZMA_VLI_C(0x21)
| LZMA2 Filter ID.
#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
#define | LZMA_LZMA1EXT_ALLOW_EOPM UINT32_C(0x01)
#define | lzma_set_ext_size(opt_lzma2, u64size)
| Macro to set the 64-bit uncompressed size in ext_size_*.

## 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.
lzma_bool | lzma_mode_is_supported (lzma_mode mode) lzma_nothrow lzma_attr_const
| Test if given compression mode is supported.
lzma_bool | lzma_lzma_preset (lzma_options_lzma *options, uint32_t preset) lzma_nothrow
| Set a compression preset to lzma_options_lzma structure.

## Detailed Description

LZMA1 and LZMA2 filters.

Note
  Never include this file directly. Use <lzma.h> instead.

## Macro Definition Documentation

## ◆ LZMA_FILTER_LZMA1

#define LZMA_FILTER_LZMA1 LZMA_VLI_C(0x4000000000000001)

LZMA1 Filter ID (for raw encoder/decoder only, not in .xz)

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.

## ◆ LZMA_FILTER_LZMA1EXT

#define LZMA_FILTER_LZMA1EXT LZMA_VLI_C(0x4000000000000002)

LZMA1 Filter ID with extended options (for raw encoder/decoder)

This is like LZMA_FILTER_LZMA1 but with this ID a few extra options are supported in the lzma_options_lzma structure:

- A flag to tell the encoder if the end of payload marker (EOPM) alias end of stream (EOS) marker must be written at the end of the stream. In contrast, LZMA_FILTER_LZMA1 always writes the end marker.
- Decoder needs to be told the uncompressed size of the stream or that it is unknown (using the special value UINT64_MAX). If the size is known, a flag can be set to allow the presence of the end marker anyway. In contrast, LZMA_FILTER_LZMA1 always behaves as if the uncompressed size was unknown.

This allows handling file formats where LZMA1 streams are used but where the end marker isn't allowed or where it might not (always) be present. This extended LZMA1 functionality is provided as a Filter ID for raw encoder and decoder instead of adding new encoder and decoder initialization functions because this way it is possible to also use extra filters, for example, LZMA_FILTER_X86 in a filter chain with LZMA_FILTER_LZMA1EXT, which might be needed to handle some file formats.

## ◆ 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 incompressible data), possibility to change lc/lp/pb in the middle of encoding, and some other internal improvements.

## ◆ lzma_set_ext_size

#define lzma_set_ext_size | ( |  | opt_lzma2,
|  |  | u64size )

Value:
do { \
(opt_lzma2).ext_size_low = (uint32_t)(u64size); \
(opt_lzma2).ext_size_high = (uint32_t)((uint64_t)(u64size) >> 32); \
} while (0)

Macro to set the 64-bit uncompressed size in ext_size_*.

This might be convenient when decoding using LZMA_FILTER_LZMA1EXT. This isn't used with LZMA_FILTER_LZMA1 or LZMA_FILTER_LZMA2.

## 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
| extern

Test if given match finder is supported.

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.

Parameters

  match_finder | Match finder ID

Returns
  lzma_bool:
  - true if the match finder is supported by this liblzma build.
  - false otherwise.

## ◆ lzma_mode_is_supported()

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

Test if given compression mode is supported.

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.

Parameters

  mode | Mode ID.

Returns
  lzma_bool:
  - true if the compression mode is supported by this liblzma build.
  - false otherwise.

## ◆ lzma_lzma_preset()

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

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 levels are subject to changes between liblzma versions.

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

If features (like certain match finders) have been disabled at build time, then the function may return success (false) even though the resulting LZMA1/LZMA2 options may not be usable for encoder initialization (LZMA_OPTIONS_ERROR).

Parameters

  [out] | options | Pointer to LZMA1 or LZMA2 options to be filled
  | preset | Preset level bitwse-ORed with preset flags

Returns
  lzma_bool:
  - true if the preset is not supported (failure).
  - false otherwise (success).