nx_zip.nx
buildroot/runtime/nx_zip.nx
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
imports: nx_syscalls.nx
imported by: nx_zip_gate.nx
structs
| none |
consts
| 32 | const NX_MAGIC_65535: i64 = 65535 |
| 34 | const NX_ZIP_SIG_LOCAL: i64 = 0x04034b50 |
| 35 | const NX_ZIP_SIG_CD: i64 = 0x02014b50 |
| 36 | const NX_ZIP_SIG_EOCD: i64 = 0x06054b50 |
| 37 | const NX_ZIP_LOCAL_LEN: i64 = 30 |
| 38 | const NX_ZIP_CD_LEN: i64 = 46 |
| 39 | const NX_ZIP_EOCD_LEN: i64 = 22 |
| 40 | const NX_ZIP_METHOD_STORE: i64 = 0 |
| 41 | const NX_ZIP_VERSION: i64 = 20 |
| 42 | const NX_ZIP_CRC_POLY: i64 = 0xedb88320 |
| 43 | const NX_ZIP_U32: i64 = 0xffffffff |
| 46 | const NX_ZIP_ST_OFF: i64 = 0 |
| 47 | const NX_ZIP_ST_CDOFF: i64 = 1 |
| 48 | const NX_ZIP_ST_COUNT: i64 = 2 |
| 51 | const NX_ZIP_FLD_CRC: i64 = 0 |
| 52 | const NX_ZIP_FLD_CSIZE: i64 = 1 |
| 53 | const NX_ZIP_FLD_USIZE: i64 = 2 |
| 54 | const NX_ZIP_FLD_NAMELEN: i64 = 3 |
| 55 | const NX_ZIP_FLD_NAMEOFF: i64 = 4 |
| 56 | const NX_ZIP_FLD_LOCALOFF: i64 = 5 |
| 57 | const NX_ZIP_FLD_NEXTCD: i64 = 6 |
| 58 | const NX_ZIP_FLD_METHOD: i64 = 7 |
functions
| 62 | func nxzip_crc32(data: *u8, n: i64) -> i64 |
| 83 | func nxzip_w16(o: *u8, p: i64, v: i64) -> i64 |
| 89 | func nxzip_w32(o: *u8, p: i64, v: i64) -> i64 |
| 97 | func nxzip_r16(b: *u8, p: i64) -> i64 |
| 101 | func nxzip_r32(b: *u8, p: i64) -> i64 |
| 106 | func nxzip_strlen(s: *u8) -> i64 called by 1: nxzip_add_stored |
| 119 | func nxzip_add_stored(out: *u8, cap: i64, cd: *u8, cdcap: i64, st: *i64, |
| 181 | func nxzip_finalize(out: *u8, cap: i64, cd: *u8, st: *i64) -> i64 |
| 206 | func nxzip_find_eocd(data: *u8, n: i64) -> i64 |
| 216 | func nxzip_count(data: *u8, n: i64) -> i64 |
| 222 | func nxzip_cd_start(data: *u8, n: i64) -> i64 |
| 229 | func nxzip_read_cd(data: *u8, n: i64, cdp: i64, fld: *i64) -> i64 |
| 251 | func nxzip_entry_data(data: *u8, n: i64, fld: *i64) -> i64 |