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: astd::io::Writesink. Buffers input into 32 KB slabs, compresses each slab, and forwardsu16 BE size | compressedframes to an inner sink. CallEncoderWriter::finishat 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 theEncoderso 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.
- Encoder
Writer std::io::Writesink that compresses its input with LZX and forwardsu16 BE size | compressed chunkframes to an inner writer.
Enums§
- Strategy
- How a chunk gets encoded. Set via
Encoder::with_strategy/EncoderWriter::with_strategy; the default isStrategy::Greedy. - Window
Size - 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_chunkcall (32 KB).