nx_deflate.nx
buildroot/runtime/nx_deflate.nx
about
nx_deflate.nx -- RFC 1951 INFLATE (DEFLATE decompression).
CAPABILITY_COMPLETENESS: FULL -- all three BTYPE handlers
(stored, static Huffman, dynamic Huffman) implemented end-to-end.
Built per the four-pillar discipline: no error-coded skip-paths
shipped as "complete primitives". See
`feedback-no-skip-paths-as-error-codes` cardinal.
Composes:
nx_bitstream (LSB-first reader)
nx_huffman (canonical Huffman decode)
+ sliding-window LZ77 with 32 KB window.
DEFLATE block format (RFC 1951):
1 bit BFINAL (1 = last block)
2 bits BTYPE
00 = stored block (no compression)
01 = static Huffman (predefined trees)
10 = dynamic Huffman (trees encoded in stream)
11 = reserved (error)
Stored block:
skip to byte boundary
LEN (16-bit LE)
NLEN (16-bit LE; one's-complement of LEN; checksum)
LEN bytes copied verbatim to output
Static Huffman block:
literal/length alphabet of 288 symbols (only 286 used; 286-287
are invalid placeholders) with predefined lengths:
0-143 : length 8
144-255 : length 9
256-279 : length 7 (256 = end-of-block)
280-287 : length 8
distance alphabet: all 30 symbols, length 5
Dynamic Huffman block (BTYPE=10):
HLIT (5 bits) + 257 = literal/length code count
HDIST (5 bits) + 1 = distance code count
HCLEN (4 bits) + 4 = code-length code count
dependencies 5 imports · 14 importers
diagram shows first 10 each side; +0 more imports, +4 more importers in the complete lists below.
imports: nx_syscalls.nxnx_runtime.nxnx_tier.nxnx_bitstream.nxnx_huffman.nx
imported by: nx_cbx_pages.nxnx_deflate_byte_diff_test.nxnx_deflate_bytes_consumed_test.nxnx_deflate_enc_gate.nxnx_deflate_huffman_test.nxnx_epub_book.nxnx_epub_read.nxnx_gzip_wrap.nxnx_inflate_kat_test.nxnx_opc.nxnx_safe_archive_ingest.nxnx_varfacts_lib.nxnx_zip_extract1.nxnx_zlib_wrap.nx
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| 117 | struct NxDeflateResult |
consts
| 67 | const NX_MAGIC_1025: i64 = 1025 |
| 68 | const NX_MAGIC_1537: i64 = 1537 |
| 69 | const NX_MAGIC_2049: i64 = 2049 |
| 70 | const NX_MAGIC_3073: i64 = 3073 |
| 71 | const NX_MAGIC_4097: i64 = 4097 |
| 72 | const NX_MAGIC_6145: i64 = 6145 |
| 73 | const NX_MAGIC_8193: i64 = 8193 |
| 74 | const NX_MAGIC_12289: i64 = 12289 |
| 75 | const NX_MAGIC_16385: i64 = 16385 |
| 76 | const NX_MAGIC_24577: i64 = 24577 |
| 77 | const NX_MAGIC_16777216: i64 = 16777216 |
| 78 | const NX_MAGIC_65535: i64 = 65535 |
| 79 | const NX_MAGIC_65536: i64 = 65536 |
| 83 | const NX_DEF_OK: nx_int = 0 |
| 84 | const NX_DEF_ERR_RESERVED: nx_int = 1 |
| 85 | const NX_DEF_ERR_NLEN: nx_int = 2 |
| 86 | const NX_DEF_ERR_OVERFLOW: nx_int = 3 |
| 87 | const NX_DEF_ERR_DYNAMIC_CL: nx_int = 4 |
| 88 | const NX_DEF_ERR_HUFFMAN: nx_int = 5 |
| 89 | const NX_DEF_ERR_DISTANCE: nx_int = 6 |
| 124 | const NX_DEF_RESULT_BYTES: nx_size = 32 |
functions
| 92 | func _deflate_cl_order(i: nx_int) -> nx_int called by 1: _deflate_build_dynamic_trees |
| 131 | func _deflate_length_base(code: nx_int) -> nx_int called by 1: _deflate_decode_huffman_block |
| 164 | func _deflate_length_extra(code: nx_int) -> nx_int called by 1: _deflate_decode_huffman_block |
| 175 | func _deflate_distance_base(code: nx_int) -> nx_int called by 1: _deflate_decode_huffman_block |
| 209 | func _deflate_distance_extra(code: nx_int) -> nx_int called by 1: _deflate_decode_huffman_block |
| 230 | func _deflate_build_static_litlen() -> *NxHuffmanTable |
| 252 | func _deflate_build_static_dist() -> *NxHuffmanTable |
| 264 | func _deflate_copy_overlap(out: *u8, dst: nx_int, src: nx_int, n: nx_int) -> nx_int called by 1: _deflate_decode_huffman_block |
| 279 | func _deflate_decode_huffman_block( |
| 362 | func _deflate_build_dynamic_trees( |
| 501 | func _deflate_inflate_block( |
| 579 | func _deflate_bytes_consumed(bs: *NxBitStream) -> nx_int called by 1: nx_deflate_inflate |
| 586 | func nx_deflate_inflate(input: *u8, input_size: nx_int, |
| 628 | func main() -> nx_int |