liblzma (XZ Utils) 5.4.7
Data Fields
lzma_options_lzma Struct Reference

Options specific to the LZMA1 and LZMA2 filters. More...

#include <lzma12.h>

Data Fields

uint32_t dict_size
 Dictionary size in bytes.
 
const uint8_t * preset_dict
 Pointer to an initial dictionary.
 
uint32_t preset_dict_size
 Size of the preset dictionary.
 
uint32_t lc
 Number of literal context bits.
 
uint32_t lp
 Number of literal position bits.
 
uint32_t pb
 Number of position bits.
 
lzma_mode mode
 
uint32_t nice_len
 Nice length of a match.
 
lzma_match_finder mf
 
uint32_t depth
 Maximum search depth in the match finder.
 
uint32_t ext_flags
 For LZMA_FILTER_LZMA1EXT: Extended flags.
 
uint32_t ext_size_low
 For LZMA_FILTER_LZMA1EXT: Uncompressed size (low bits)
 
uint32_t ext_size_high
 For LZMA_FILTER_LZMA1EXT: Uncompressed size (high bits)
 

Detailed Description

Options specific to the LZMA1 and LZMA2 filters.

Since LZMA1 and LZMA2 share most of the code, it's simplest to share the options structure too. For encoding, all but the reserved variables need to be initialized unless specifically mentioned otherwise. lzma_lzma_preset() can be used to get a good starting point.

For raw decoding, both LZMA1 and LZMA2 need dict_size, preset_dict, and preset_dict_size (if preset_dict != NULL). LZMA1 needs also lc, lp, and pb.

Field Documentation

◆ dict_size

uint32_t lzma_options_lzma::dict_size

Dictionary size in bytes.

Dictionary size indicates how many bytes of the recently processed uncompressed data is kept in memory. One method to reduce size of the uncompressed data is to store distance-length pairs, which indicate what data to repeat from the dictionary buffer. Thus, the bigger the dictionary, the better the compression ratio usually is.

Maximum size of the dictionary depends on multiple things:

  • Memory usage limit
  • Available address space (not a problem on 64-bit systems)
  • Selected match finder (encoder only)

Currently the maximum dictionary size for encoding is 1.5 GiB (i.e. (UINT32_C(1) << 30) + (UINT32_C(1) << 29)) even on 64-bit systems for certain match finder implementation reasons. In the future, there may be match finders that support bigger dictionaries.

Decoder already supports dictionaries up to 4 GiB - 1 B (i.e. UINT32_MAX), so increasing the maximum dictionary size of the encoder won't cause problems for old decoders.

Because extremely small dictionaries sizes would have unneeded overhead in the decoder, the minimum dictionary size is 4096 bytes.

Note
When decoding, too big dictionary does no other harm than wasting memory.

◆ preset_dict

const uint8_t* lzma_options_lzma::preset_dict

Pointer to an initial dictionary.

It is possible to initialize the LZ77 history window using a preset dictionary. It is useful when compressing many similar, relatively small chunks of data independently from each other. The preset dictionary should contain typical strings that occur in the files being compressed. The most probable strings should be near the end of the preset dictionary.

This feature should be used only in special situations. For now, it works correctly only with raw encoding and decoding. Currently none of the container formats supported by liblzma allow preset dictionary when decoding, thus if you create a .xz or .lzma file with preset dictionary, it cannot be decoded with the regular decoder functions. In the future, the .xz format will likely get support for preset dictionary though.

◆ preset_dict_size

uint32_t lzma_options_lzma::preset_dict_size

Size of the preset dictionary.

Specifies the size of the preset dictionary. If the size is bigger than dict_size, only the last dict_size bytes are processed.

This variable is read only when preset_dict is not NULL. If preset_dict is not NULL but preset_dict_size is zero, no preset dictionary is used (identical to only setting preset_dict to NULL).

◆ lc

uint32_t lzma_options_lzma::lc

Number of literal context bits.

How many of the highest bits of the previous uncompressed eight-bit byte (also known as `literal') are taken into account when predicting the bits of the next literal.

E.g. in typical English text, an upper-case letter is often followed by a lower-case letter, and a lower-case letter is usually followed by another lower-case letter. In the US-ASCII character set, the highest three bits are 010 for upper-case letters and 011 for lower-case letters. When lc is at least 3, the literal coding can take advantage of this property in the uncompressed data.

There is a limit that applies to literal context bits and literal position bits together: lc + lp <= 4. Without this limit the decoding could become very slow, which could have security related results in some cases like email servers doing virus scanning. This limit also simplifies the internal implementation in liblzma.

There may be LZMA1 streams that have lc + lp > 4 (maximum possible lc would be 8). It is not possible to decode such streams with liblzma.

◆ lp

uint32_t lzma_options_lzma::lp

Number of literal position bits.

lp affects what kind of alignment in the uncompressed data is assumed when encoding literals. A literal is a single 8-bit byte. See pb below for more information about alignment.

◆ pb

uint32_t lzma_options_lzma::pb

Number of position bits.

pb affects what kind of alignment in the uncompressed data is assumed in general. The default means four-byte alignment (2^ pb =2^2=4), which is often a good choice when there's no better guess.

When the alignment is known, setting pb accordingly may reduce the file size a little. E.g. with text files having one-byte alignment (US-ASCII, ISO-8859-*, UTF-8), setting pb=0 can improve compression slightly. For UTF-16 text, pb=1 is a good choice. If the alignment is an odd number like 3 bytes, pb=0 might be the best choice.

Even though the assumed alignment can be adjusted with pb and lp, LZMA1 and LZMA2 still slightly favor 16-byte alignment. It might be worth taking into account when designing file formats that are likely to be often compressed with LZMA1 or LZMA2.

◆ mode

lzma_mode lzma_options_lzma::mode

Compression mode

◆ nice_len

uint32_t lzma_options_lzma::nice_len

Nice length of a match.

This determines how many bytes the encoder compares from the match candidates when looking for the best match. Once a match of at least nice_len bytes long is found, the encoder stops looking for better candidates and encodes the match. (Naturally, if the found match is actually longer than nice_len, the actual length is encoded; it's not truncated to nice_len.)

Bigger values usually increase the compression ratio and compression time. For most files, 32 to 128 is a good value, which gives very good compression ratio at good speed.

The exact minimum value depends on the match finder. The maximum is 273, which is the maximum length of a match that LZMA1 and LZMA2 can encode.

◆ mf

lzma_match_finder lzma_options_lzma::mf

Match finder ID

◆ depth

uint32_t lzma_options_lzma::depth

Maximum search depth in the match finder.

For every input byte, match finder searches through the hash chain or binary tree in a loop, each iteration going one step deeper in the chain or tree. The searching stops if

  • a match of at least nice_len bytes long is found;
  • all match candidates from the hash chain or binary tree have been checked; or
  • maximum search depth is reached.

Maximum search depth is needed to prevent the match finder from wasting too much time in case there are lots of short match candidates. On the other hand, stopping the search before all candidates have been checked can reduce compression ratio.

Setting depth to zero tells liblzma to use an automatic default value, that depends on the selected match finder and nice_len. The default is in the range [4, 200] or so (it may vary between liblzma versions).

Using a bigger depth value than the default can increase compression ratio in some cases. There is no strict maximum value, but high values (thousands or millions) should be used with care: the encoder could remain fast enough with typical input, but malicious input could cause the match finder to slow down dramatically, possibly creating a denial of service attack.

◆ ext_flags

uint32_t lzma_options_lzma::ext_flags

For LZMA_FILTER_LZMA1EXT: Extended flags.

This is used only with LZMA_FILTER_LZMA1EXT.

Currently only one flag is supported, LZMA_LZMA1EXT_ALLOW_EOPM:

  • Encoder: If the flag is set, then end marker is written just like it is with LZMA_FILTER_LZMA1. Without this flag the end marker isn't written and the application has to store the uncompressed size somewhere outside the compressed stream. To decompress streams without the end marker, the application has to set the correct uncompressed size in ext_size_low and ext_size_high.
  • Decoder: If the uncompressed size in ext_size_low and ext_size_high is set to the special value UINT64_MAX (indicating unknown uncompressed size) then this flag is ignored and the end marker must always be present, that is, the behavior is identical to LZMA_FILTER_LZMA1.

    Otherwise, if this flag isn't set, then the input stream must not have the end marker; if the end marker is detected then it will result in LZMA_DATA_ERROR. This is useful when it is known that the stream must not have the end marker and strict validation is wanted.

    If this flag is set, then it is autodetected if the end marker is present after the specified number of uncompressed bytes has been decompressed (ext_size_low and ext_size_high). The end marker isn't allowed in any other position. This behavior is useful when uncompressed size is known but the end marker may or may not be present. This is the case, for example, in .7z files (valid .7z files that have the end marker in LZMA1 streams are rare but they do exist).

◆ ext_size_low

uint32_t lzma_options_lzma::ext_size_low

For LZMA_FILTER_LZMA1EXT: Uncompressed size (low bits)

The 64-bit uncompressed size is needed for decompression with LZMA_FILTER_LZMA1EXT. The size is ignored by the encoder.

The special value UINT64_MAX indicates that the uncompressed size is unknown and that the end of payload marker (also known as end of stream marker) must be present to indicate the end of the LZMA1 stream. Any other value indicates the expected uncompressed size of the LZMA1 stream. (If LZMA1 was used together with filters that change the size of the data then the uncompressed size of the LZMA1 stream could be different than the final uncompressed size of the filtered stream.)

ext_size_low holds the least significant 32 bits of the uncompressed size. The most significant 32 bits must be set in ext_size_high. The macro lzma_ext_size_set(opt_lzma, u64size) can be used to set these members.

The 64-bit uncompressed size is split into two uint32_t variables because there were no reserved uint64_t members and using the same options structure for LZMA_FILTER_LZMA1, LZMA_FILTER_LZMA1EXT, and LZMA_FILTER_LZMA2 was otherwise more convenient than having a new options structure for LZMA_FILTER_LZMA1EXT. (Replacing two uint32_t members with one uint64_t changes the ABI on some systems as the alignment of this struct can increase from 4 bytes to 8.)

◆ ext_size_high

uint32_t lzma_options_lzma::ext_size_high

For LZMA_FILTER_LZMA1EXT: Uncompressed size (high bits)

This holds the most significant 32 bits of the uncompressed size.


The documentation for this struct was generated from the following file: