Windows Documentation

API Reference | File I/O

LZX Decompression

This section details the LZX decompression algorithm used within the Windows operating system. LZX is a lossless data compression technique that offers high compression ratios, particularly effective for large data sets like disk images and executable files. Understanding LZX decompression is crucial for developers working with compressed file formats or implementing custom file handling mechanisms.

Key Concepts

LZX decompression involves reading a compressed stream and reconstructing the original data. The algorithm utilizes a dictionary-based approach combined with a finite state entropy (FSE) coder. Key elements include:

  • Sliding Window Dictionary: LZX maintains a history of recently seen data, which is used to represent repeated sequences more compactly.
  • Literal Symbols: Uncompressed bytes are represented as literal symbols.
  • Offset/Length Pairs: Matches found in the dictionary are encoded as an offset from the current position and the length of the match.
  • Finite State Entropy Coding: Both literal symbols and offset/length pairs are further compressed using FSE to achieve optimal bit packing.

Decompression Process Overview

The decompression process can be conceptually divided into the following stages:

  1. Initialization: The decompressor initializes its state, including the dictionary buffer and FSE tables.
  2. Reading Symbols: The decompressor reads symbols from the compressed stream. These symbols can be either literal bytes or indications of dictionary matches.
  3. Decoding Literals: If a literal symbol is read, the corresponding byte is directly written to the output stream.
  4. Decoding Matches: If a dictionary match symbol is read, the decompressor uses the encoded offset and length to copy data from the previously decompressed output (the dictionary) to the current output position.
  5. Updating State: After processing each symbol, the decompressor updates its internal state, including advancing the dictionary window.
  6. Termination: The decompression continues until the end of the compressed stream is reached or an end-of-data marker is encountered.

Common Use Cases

LZX decompression is prevalent in several Windows technologies:

Decompression Functions (Illustrative Example)

While direct manipulation of the LZX algorithm is typically handled by system-level APIs, understanding the conceptual functions involved is beneficial. Below is a pseudo-code representation:


// This is a conceptual representation, not actual API code.
typedef struct {
    // Dictionary buffer, FSE tables, state variables, etc.
    uint8_t* dictionary;
    size_t dictionary_size;
    // ... other internal state ...
} LzxDecompressorState;

// Function to initialize the decompressor
bool InitializeLzxDecompressor(LzxDecompressorState* state);

// Function to decompress data from input to output
size_t DecompressLzxChunk(
    LzxDecompressorState* state,
    const uint8_t* compressed_input,
    size_t compressed_input_size,
    uint8_t* decompressed_output,
    size_t decompressed_output_buffer_size
);

// Function to free resources
void FreeLzxDecompressor(LzxDecompressorState* state);
            

Note: Developers typically interact with LZX compression and decompression through higher-level Windows APIs such as those provided by the Windows API for compression (e.g., `CreateCompress` / `CreateDecompress` or specific WIM APIs) rather than by implementing the LZX algorithm directly.

Performance Considerations

LZX decompression is generally CPU-intensive. The performance can be influenced by factors such as:

Further Reading