code wiki / (root) / nx_zip.nx

nx_zip.nx

buildroot/runtime/nx_zip.nx

9601 B264 linesdepth 2pulls 2 transitivereach 1 importersview sourcekind librarytopic zip
docsdependenciesstructsconstsfunctions

about

nx_zip.nx -- ZIP archive writer + reader (STORED method): a COMPLETE pair. The tree could READ zips (nx_zip_read.nx) and could not write one. That is half a format: EPUB, OOXML, JAR and every download bundle are ZIP, and producing them was impossible. This closes it with a writer and an independent reader in one file, so it proves by exact round-trip. THE CRC IS THE REFLECTED ONE. ZIP uses CRC-32 with polynomial 0xEDB88320 (the reflected form of 0x04C11DB7), init and final-xor both 0xFFFFFFFF. This is a DIFFERENT algorithm from the one nx_ogg.nx uses, which is the same polynomial UNreflected with zero init. Two formats in this tree now use "CRC-32" and they are not interchangeable -- swapping them yields archives that every unzip rejects with a checksum error. T1 pins this one to the classic check value: CRC32("123456789") == 0xCBF43926. THE OFFSET IS WRITTEN TWICE. Each entry's metadata appears in BOTH the local header and the central directory, and the central directory also carries the local header's byte offset. Readers trust the CENTRAL DIRECTORY -- an archive whose local headers are fine but whose central offsets are wrong opens as empty or corrupt, and the local headers give no hint anything is off. STORED, NOT DEFLATED. Method 0 stores bytes verbatim. That is a fully valid ZIP that every tool opens; wiring nx_deflate_enc.nx in as method 8 is a compression improvement, not a correctness one. genealogy_id: pkware_appnote_zip lineage_id: nx_zip_v1 license_tier: ORIGINAL

dependencies 1 imports · 1 importers

nx_syscalls.nx nx_zip.nx nx_zip_gate.nx

imports: nx_syscalls.nx

imported by: nx_zip_gate.nx

structs

none

consts

32const NX_MAGIC_65535: i64 = 65535
34const NX_ZIP_SIG_LOCAL: i64 = 0x04034b50
35const NX_ZIP_SIG_CD: i64 = 0x02014b50
36const NX_ZIP_SIG_EOCD: i64 = 0x06054b50
37const NX_ZIP_LOCAL_LEN: i64 = 30
38const NX_ZIP_CD_LEN: i64 = 46
39const NX_ZIP_EOCD_LEN: i64 = 22
40const NX_ZIP_METHOD_STORE: i64 = 0
41const NX_ZIP_VERSION: i64 = 20
42const NX_ZIP_CRC_POLY: i64 = 0xedb88320
43const NX_ZIP_U32: i64 = 0xffffffff
46const NX_ZIP_ST_OFF: i64 = 0
47const NX_ZIP_ST_CDOFF: i64 = 1
48const NX_ZIP_ST_COUNT: i64 = 2
51const NX_ZIP_FLD_CRC: i64 = 0
52const NX_ZIP_FLD_CSIZE: i64 = 1
53const NX_ZIP_FLD_USIZE: i64 = 2
54const NX_ZIP_FLD_NAMELEN: i64 = 3
55const NX_ZIP_FLD_NAMEOFF: i64 = 4
56const NX_ZIP_FLD_LOCALOFF: i64 = 5
57const NX_ZIP_FLD_NEXTCD: i64 = 6
58const NX_ZIP_FLD_METHOD: i64 = 7

functions

62func nxzip_crc32(data: *u8, n: i64) -> i64
83func nxzip_w16(o: *u8, p: i64, v: i64) -> i64
89func nxzip_w32(o: *u8, p: i64, v: i64) -> i64
97func nxzip_r16(b: *u8, p: i64) -> i64
101func nxzip_r32(b: *u8, p: i64) -> i64
106func nxzip_strlen(s: *u8) -> i64
called by 1: nxzip_add_stored
119func nxzip_add_stored(out: *u8, cap: i64, cd: *u8, cdcap: i64, st: *i64,
181func nxzip_finalize(out: *u8, cap: i64, cd: *u8, st: *i64) -> i64
called by 1: main calls 2: nxzip_w32nxzip_w16
206func nxzip_find_eocd(data: *u8, n: i64) -> i64
216func nxzip_count(data: *u8, n: i64) -> i64
called by 1: main calls 2: nxzip_find_eocdnxzip_r16
222func nxzip_cd_start(data: *u8, n: i64) -> i64
called by 1: main calls 2: nxzip_find_eocdnxzip_r32
229func nxzip_read_cd(data: *u8, n: i64, cdp: i64, fld: *i64) -> i64
called by 1: main calls 2: nxzip_r32nxzip_r16
251func nxzip_entry_data(data: *u8, n: i64, fld: *i64) -> i64
called by 1: main calls 3: nxzip_r32nxzip_r16nxzip_crc32