Implement a pure Rust DEFLATE decompressor in the image crate (or a shared module within it) per RFC 1951.
Requirements#
- Decode DEFLATE compressed data streams
- Support all three block types:
- Non-compressed blocks (BTYPE=00)
- Fixed Huffman codes (BTYPE=01)
- Dynamic Huffman codes (BTYPE=10)
- Huffman tree construction from code lengths
- LZ77 back-reference decoding (length/distance pairs)
- Streaming-friendly API:
fn inflate(input: &[u8]) -> Result<Vec<u8>, DeflateError>
Acceptance Criteria#
- Passes round-trip tests with known compressed data
- Handles edge cases: empty input, maximum back-reference distance (32KB window), all block types
- Unit tests for Huffman tree construction, each block type, and error cases
- No external dependencies
- No
unsafe
Context#
This is the foundation for zlib (used by PNG) and potentially gzip. Must be implemented before the PNG decoder.
Phase 7 — Image Decoders