Expand description
Allocation-free streaming zlib encoding and inflation (RFC 1950/1951). The encoder uses stored blocks; the decoder also accepts fixed and dynamic Huffman blocks, with caller-owned history and explicit expansion budgets. The decoder is implemented from RFC 1950 and RFC 1951.
use git_zero_core::{io::{SliceWriter, Write}, zlib::{Inflater, InflateLimits, InflateStatus, WINDOW_SIZE}};
let mut input: &[u8] = &[120, 156, 203, 72, 205, 201, 201, 7, 0, 6, 44, 2, 21];
let mut window = [0; WINDOW_SIZE];
let limits = InflateLimits { max_output: 5, max_ratio: 16, ratio_slack: 0 };
let mut decoder = Inflater::new(&mut window, limits);
let mut scratch = [0; 2];
let mut storage = [0; 5];
let mut staged = SliceWriter::new(&mut storage);
loop {
let progress = decoder.update(input, &mut scratch, true)?;
staged.write_all(&scratch[..progress.written])?;
input = &input[progress.consumed..];
if progress.status == InflateStatus::Finished { break; }
}
assert_eq!(staged.as_bytes(), b"hello");
assert!(input.is_empty());Structs§
- Inflate
Limits - Budgets for one zlib stream, including its decompressed loose-object header.
- Inflate
Progress - Inflater
- Incremental zlib decoder with no allocation or dependency on
std/alloc. - Stored
Encoder
Enums§
Constants§
- WINDOW_
SIZE - DEFLATE’s maximum back-reference distance. Each decoder borrows one window.
Functions§
- compress_
bound - zlib compressBound for its default window/memory settings (as used by Git). Includes wrapper/checksum overhead, with checked arithmetic. This is not a bound on arbitrarily padded streams or other deflate settings. https://github.com/madler/zlib/blob/master/compress.c
- decode_
gzip - Decode a complete single gzip member into caller-owned storage. Validate optional header fields/checksum, raw DEFLATE, CRC32 and ISIZE. Trailing data and concatenated members are rejected. All output is provisional on error.
- write_
parts