### Custom Compressor Filter Chains Source: https://tukaani.org/xz/man/xz.1.html Examples for customizing LZMA2 presets and dictionary sizes for specific compression requirements. ```text Preset CompCPU -0 0 -1 1 -2 2 -3 3 -4 4 -5 5 -6 6 -5e 7 -6e 8 ``` ```bash xz --lzma2=preset=1,dict=32MiB foo.tar ``` ```bash xz -vv --lzma2=dict=192MiB big_foo.tar ``` -------------------------------- ### Displaying lzma_str_to_filters error messages Source: https://tukaani.org/xz/liblzma-api/filter_8h.html Example of how to handle and display error messages returned by lzma_str_to_filters, including pointing to the error position in the input string. ```c const char *str = ...; // From user lzma_filter filters[LZMA_FILTERS_MAX + 1]; int pos; const char *msg = lzma_str_to_filters(str, &pos, filters, 0, NULL); if (msg != NULL) { printf("%s: Error in XZ compression options:\n", argv[0]); printf("%s: %s\n", argv[0], str); printf("%s: %*s^\n", argv[0], errpos, ""); printf("%s: %s\n", argv[0], msg); } ``` -------------------------------- ### lzma_memlimit_get Source: https://tukaani.org/xz/liblzma-api/base_8h.html Gets the current memory usage limit. ```APIDOC ## uint64_t lzma_memlimit_get(const lzma_stream *strm) ### Description Returns the current memory usage limit in bytes. ### Parameters - **strm** (const lzma_stream*) - Required - Pointer to the lzma_stream structure. ``` -------------------------------- ### Pass options to xz via environment variables Source: https://tukaani.org/xz/man/xz.1.html Demonstrates passing compression options to xz when invoked by other tools like tar. ```bash XZ_OPT=-2v tar caf foo.tar.xz foo ``` -------------------------------- ### lzma_memusage Source: https://tukaani.org/xz/liblzma-api/base_8h.html Gets the memory usage of the decoder filter chain. ```APIDOC ## uint64_t lzma_memusage(const lzma_stream *strm) ### Description Returns the current memory usage of the decoder filter chain in bytes. ### Parameters - **strm** (const lzma_stream*) - Required - Pointer to the lzma_stream structure. ``` -------------------------------- ### lzma_index_init() Source: https://tukaani.org/xz/liblzma-api/index_8h.html Allocates and initializes a new lzma_index structure. ```APIDOC ## lzma_index * lzma_index_init(const lzma_allocator *allocator) ### Description Allocate and initialize a new lzma_index structure. ### Parameters - **allocator** (const lzma_allocator *) - Optional - lzma_allocator for custom allocator functions. Set to NULL to use malloc() and free(). ### Returns - **lzma_index*** - On success, a pointer to an empty initialized lzma_index is returned. If allocation fails, NULL is returned. ``` -------------------------------- ### Generate build files with Autotools Source: https://tukaani.org/xz Run this script to generate the configure script and other necessary files for the Autotools-based build system. ```bash ./autogen.sh ``` -------------------------------- ### lzma_index_init Source: https://tukaani.org/xz/liblzma-api/index_8h.html Allocates and initializes a new lzma_index structure. ```APIDOC ## lzma_index *lzma_index_init(const lzma_allocator *allocator) ### Description Allocates and initializes a new lzma_index structure for tracking .xz file metadata. ### Parameters - **allocator** (const lzma_allocator *) - Optional - Custom memory allocator, or NULL to use standard malloc. ``` -------------------------------- ### lzma_lzma_preset() Source: https://tukaani.org/xz/liblzma-api/lzma12_8h.html Sets a compression preset to an lzma_options_lzma structure. The preset levels range from 0 (fastest) to 9 (slowest), matching the xz command line tool switches, with optional flags like LZMA_PRESET_EXTREME. ```APIDOC ## lzma_lzma_preset() ### Description Sets a compression preset to an lzma_options_lzma structure. Preset levels range from 0 to 9, and can be combined with flags such as LZMA_PRESET_EXTREME. ### Signature `lzma_bool lzma_lzma_preset(lzma_options_lzma *options, uint32_t preset)` ### Parameters - **options** (lzma_options_lzma*) - Required - Pointer to the LZMA1 or LZMA2 options structure to be filled. - **preset** (uint32_t) - Required - The preset level (0-9) bitwise-ORed with optional flags. ### Returns - **lzma_bool** - Returns true if the preset is not supported (failure), or false if successful. ``` -------------------------------- ### Clone the XZ Utils repository Source: https://tukaani.org/xz Use this command to clone the primary Git repository from GitHub. ```bash git clone https://github.com/tukaani-project/xz ``` -------------------------------- ### Set default compression options in shell scripts Source: https://tukaani.org/xz/man/xz.1.html Shows how to set default XZ_OPT values in a shell script while allowing user overrides. ```bash XZ_OPT=${XZ_OPT-"-7e"} export XZ_OPT ``` -------------------------------- ### Initialize lzma_stream Source: https://tukaani.org/xz/liblzma-api/base_8h.html Use the LZMA_STREAM_INIT macro to initialize a new lzma_stream instance, ensuring that internal pointers are correctly set to NULL. ```c lzma_stream strm = LZMA_STREAM_INIT; ``` ```c lzma_stream tmp = LZMA_STREAM_INIT; *strm = tmp; ``` -------------------------------- ### Compress for Embedded Systems Source: https://tukaani.org/xz/man/xz.1.html Uses the extreme preset and a fixed 64 KiB dictionary to ensure compatibility with XZ Embedded and low memory usage during decompression. ```bash xz --check=crc32 --lzma2=preset=6e,dict=64KiB foo ``` -------------------------------- ### Define Compile-time Version String Source: https://tukaani.org/xz/liblzma-api/version_8h.html Constructs the version string representation using the version components. ```c #define LZMA_VERSION_STRING LZMA_VERSION_STRING_C( \ LZMA_VERSION_MAJOR, LZMA_VERSION_MINOR, \ LZMA_VERSION_PATCH, LZMA_VERSION_STABILITY_STRING, \ LZMA_VERSION_COMMIT) ``` -------------------------------- ### lzma_lzma_preset Source: https://tukaani.org/xz/liblzma-api/lzma12_8h.html Initializes an lzma_options_lzma structure with default settings based on a preset level. ```APIDOC ## lzma_bool lzma_lzma_preset(lzma_options_lzma *options, uint32_t preset) ### Description Sets a compression preset to the provided lzma_options_lzma structure. ### Parameters - **options** (lzma_options_lzma*) - Pointer to the options structure to be initialized. - **preset** (uint32_t) - The preset level to apply. ``` -------------------------------- ### Retrieve Run-time Version String Source: https://tukaani.org/xz/liblzma-api/version_8h.html Returns the string representation of the linked liblzma library version. ```c const char * lzma_version_string (void) lzma_nothrow lzma_attr_const ``` -------------------------------- ### lzma_index_hash_init Source: https://tukaani.org/xz/liblzma-api/index__hash_8h.html Allocates and initializes a new lzma_index_hash structure or reinitializes an existing one. ```APIDOC ## lzma_index_hash *lzma_index_hash_init(lzma_index_hash *index_hash, const lzma_allocator *allocator) ### Description Allocates and initializes a new lzma_index_hash structure. If index_hash is NULL, it allocates a new structure; if non-NULL, it reinitializes the existing structure. ### Parameters - **index_hash** (lzma_index_hash *) - Pointer to a lzma_index_hash structure or NULL. - **allocator** (lzma_allocator *) - Custom allocator functions. Set to NULL to use standard malloc() and free(). ### Returns - **lzma_index_hash*** - Initialized lzma_index_hash structure on success, or NULL on failure. ``` -------------------------------- ### lzma_easy_encoder() Source: https://tukaani.org/xz/liblzma-api/container_8h.html Initializes a .xz Stream encoder using a specified preset number. ```APIDOC ## lzma_easy_encoder() ### Description Initialize .xz Stream encoder using a preset number. If initialization fails, memory is automatically freed. If successful, use lzma_code() to perform encoding. ### Parameters - **strm** (lzma_stream *) - Pointer to lzma_stream that is at least initialized with LZMA_STREAM_INIT. - **preset** (uint32_t) - Compression preset to use (level [0, 9] and optional flags like LZMA_PRESET_EXTREME). - **check** (lzma_check) - Integrity check type to use. ### Returns - **lzma_ret** - Returns LZMA_OK on success, or error codes: LZMA_MEM_ERROR, LZMA_OPTIONS_ERROR, LZMA_UNSUPPORTED_CHECK, or LZMA_PROG_ERROR. ``` -------------------------------- ### lzma_alone_decoder() Source: https://tukaani.org/xz/liblzma-api/container_8h.html Initializes the .lzma decoder for the legacy file format. ```APIDOC ## lzma_ret lzma_alone_decoder(lzma_stream *strm, uint64_t memlimit) ### Description Initializes the .lzma decoder for the legacy file format. Valid action arguments to lzma_code() are LZMA_RUN and LZMA_FINISH. ### Parameters - **strm** (lzma_stream *) - Required - Pointer to lzma_stream that is at least initialized with LZMA_STREAM_INIT. - **memlimit** (uint64_t) - Required - Memory usage limit as bytes. Use UINT64_MAX to effectively disable the limiter. ### Returns - **lzma_ret** - Possible values: LZMA_OK, LZMA_MEM_ERROR, LZMA_PROG_ERROR ``` -------------------------------- ### Check xz version information Source: https://tukaani.org/xz/man/xz.1.html Displays the version number of xz and liblzma in a machine-readable format. ```bash xz --robot --version ``` -------------------------------- ### Compression Presets Source: https://tukaani.org/xz/liblzma-api/container_8h.html Macros defining default, extreme, and level-masking presets for compression. ```APIDOC ## LZMA_PRESET_DEFAULT #define LZMA_PRESET_DEFAULT UINT32_C(6) ## LZMA_PRESET_LEVEL_MASK #define LZMA_PRESET_LEVEL_MASK UINT32_C(0x1F) ## LZMA_PRESET_EXTREME #define LZMA_PRESET_EXTREME (UINT32_C(1) << 31) ``` -------------------------------- ### lzma_lzip_decoder() Source: https://tukaani.org/xz/liblzma-api/container_8h.html Initializes the .lz (lzip) decoder for foreign file formats. ```APIDOC ## lzma_ret lzma_lzip_decoder(lzma_stream *strm, uint64_t memlimit, uint32_t flags) ### Description Initializes the .lz (lzip) decoder. This decoder supports .lz format versions 0 and 1. ### Parameters - **strm** (lzma_stream *) - Required - Pointer to lzma_stream that is at least initialized with LZMA_STREAM_INIT. - **memlimit** (uint64_t) - Required - Memory usage limit as bytes. Use UINT64_MAX to effectively disable the limiter. - **flags** (uint32_t) - Required - Bitwise-or of flags, or zero for no flags. ### Returns - **lzma_ret** - Possible values: LZMA_OK, LZMA_MEM_ERROR, LZMA_OPTIONS_ERROR, LZMA_PROG_ERROR ``` -------------------------------- ### Basic Compression and Decompression Source: https://tukaani.org/xz/man/xz.1.html Standard commands for compressing and decompressing files, including piping output from tar. ```bash xz foo ``` ```bash xz -dk bar.xz ``` ```bash tar cf - baz | xz -4e > baz.tar.xz ``` ```bash xz -dcf a.txt b.txt.xz c.txt d.txt.lzma > abcd.txt ``` -------------------------------- ### Configure GNU tar options for distribution Source: https://tukaani.org/xz-backdoor/review.html Sets environment variables to normalize file ownership and permissions during tarball creation. ```bash TAR_OPTIONS='--owner=0 --group=0 --numeric-owner --mode=u+rw,go+r-w' ``` -------------------------------- ### lzma_index_encoder Source: https://tukaani.org/xz/liblzma-api/index_8h.html Initializes an .xz Index encoder. ```APIDOC ## lzma_ret lzma_index_encoder(lzma_stream *strm, const lzma_index *i) ### Description Initializes the encoder for an .xz Index structure using the provided lzma_stream. ### Parameters - **strm** (lzma_stream *) - Required - The stream to initialize. - **i** (const lzma_index *) - Required - The index to be encoded. ``` -------------------------------- ### Clone XZ Embedded Repository Source: https://tukaani.org/xz/embedded.html Use this command to retrieve the latest source code from the GitHub repository. ```bash git clone https://github.com/tukaani-project/xz-embedded ``` -------------------------------- ### lzma_index_decoder Source: https://tukaani.org/xz/liblzma-api/index_8h.html Initializes an .xz Index decoder. ```APIDOC ## lzma_ret lzma_index_decoder(lzma_stream *strm, lzma_index **i, uint64_t memlimit) ### Description Initializes the decoder for an .xz Index structure. ### Parameters - **strm** (lzma_stream *) - Required - The stream to initialize. - **i** (lzma_index **) - Required - Pointer to store the resulting index structure. - **memlimit** (uint64_t) - Required - Memory usage limit for the decoder. ``` -------------------------------- ### lzma_auto_decoder() Source: https://tukaani.org/xz/liblzma-api/container_8h.html Initializes a decoder that automatically detects the input file format (.xz, .lzma, or .lz) and delegates to the appropriate decoder implementation. ```APIDOC ## lzma_ret lzma_auto_decoder(lzma_stream *strm, uint64_t memlimit, uint32_t flags) ### Description Initializes the stream to decode .xz, .lzma, and .lz (lzip) files with autodetection. It automatically selects the correct decoder based on the input file type. ### Parameters - **strm** (lzma_stream *) - Required - Pointer to lzma_stream that is at least initialized with LZMA_STREAM_INIT. - **memlimit** (uint64_t) - Required - Memory usage limit in bytes. Use UINT64_MAX to disable the limiter. - **flags** (uint32_t) - Required - Bitwise-or of zero or more decoder flags (e.g., LZMA_TELL_NO_CHECK, LZMA_CONCATENATED). ### Returns - **LZMA_OK**: Initialization was successful. - **LZMA_MEM_ERROR**: Cannot allocate memory. - **LZMA_OPTIONS_ERROR**: Unsupported flags. - **LZMA_PROG_ERROR**: Invalid arguments provided. ``` -------------------------------- ### Parallel Compression of Multiple Files Source: https://tukaani.org/xz/man/xz.1.html Utilize find and xargs to parallelize xz compression across multiple files. ```bash find . -type f \! -name '*.xz' -print0 \ | xargs -0r -P4 -n16 xz -T1 ``` -------------------------------- ### lzma_easy_encoder Source: https://tukaani.org/xz/liblzma-api/container_8h.html Initializes an .xz Stream encoder using a preset compression level. ```APIDOC ## lzma_easy_encoder ### Description Initializes an .xz Stream encoder using a preset number. This function sets up the stream for compression. ### Signature lzma_ret lzma_easy_encoder(lzma_stream *strm, uint32_t preset, lzma_check check) ``` -------------------------------- ### lzma_block_encoder Source: https://tukaani.org/xz/liblzma-api/block_8h.html Initializes the .xz Block encoder. ```APIDOC ## lzma_ret lzma_block_encoder(lzma_stream *strm, lzma_block *block) ### Description Initializes the encoder for a single .xz Block. ### Parameters - **strm** (lzma_stream*) - Required - Pointer to the stream structure. - **block** (lzma_block*) - Required - Pointer to the block structure containing encoding options. ``` -------------------------------- ### LZMA_STREAM_INIT Source: https://tukaani.org/xz/liblzma-api/base_8h.html Macro for initializing an lzma_stream structure. ```APIDOC ## LZMA_STREAM_INIT ### Description Initialization constant for lzma_stream. Use this to initialize a new lzma_stream instance to ensure no memory is allocated yet. ``` -------------------------------- ### preset_dict Source: https://tukaani.org/xz/liblzma-api/structlzma__options__lzma.html Pointer to an initial dictionary used to initialize the LZ77 history window, useful for compressing small, similar chunks of data. ```APIDOC ## const uint8_t* lzma_options_lzma::preset_dict ### Description Pointer to an initial dictionary. This feature allows initializing the LZ77 history window with typical strings to improve compression of small, independent data chunks. ### Usage Note This feature is currently limited to raw encoding and decoding and is not supported by standard .xz or .lzma container formats. ``` -------------------------------- ### lzma_alone_encoder() Source: https://tukaani.org/xz/liblzma-api/container_8h.html Initializes the legacy .lzma (LZMA_Alone) format encoder. ```APIDOC ## lzma_ret lzma_alone_encoder(lzma_stream *strm, const lzma_options_lzma *options) ### Description Initializes the .lzma encoder for legacy file format support. This format supports only the LZMA1 filter and no integrity checks. ### Parameters - **strm** (lzma_stream *) - Required - Pointer to lzma_stream that is at least initialized with LZMA_STREAM_INIT. - **options** (const lzma_options_lzma *) - Required - Pointer to encoder options. ### Returns - **lzma_ret** - Returns LZMA_OK, LZMA_MEM_ERROR, LZMA_OPTIONS_ERROR, or LZMA_PROG_ERROR. ``` -------------------------------- ### lzma_auto_decoder Source: https://tukaani.org/xz/liblzma-api/container_8h.html Initializes a decoder that automatically detects the file format (.xz, .lzma, or .lz). ```APIDOC ## lzma_auto_decoder ### Description Decodes .xz, .lzma, and .lz (lzip) files with automatic format detection. ### Signature lzma_ret lzma_auto_decoder(lzma_stream *strm, uint64_t memlimit, uint32_t flags) ``` -------------------------------- ### lzma_index_iter_init() Source: https://tukaani.org/xz/liblzma-api/index_8h.html Initializes an iterator and associates it with a given lzma_index. It also calls lzma_index_iter_rewind() on the iterator. ```APIDOC ## void lzma_index_iter_init(lzma_index_iter *iter, const lzma_index *i) ### Description Initializes an iterator and associates it with the provided lzma_index. The iterator remains valid as long as the associated lzma_index is valid. ### Parameters - **iter** (lzma_index_iter *) - Pointer to the iterator structure to initialize. - **i** (const lzma_index *) - The lzma_index to associate with the iterator. ``` -------------------------------- ### lzma_stream_encoder_mt Source: https://tukaani.org/xz/liblzma-api/container_8h.html Initializes a multithreaded .xz Stream encoder. ```APIDOC ## lzma_ret lzma_stream_encoder_mt(lzma_stream *strm, const lzma_mt *options) ### Description Initializes the multithreaded .xz Stream encoder. This function combines the functionality of lzma_easy_encoder() and lzma_stream_encoder() for multithreaded use. ### Parameters - **strm** (lzma_stream *) - Required - Pointer to an lzma_stream structure initialized with LZMA_STREAM_INIT. - **options** (const lzma_mt *) - Required - Pointer to multithreaded compression options. ### Returns - **lzma_ret** - Returns LZMA_OK on success, or an error code (LZMA_MEM_ERROR, LZMA_UNSUPPORTED_CHECK, LZMA_OPTIONS_ERROR, LZMA_PROG_ERROR) on failure. ``` -------------------------------- ### lzma_index_file_size() Source: https://tukaani.org/xz/liblzma-api/index_8h.html Calculates the total size of the .xz file. ```APIDOC ## lzma_vli lzma_index_file_size(const lzma_index *i) ### Description Returns the total size of the .xz file in bytes. This includes headers of separate Streams and Stream Padding if multiple indexes have been combined. ### Parameters - **i** (const lzma_index *) - Required - Pointer to lzma_index structure ### Returns - **lzma_vli** - Total size of the .xz file in bytes. ``` -------------------------------- ### lzma_str_list_filters() Source: https://tukaani.org/xz/liblzma-api/filter_8h.html Lists available filters and/or their options. If a specific filter_id is provided, it returns information for that filter; otherwise, it lists all supported filters based on the provided flags. ```APIDOC ## lzma_ret lzma_str_list_filters(char **str, lzma_vli filter_id, uint32_t flags, const lzma_allocator *allocator) ### Description Lists available filters and/or their options. The output is stored in an allocated string pointed to by *str. ### Parameters - **str** (char **) - Required - Pointer to a char pointer where the result string will be stored. Set to NULL on error. - **filter_id** (lzma_vli) - Required - The ID of the filter to list, or LZMA_VLI_UNKNOWN to list all supported filters. - **flags** (uint32_t) - Required - Bitwise-or of flags: LZMA_STR_ALL_FILTERS, LZMA_STR_ENCODER, LZMA_STR_DECODER, or LZMA_STR_GETOPT_LONG. - **allocator** (const lzma_allocator *) - Optional - Custom allocator functions. Set to NULL to use standard malloc/free. ### Returns - **LZMA_OK**: Success. - **LZMA_OPTIONS_ERROR**: Unsupported filter_id or flags. - **LZMA_MEM_ERROR**: Memory allocation failed. - **LZMA_PROG_ERROR**: Invalid arguments provided. ``` -------------------------------- ### Define LZMA_STR_GETOPT_LONG constant Source: https://tukaani.org/xz/liblzma-api/filter_8h.html Flag to produce xz-compatible getopt_long() syntax for filter strings. ```c #define LZMA_STR_GETOPT_LONG UINT32_C(0x40) ``` -------------------------------- ### lzma_block_encoder() Source: https://tukaani.org/xz/liblzma-api/block_8h.html Initializes the .xz Block encoder to encode Block Data, Block Padding, and Check value. ```APIDOC ## lzma_ret lzma_block_encoder(lzma_stream *strm, lzma_block *block) ### Description Initializes the .xz Block encoder. The encoder handles Block Data, Block Padding, and Check value, but does not encode the Block Header. ### Parameters - **strm** (lzma_stream *) - Required - Pointer to lzma_stream initialized with LZMA_STREAM_INIT. - **block** (lzma_block *) - Required - Block options; block->version, block->check, and block->filters must be initialized. ### Returns - **lzma_ret** - Returns LZMA_OK on success, or error codes: LZMA_MEM_ERROR, LZMA_OPTIONS_ERROR, LZMA_UNSUPPORTED_CHECK, or LZMA_PROG_ERROR. ``` -------------------------------- ### lzma_mf_is_supported() Source: https://tukaani.org/xz/liblzma-api/lzma12_8h.html Checks if a specific match finder is supported by the current liblzma build. ```APIDOC ## lzma_bool lzma_mf_is_supported(lzma_match_finder match_finder) ### Description Tests if the given match finder is supported by the current liblzma build. It is safe to call this with a value not listed in the lzma_match_finder enumeration, which will return false. ### Parameters - **match_finder** (lzma_match_finder) - Required - The match finder ID to check. ### Returns - **lzma_bool** - Returns true if the match finder is supported, false otherwise. ``` -------------------------------- ### Robot Mode and Scripting Source: https://tukaani.org/xz/man/xz.1.html Commands designed for machine-readable output and script-based version or memory limit checks. ```bash xz --robot --list *.xz | awk '/^totals/{print $5-$4}' ``` ```bash if ! eval "$(xz --robot --version 2> /dev/null)" || [ "$XZ_VERSION" -lt 50000002 ]; then echo "Your xz is too old." fi unset XZ_VERSION LIBLZMA_VERSION ``` ```bash NEWLIM=$((123 << 20)) # 123 MiB OLDLIM=$(xz --robot --info-memory | cut -f3) if [ $OLDLIM -eq 0 -o $OLDLIM -gt $NEWLIM ]; then XZ_OPT="$XZ_OPT --memlimit-decompress=$NEWLIM" export XZ_OPT fi ``` -------------------------------- ### lzma_stream_decoder() Source: https://tukaani.org/xz/liblzma-api/container_8h.html Initializes the .xz Stream decoder for single-threaded processing. ```APIDOC ## lzma_stream_decoder() ### Description Initializes the .xz Stream decoder. This function prepares the lzma_stream structure for decoding operations. ### Parameters - **strm** (lzma_stream*) - Required - Pointer to lzma_stream that is at least initialized with LZMA_STREAM_INIT. - **memlimit** (uint64_t) - Required - Memory usage limit as bytes. Use UINT64_MAX to effectively disable the limiter. - **flags** (uint32_t) - Required - Bitwise-or of zero or more of the decoder flags: LZMA_TELL_NO_CHECK, LZMA_TELL_UNSUPPORTED_CHECK, LZMA_TELL_ANY_CHECK, LZMA_IGNORE_CHECK, LZMA_CONCATENATED, LZMA_FAIL_FAST. ### Returns - **LZMA_OK**: Initialization was successful. - **LZMA_MEM_ERROR**: Cannot allocate memory. - **LZMA_OPTIONS_ERROR**: Unsupported flags. - **LZMA_PROG_ERROR**: Programming error. ``` -------------------------------- ### liblzma Typedefs Reference Source: https://tukaani.org/xz/liblzma-api/globals_type.html A list of documented typedefs available for use in liblzma applications. ```APIDOC ## liblzma Typedefs - **lzma_bool** (base.h) - Boolean type used within the library. - **lzma_index** (index.h) - Opaque structure for handling .xz index data. - **lzma_index_hash** (index_hash.h) - Opaque structure for hashing index data. - **lzma_internal** (base.h) - Internal library type definition. - **lzma_vli** (vli.h) - Variable-length integer type used for encoding and decoding. ``` -------------------------------- ### Define LZMA_PRESET_EXTREME Source: https://tukaani.org/xz/liblzma-api/container_8h.html Flag to enable extreme compression, which increases encoding time for marginal ratio improvements. ```c #define LZMA_PRESET_EXTREME (UINT32_C(1) << 31) ``` -------------------------------- ### lzma_microlzma_decoder() Source: https://tukaani.org/xz/liblzma-api/container_8h.html Initializes the MicroLZMA decoder. The lzma_code() usage with this decoder follows standard liblzma patterns. ```APIDOC ## lzma_microlzma_decoder() ### Description Initializes the MicroLZMA decoder. This function prepares the lzma_stream structure for decoding a MicroLZMA stream. ### Signature `lzma_ret lzma_microlzma_decoder(lzma_stream *strm, uint64_t comp_size, uint64_t uncomp_size, lzma_bool uncomp_size_is_exact, uint32_t dict_size)` ### Parameters - **strm** (lzma_stream *) - Pointer to lzma_stream that is at least initialized with LZMA_STREAM_INIT. - **comp_size** (uint64_t) - Compressed size of the MicroLZMA stream. - **uncomp_size** (uint64_t) - Uncompressed size of the MicroLZMA stream. - **uncomp_size_is_exact** (lzma_bool) - If true, uncomp_size must be exactly correct for improved error detection. - **dict_size** (uint32_t) - LZMA dictionary size used during compression. ### Returns - **lzma_ret** - Returns LZMA_OK, LZMA_MEM_ERROR, LZMA_OPTIONS_ERROR, or LZMA_PROG_ERROR. ``` -------------------------------- ### lzma_file_info_decoder Source: https://tukaani.org/xz/liblzma-api/index_8h.html Initializes a .xz file information decoder to extract metadata and index information from a file stream. ```APIDOC ## lzma_ret lzma_file_info_decoder(lzma_stream *strm, lzma_index **dest_index, uint64_t memlimit, uint64_t file_size) ### Description Initializes a .xz file information decoder. This function decodes the Stream Header, Stream Footer, Index, and Stream Padding fields from an input .xz file and stores the resulting combined index in the provided dest_index pointer. ### Parameters - **strm** (lzma_stream *) - Pointer to a properly prepared lzma_stream. - **dest_index** (lzma_index **) - Pointer to a pointer where the decoder will store the decoded lzma_index. - **memlimit** (uint64_t) - Memory limit for the resulting lzma_index. Use UINT64_MAX to disable. - **file_size** (uint64_t) - The total size of the input .xz file. ### Returns - **lzma_ret** - Returns LZMA_OK, LZMA_MEM_ERROR, or LZMA_PROG_ERROR upon initialization. ### Usage Notes - During decoding, lzma_code() may return LZMA_SEEK_NEEDED, requiring the application to seek to strm->seek_pos. - Valid actions for lzma_code() are LZMA_RUN and LZMA_FINISH. ``` -------------------------------- ### Define Version Stability Source: https://tukaani.org/xz/liblzma-api/version_8h.html Sets the stability marker for the current liblzma release. ```c #define LZMA_VERSION_STABILITY LZMA_VERSION_STABILITY_STABLE ``` -------------------------------- ### lzma_stream_encoder() Source: https://tukaani.org/xz/liblzma-api/container_8h.html Initializes .xz Stream encoder using a custom filter chain. ```APIDOC ## lzma_stream_encoder() ### Description Initializes .xz Stream encoder using a custom filter chain. ### Parameters - **strm** (lzma_stream *) - Pointer to lzma_stream that is at least initialized with LZMA_STREAM_INIT. - **filters** (const lzma_filter *) - Array of filters terminated with .id == LZMA_VLI_UNKNOWN. - **check** (lzma_check) - Type of the integrity check to calculate from uncompressed data. ### Returns - **lzma_ret**: LZMA_OK, LZMA_MEM_ERROR, LZMA_UNSUPPORTED_CHECK, LZMA_OPTIONS_ERROR, or LZMA_PROG_ERROR. ``` -------------------------------- ### lzma_raw_decoder Source: https://tukaani.org/xz/liblzma-api/filter_8h.html Initializes a raw decoder for custom file format implementations. ```APIDOC ## lzma_raw_decoder(lzma_stream *strm, const lzma_filter *filters) ### Description Initializes the raw decoder. The 'action' with lzma_code() can be LZMA_RUN or LZMA_FINISH. ### Parameters - **strm** (lzma_stream *) - Required - Pointer to lzma_stream initialized with LZMA_STREAM_INIT. - **filters** (const lzma_filter *) - Required - Array of filters terminated with .id == LZMA_VLI_UNKNOWN. ### Returns - **lzma_ret** - Returns LZMA_OK, LZMA_MEM_ERROR, LZMA_OPTIONS_ERROR, or LZMA_PROG_ERROR. ``` -------------------------------- ### lzma_stream_decoder_mt() Source: https://tukaani.org/xz/liblzma-api/container_8h.html Initializes the multithreaded .xz Stream decoder for parallel block decoding. ```APIDOC ## lzma_stream_decoder_mt() ### Description Initializes the multithreaded .xz Stream decoder. This decoder can decode multiple Blocks in parallel if the Block Headers contain the necessary size information. ### Parameters - **strm** (lzma_stream*) - Required - Pointer to lzma_stream that is at least initialized with LZMA_STREAM_INIT. - **options** (const lzma_mt*) - Required - Pointer to multithreaded compression options. ### Returns - **LZMA_OK**: Initialization was successful. - **LZMA_MEM_ERROR**: Cannot allocate memory. - **LZMA_MEMLIMIT_ERROR**: Memory usage limit was reached. - **LZMA_OPTIONS_ERROR**: Unsupported flags. - **LZMA_PROG_ERROR**: Programming error. ``` -------------------------------- ### lzma_block_decoder() Source: https://tukaani.org/xz/liblzma-api/block_8h.html Initializes the .xz Block decoder. This function decodes Block Data, Block Padding, and Check values, but does not decode the Block Header. ```APIDOC ## lzma_block_decoder(lzma_stream *strm, lzma_block *block) ### Description Initializes the .xz Block decoder. Valid actions for lzma_code() are LZMA_RUN and LZMA_FINISH. ### Parameters - **strm** (lzma_stream*) - Required - Pointer to lzma_stream initialized with LZMA_STREAM_INIT. - **block** (lzma_block*) - Required - Block options. ### Returns - **lzma_ret** - LZMA_OK, LZMA_PROG_ERROR, or LZMA_MEM_ERROR. ``` -------------------------------- ### lzma_raw_encoder Source: https://tukaani.org/xz/liblzma-api/filter_8h.html Initializes a raw encoder for custom file format implementations. ```APIDOC ## lzma_raw_encoder(lzma_stream *strm, const lzma_filter *filters) ### Description Initializes the raw encoder. The 'action' with lzma_code() can be LZMA_RUN, LZMA_SYNC_FLUSH (if supported), or LZMA_FINISH. ### Parameters - **strm** (lzma_stream *) - Required - Pointer to lzma_stream initialized with LZMA_STREAM_INIT. - **filters** (const lzma_filter *) - Required - Array of filters terminated with .id == LZMA_VLI_UNKNOWN. ### Returns - **lzma_ret** - Returns LZMA_OK, LZMA_MEM_ERROR, LZMA_OPTIONS_ERROR, or LZMA_PROG_ERROR. ``` -------------------------------- ### Define LZMA_PRESET_DEFAULT Source: https://tukaani.org/xz/liblzma-api/container_8h.html Represents the default compression preset level. ```c #define LZMA_PRESET_DEFAULT UINT32_C(6) ``` -------------------------------- ### uint64_t lzma_physmem(void) Source: https://tukaani.org/xz/liblzma-api/hardware_8h.html Retrieves the total amount of physical memory (RAM) available on the system in bytes. ```APIDOC ## uint64_t lzma_physmem(void) ### Description Returns the total amount of physical memory (RAM) in bytes. This is useful for calculating memory usage limits for compression or decompression operations. ### Returns - **uint64_t**: The total amount of physical memory in bytes. Returns zero if the amount cannot be determined or an error occurs. ``` -------------------------------- ### lzma_version_string Source: https://tukaani.org/xz/liblzma-api/version_8h.html Retrieves the run-time version of the liblzma library as a human-readable string. ```APIDOC ## const char * lzma_version_string(void) ### Description Returns the run-time version of the liblzma library as a string. This is useful for logging or displaying the library version currently in use by the application. ### Returns - **const char *** - A string representation of the liblzma version. ``` -------------------------------- ### lzma_easy_buffer_encode() Source: https://tukaani.org/xz/liblzma-api/container_8h.html Performs single-call .xz Stream encoding using a preset number. ```APIDOC ## lzma_easy_buffer_encode() ### Description Performs single-call .xz Stream encoding using a preset number. The maximum required output buffer size can be calculated with lzma_stream_buffer_bound(). ### Parameters - **preset** (uint32_t) - Compression preset to use. - **check** (lzma_check) - Type of the integrity check to calculate from uncompressed data. - **allocator** (const lzma_allocator *) - Custom allocator functions; set to NULL to use malloc() and free(). - **in** (const uint8_t *) - Beginning of the input buffer. - **in_size** (size_t) - Size of the input buffer. - **out** (uint8_t *) - Beginning of the output buffer. - **out_pos** (size_t *) - Pointer to the current position in the output buffer; updated only if encoding succeeds. - **out_size** (size_t) - Size of the output buffer. ### Returns - **lzma_ret**: LZMA_OK, LZMA_BUF_ERROR, LZMA_UNSUPPORTED_CHECK, LZMA_OPTIONS_ERROR, LZMA_MEM_ERROR, LZMA_DATA_ERROR, or LZMA_PROG_ERROR. ``` -------------------------------- ### liblzma API Overview Source: https://tukaani.org/xz/liblzma-api/globals.html The liblzma library provides a wide range of functions for handling XZ and LZMA compression formats. Key areas include stream encoding/decoding, block processing, index management, and hardware-specific filters. ```APIDOC ## liblzma API Reference ### Overview The liblzma library provides functions for compression and decompression. Users interact with the library through various headers: - **base.h**: Core functions like `lzma_code()`, `lzma_end()`, and memory management. - **container.h**: High-level container formats (e.g., `lzma_easy_encoder()`, `lzma_auto_decoder()`). - **block.h**: Low-level block processing functions. - **index.h**: Functions for managing and validating index structures. - **filter.h**: Filter management for custom compression chains. ### Key Functions - `lzma_code()`: Main function to process data. - `lzma_end()`: Clean up resources associated with a stream. - `lzma_easy_encoder()`: Initialize an encoder with preset settings. - `lzma_auto_decoder()`: Initialize a decoder that detects the format automatically. ### Constants - `LZMA_OK`, `LZMA_STREAM_END`, `LZMA_MEM_ERROR`, `LZMA_DATA_ERROR` are common return codes used throughout the API. ``` -------------------------------- ### lzma_set_ext_size Source: https://tukaani.org/xz/liblzma-api/lzma12_8h.html Macro to set the 64-bit uncompressed size for LZMA1EXT filtering. ```APIDOC ## lzma_set_ext_size(opt_lzma2, u64size) ### Description Sets the 64-bit uncompressed size in the provided structure. This is specifically intended for use with LZMA_FILTER_LZMA1EXT. ### Parameters - **opt_lzma2**: The structure to update. - **u64size**: The 64-bit size value to assign. ``` -------------------------------- ### lzma_match_finder Source: https://tukaani.org/xz/liblzma-api/lzma12_8h.html Enumeration of available match finder algorithms that impact compression speed and ratio. ```APIDOC ## enum lzma_match_finder ### Description Defines the match finder algorithm used during compression. The choice affects both performance and the resulting compression ratio. ### Enumerators - **LZMA_MF_HC3**: Hash Chain with 2- and 3-byte hashing. - **LZMA_MF_HC4**: Hash Chain with 2-, 3-, and 4-byte hashing. - **LZMA_MF_BT2**: Binary Tree with 2-byte hashing. - **LZMA_MF_BT3**: Binary Tree with 2- and 3-byte hashing. - **LZMA_MF_BT4**: Binary Tree with 2-, 3-, and 4-byte hashing. ``` -------------------------------- ### Retrieve Run-time Version Number Source: https://tukaani.org/xz/liblzma-api/version_8h.html Returns the integer version number of the linked liblzma library. ```c uint32_t lzma_version_number (void) lzma_nothrow lzma_attr_const ``` -------------------------------- ### Compress Shared Libraries with BCJ Filter Source: https://tukaani.org/xz/man/xz.1.html Applies the x86 BCJ filter before LZMA2 to improve compression of x86-32 or x86-64 shared libraries. ```bash xz --x86 --lzma2 libfoo.so ``` -------------------------------- ### Match Finder Enumeration Source: https://tukaani.org/xz/liblzma-api/lzma12_8h.html Enumeration defining the available match finder algorithms, which significantly impact compression speed and ratio. ```c enum lzma_match_finder ``` -------------------------------- ### Define LZMA_TELL_ANY_CHECK Source: https://tukaani.org/xz/liblzma-api/container_8h.html Flag to trigger LZMA_GET_CHECK return as soon as the integrity check type is identified. ```c #define LZMA_TELL_ANY_CHECK UINT32_C(0x04) ``` -------------------------------- ### lzma_mode_is_supported() Source: https://tukaani.org/xz/liblzma-api/lzma12_8h.html Checks if a specific compression mode is supported by the current liblzma build. ```APIDOC ## lzma_bool lzma_mode_is_supported(lzma_mode mode) ### Description Tests if the given compression mode is supported by the current liblzma build. It is safe to call this with a value not listed in the lzma_mode enumeration, which will return false. ### Parameters - **mode** (lzma_mode) - Required - The compression mode ID to check. ### Returns - **lzma_bool** - Returns true if the compression mode is supported, false otherwise. ``` -------------------------------- ### Optimize Source Code Compression Source: https://tukaani.org/xz/man/xz.1.html Adjusts literal context bits and position bits to achieve higher compression ratios for US-ASCII source code archives. ```bash xz --lzma2=preset=6e,pb=0,lc=4 source_code.tar ``` -------------------------------- ### Check filter decoder support Source: https://tukaani.org/xz/liblzma-api/filter_8h.html Tests if a specific Filter ID is supported for decoding in the current liblzma build. ```c lzma_bool lzma_filter_decoder_is_supported(lzma_vli id) ``` -------------------------------- ### Define LZMA_STR_NO_SPACES constant Source: https://tukaani.org/xz/liblzma-api/filter_8h.html Flag to use double dashes instead of spaces to separate filters in a string. ```c #define LZMA_STR_NO_SPACES UINT32_C(0x80) ``` -------------------------------- ### lzma_stream_decoder Source: https://tukaani.org/xz/liblzma-api/container_8h.html Initializes an .xz Stream decoder with a specified memory limit and flags. ```APIDOC ## lzma_stream_decoder ### Description Initializes an .xz Stream decoder. The memory limit prevents excessive memory usage during decompression. ### Signature lzma_ret lzma_stream_decoder(lzma_stream *strm, uint64_t memlimit, uint32_t flags) ``` -------------------------------- ### lzma_easy_decoder_memusage() Source: https://tukaani.org/xz/liblzma-api/container_8h.html Calculates the approximate decoder memory usage for a given compression preset. ```APIDOC ## lzma_easy_decoder_memusage() ### Description Calculate approximate decoder memory usage of a preset. This function is a wrapper for lzma_raw_decoder_memusage(). ### Parameters - **preset** (uint32_t) - Compression preset (level and possible flags). ### Returns - **uint64_t** - Number of bytes of memory required to decompress a file that was compressed using the given preset or UINT64_MAX on error. ``` -------------------------------- ### lzma_easy_encoder_memusage() Source: https://tukaani.org/xz/liblzma-api/container_8h.html Calculates the approximate memory usage of the easy encoder based on the provided compression preset. ```APIDOC ## lzma_easy_encoder_memusage() ### Description Calculate approximate memory usage of easy encoder. This function is a wrapper for lzma_raw_encoder_memusage(). ### Parameters - **preset** (uint32_t) - Compression preset (level and possible flags) ### Returns - **uint64_t** - Number of bytes of memory required for the given preset when encoding or UINT64_MAX on error. ``` -------------------------------- ### Verify Quoting Style Changes Source: https://tukaani.org/xz-backdoor/review.html Use this command to verify changes in quoting style by comparing git diff output and filtering for specific character replacements. ```bash git diff ce162db07f03^..9fb5de41f2fb \ | sed "/^-/{s/\`/'/g;s/^-/+/}" \ | grep ^+ | sort | uniq -u ``` -------------------------------- ### lzma_mf_is_supported Source: https://tukaani.org/xz/liblzma-api/lzma12_8h.html Tests if a specific match finder algorithm is supported by the current build of liblzma. ```APIDOC ## lzma_bool lzma_mf_is_supported(lzma_match_finder match_finder) ### Description Checks if the provided match finder is supported. ### Parameters - **match_finder** (lzma_match_finder) - The match finder enum value to test. ``` -------------------------------- ### Check filter encoder support Source: https://tukaani.org/xz/liblzma-api/filter_8h.html Tests if a specific Filter ID is supported for encoding in the current liblzma build. ```c lzma_bool lzma_filter_encoder_is_supported(lzma_vli id) ``` -------------------------------- ### lzma_get_progress() Source: https://tukaani.org/xz/liblzma-api/base_8h.html Retrieves accurate progress information for both single-threaded and multi-threaded compression/decompression modes. ```APIDOC ## lzma_get_progress(lzma_stream *strm, uint64_t *progress_in, uint64_t *progress_out) ### Description Provides realistic progress metrics by accounting for internally buffered data in multi-threaded modes. In single-threaded mode, it returns the values from strm->total_in and strm->total_out. ### Parameters - **strm** (lzma_stream*) - Required - Pointer to an lzma_stream initialized with LZMA_STREAM_INIT. - **progress_in** (uint64_t*) - Required - Pointer to store the number of input bytes processed. - **progress_out** (uint64_t*) - Required - Pointer to store the number of output bytes processed. ``` -------------------------------- ### Delta Filter Constants Source: https://tukaani.org/xz/liblzma-api/delta_8h.html Macros and enumerations defining the Delta filter behavior. ```APIDOC ## Macros - **LZMA_FILTER_DELTA**: 0x03 (Filter ID for the Delta filter) - **LZMA_DELTA_DIST_MIN**: 1 (Minimum allowed distance) - **LZMA_DELTA_DIST_MAX**: 256 (Maximum allowed distance) ## Enumerations ### lzma_delta_type - **LZMA_DELTA_TYPE_BYTE**: Byte-wise delta calculation. ``` -------------------------------- ### Set 64-bit Uncompressed Size Macro Source: https://tukaani.org/xz/liblzma-api/lzma12_8h.html Macro used to set the 64-bit uncompressed size in ext_size fields, primarily for use with LZMA_FILTER_LZMA1EXT. ```c do { \ (opt_lzma2).ext_size_low = (uint32_t)(u64size); \ (opt_lzma2).ext_size_high = (uint32_t)((uint64_t)(u64size) >> 32); \ } while (0) ``` -------------------------------- ### lzma_str_to_filters() Source: https://tukaani.org/xz/liblzma-api/filter_8h.html Converts a string representing a preset or a filter chain into an array of lzma_filter structures. ```APIDOC ## lzma_str_to_filters() ### Description Converts a string (preset or filter chain) into an array of lzma_filter structures. This function is useful for applications allowing users to define custom compression settings. ### Signature `const char * lzma_str_to_filters(const char *str, int *error_pos, lzma_filter *filters, uint32_t flags, const lzma_allocator *allocator)` ### Parameters - **str** (const char *) - User-supplied string describing a preset or a filter chain. - **error_pos** (int *) - [out] Pointer to an integer that will be set to the location of the error in the string on both success and failure. - **filters** (lzma_filter *) - [out] An array of lzma_filter structures (must have at least LZMA_FILTERS_MAX + 1 elements). - **flags** (uint32_t) - Bitwise-or of flags (e.g., LZMA_STR_ALL_FILTERS, LZMA_STR_NO_VALIDATION). - **allocator** (const lzma_allocator *) - Custom allocator functions, or NULL to use default malloc/free. ### Returns - **const char*** - Returns NULL on success. On error, returns a statically-allocated error message string. ``` -------------------------------- ### lzma_memlimit_set Source: https://tukaani.org/xz/liblzma-api/base_8h.html Sets the memory usage limit. ```APIDOC ## lzma_ret lzma_memlimit_set(lzma_stream *strm, uint64_t memlimit) ### Description Sets the memory usage limit for the coder. ### Parameters - **strm** (lzma_stream*) - Required - Pointer to the lzma_stream structure. - **memlimit** (uint64_t) - Required - The new memory limit in bytes. ``` -------------------------------- ### lzma_mode_is_supported Source: https://tukaani.org/xz/liblzma-api/lzma12_8h.html Tests if a specific compression mode is supported by the current build of liblzma. ```APIDOC ## lzma_bool lzma_mode_is_supported(lzma_mode mode) ### Description Checks if the provided compression mode is supported. ### Parameters - **mode** (lzma_mode) - The compression mode enum value to test. ``` -------------------------------- ### lzma_options_lzma Structure Members Source: https://tukaani.org/xz/liblzma-api/structlzma__options__lzma.html Details regarding the configurable members of the lzma_options_lzma structure. ```APIDOC ## lzma_options_lzma Members ### mf - **Type**: lzma_match_finder - **Description**: Match finder ID used by the encoder. ### depth - **Type**: uint32_t - **Description**: Maximum search depth in the match finder. Setting to zero enables an automatic default value. High values should be used with caution to avoid potential performance degradation. ### ext_flags - **Type**: uint32_t - **Description**: Extended flags used only with LZMA_FILTER_LZMA1EXT. Supports LZMA_LZMA1EXT_ALLOW_EOPM to control the writing and detection of the end marker in the compressed stream. ``` -------------------------------- ### uint32_t lzma_cputhreads(void) Source: https://tukaani.org/xz/liblzma-api/hardware_8h.html Retrieves the number of processor cores or hardware threads available on the system. ```APIDOC ## uint32_t lzma_cputhreads(void) ### Description Returns the number of processor cores or threads available. This is useful for determining the optimal number of threads to use for multi-threaded operations. ### Returns - **uint32_t**: The number of available CPU threads or cores. Returns zero if the information is unavailable or an error occurs. ``` -------------------------------- ### Decode Block Header Size Source: https://tukaani.org/xz/liblzma-api/block_8h.html Use this macro to calculate the Block Header size from the first byte of a Block. Ensure the byte is not 0x00, as that indicates the beginning of an Index. ```c #define lzma_block_header_size_decode(b) (((uint32_t)(b) + 1) * 4) ```