code wiki / (root) / gzip_header.nx

gzip_header.nx

buildroot/runtime/gzip_header.nx

5637 B171 linesdepth 3pulls 3 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

syscalls.nx gzip_header.nx

imports: syscalls.nx

imported by: nobody (leaf or entry point)

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

main gzip_parse_header gz_read_u32 gz_scan_nul

structs

50struct GzipHeader {

consts

36const GZIP_MAGIC_0: i64 = 0x1F
37const GZIP_MAGIC_1: i64 = 0x8B
38const GZIP_METHOD_DEFLATE: i64 = 8
40const GZIP_FLG_FTEXT: i64 = 0x01
41const GZIP_FLG_FHCRC: i64 = 0x02
42const GZIP_FLG_FEXTRA: i64 = 0x04
43const GZIP_FLG_FNAME: i64 = 0x08
44const GZIP_FLG_FCOMMENT: i64 = 0x10
46const GZIP_ERR_FORMAT: i64 = -1
47const GZIP_ERR_METHOD: i64 = -2
48const GZIP_ERR_SHORT: i64 = -3

functions

66func gz_read_u32(buf: *u8, off: i64) -> i64 {
called by 1: gzip_parse_header
76func gz_scan_nul(buf: *u8, n: i64, off: i64) -> i64 {
called by 1: gzip_parse_header
85func gzip_parse_header(buf: *u8, n: i64, h: *GzipHeader) -> i64 {
called by 1: main calls 2: gz_read_u32gz_scan_nul
145func main() -> i64 {