gzip_header.nx
buildroot/runtime/gzip_header.nx
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
imports: syscalls.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| 50 | struct GzipHeader { |
consts
| 36 | const GZIP_MAGIC_0: i64 = 0x1F |
| 37 | const GZIP_MAGIC_1: i64 = 0x8B |
| 38 | const GZIP_METHOD_DEFLATE: i64 = 8 |
| 40 | const GZIP_FLG_FTEXT: i64 = 0x01 |
| 41 | const GZIP_FLG_FHCRC: i64 = 0x02 |
| 42 | const GZIP_FLG_FEXTRA: i64 = 0x04 |
| 43 | const GZIP_FLG_FNAME: i64 = 0x08 |
| 44 | const GZIP_FLG_FCOMMENT: i64 = 0x10 |
| 46 | const GZIP_ERR_FORMAT: i64 = -1 |
| 47 | const GZIP_ERR_METHOD: i64 = -2 |
| 48 | const GZIP_ERR_SHORT: i64 = -3 |
functions
| 66 | func gz_read_u32(buf: *u8, off: i64) -> i64 {
called by 1: gzip_parse_header |
| 76 | func gz_scan_nul(buf: *u8, n: i64, off: i64) -> i64 {
called by 1: gzip_parse_header |
| 85 | func gzip_parse_header(buf: *u8, n: i64, h: *GzipHeader) -> i64 { |
| 145 | func main() -> i64 {
calls 1: gzip_parse_header |