Skip to main content

Crate lzxc

Crate lzxc 

Source
Expand description

LZX compression encoder.

Produces byte streams that round-trip through the lzxd decoder. See the MS-PATCH LZX-DELTA format spec for the on-disk layout.

§Two entry points

  • EncoderWriter: a std::io::Write sink. Buffers input into 32 KB slabs, compresses each slab, and forwards u16 BE size | compressed frames to an inner sink. Call EncoderWriter::finish at the end.
  • Encoder: the chunk-at-a-time primitive. Use this when you want to control the framing yourself (an XEX “Normal” data region, for example, wraps chunks in its own block header).

§Strategy

Strategy controls how a chunk is encoded:

  • Strategy::Greedy (default): verbatim block + hash-chain match finder with a greedy parser. Cross-chunk match history is kept in the Encoder so matches can span chunk boundaries. On representative XEX PE payloads this lands around 1.8:1 (~55% of input).
  • Strategy::LiteralOnly: verbatim block with no LZ77 matching. Useful as a Huffman-only baseline.
  • Strategy::Uncompressed: type-3 blocks only. No compression, fastest.

§Not implemented

  • Aligned-offset blocks (block type 2). A verbatim block always works in their place, so output is valid without them.

§Example: Write sink

use lzxc::{EncoderWriter, WindowSize};
use std::io::Write;

let mut out: Vec<u8> = Vec::new();
let mut enc = EncoderWriter::new(&mut out, WindowSize::KB64);
enc.write_all(b"hello world, hello world, hello world!").unwrap();
enc.finish().unwrap();
// `out` is now a sequence of `u16 BE size | compressed chunk` frames.

§Example: chunk-at-a-time

use lzxc::{Encoder, WindowSize, MAX_CHUNK_SIZE};

let input: &[u8] = b"...some PE image...";
let mut enc = Encoder::new(WindowSize::KB64);
for slab in input.chunks(MAX_CHUNK_SIZE) {
    let compressed = enc.encode_chunk(slab);
    // `compressed` decodes with `lzxd::Lzxd::decompress_next`.
}

Structs§

Encoder
LZX encoder: produces one compressed chunk per call.
EncoderWriter
std::io::Write sink that compresses its input with LZX and forwards u16 BE size | compressed chunk frames to an inner writer.

Enums§

Strategy
How a chunk gets encoded. Set via Encoder::with_strategy / EncoderWriter::with_strategy; the default is Strategy::Greedy.
WindowSize
LZX window sizes. Mirrors the sizes in the lzxd decoder crate so callers can pass the same choice to both sides of a round-trip.

Constants§

MAX_CHUNK_SIZE
Maximum input size passed to a single Encoder::encode_chunk call (32 KB).