code wiki / (root) / nx_gzip_header.nx

nx_gzip_header.nx

buildroot/runtime/nx_gzip_header.nx

5720 B177 linesdepth 2pulls 2 transitivereach 0 importersview sourcekind tooltopic gzip
docsdependenciesstructsconstsfunctions

about

gzip_header.nx -- parse RFC 1952 gzip stream headers. gzip = DEFLATE (RFC 1951) + gzip framing (RFC 1952). This module parses the framing, not the compression; a future deflate.nx will handle block decompression. Use cases: inspect a .gz file's original filename + mtime, detect corruption before paying the decompress cost, split a multi-member concatenated archive (gzip supports that), read NAS backup archives. Header layout (fixed-prefix then variable optionals): ID1 1 byte = 0x1F ID2 1 byte = 0x8B CM 1 byte compression method; 8 = DEFLATE FLG 1 byte flag bits MTIME 4 bytes modification time, seconds since epoch LE XFL 1 byte extra flags OS 1 byte originating filesystem FLG bits: bit 0 FTEXT probably ASCII text bit 1 FHCRC header CRC16 follows the header bit 2 FEXTRA extra fields follow (2-byte length + data) bit 3 FNAME original filename follows (NUL-terminated) bit 4 FCOMMENT comment follows (NUL-terminated) bits 5-7 reserved Invariants: G1 Magic (0x1F 0x8B) must match. G2 CM must be 8 (no other method is defined). G3 Unterminated FNAME / FCOMMENT returns GZIP_ERR_SHORT.

dependencies 1 imports · 0 importers

nx_syscalls.nx nx_gzip_header.nx

imports: nx_syscalls.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main sys_mmap gzip_parse_header gz_read_u32 gz_scan_nul

structs

56struct GzipHeader

consts

42const GZIP_MAGIC_0: i64 = 0x1F
43const GZIP_MAGIC_1: i64 = 0x8B
44const GZIP_METHOD_DEFLATE: i64 = 8
46const GZIP_FLG_FTEXT: i64 = 0x01
47const GZIP_FLG_FHCRC: i64 = 0x02
48const GZIP_FLG_FEXTRA: i64 = 0x04
49const GZIP_FLG_FNAME: i64 = 0x08
50const GZIP_FLG_FCOMMENT: i64 = 0x10
52const GZIP_ERR_FORMAT: i64 = -1
53const GZIP_ERR_METHOD: i64 = -2
54const GZIP_ERR_SHORT: i64 = -3

functions

72func gz_read_u32(buf: *u8, off: i64) -> i64
called by 1: gzip_parse_header
82func gz_scan_nul(buf: *u8, n: i64, off: i64) -> i64
called by 1: gzip_parse_header
91func gzip_parse_header(buf: *u8, n: i64, h: *GzipHeader) -> i64
called by 1: main calls 2: gz_read_u32gz_scan_nul
151func main() -> i64