code wiki / (root) / nx_archive_media_recovery.nx

nx_archive_media_recovery.nx

buildroot/runtime/nx_archive_media_recovery.nx

12709 B166 linesdepth 11pulls 51 transitivereach 0 importersview sourcekind tooltopic archive
docsdependenciesstructsconstsfunctions

about

nx_archive_media_recovery.nx -- R6 step B (recovery half): the DIFFERENTIATOR. Reads media/manifest.tsv + the stored image bytes, decodes each (nx_img_to_gray: JPEG/PNG; GIF returns 0 -> perceptual pending), perceptual-hashes the decodable ones (dHash, Krawetz 2011), and DEMONSTRATES recovery: a dead image URL is recovered by perceptual match -- a resized/re-encoded copy of the SAME image still matches (small Hamming) while an unrelated image does not (large Hamming), and nx_phash_nearest picks the survivor. This is what the Wayback Machine cannot do. Emits web_assets/archive/recovery.html (gallery of OUR grabbed media + the recovery proof). Image stack only (composes nx_phash + nx_image_gray over syscalls.nx) -- file-based handoff from nx_archive_media_fetch. license_tier: ORIGINAL

dependencies 3 imports · 0 importers

nx_phash.nx nx_image_gray.nx nx_gif_decode.nx nx_archive_media_recovery.nx

imports: nx_phash.nxnx_image_gray.nxnx_gif_decode.nx

imported by: nobody (leaf or entry point)

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

main iputs sys_read_file sys_openat_rd sys_lseek sys_mmap sys_read sys_close ap apslice decode_any nx_img_to_gray sys_read_file ↻ nx_jpeg_decode_luma sys_mmap ↻ nx_jpeg_dec_ctx_init sys_mmap ↻ _jpeg_ascii_probe_sof sys_mmap ↻ nx_jpeg_seg_init nx_jpeg_seg_next nx_jpeg_classify_marker nx_jpeg_marker_is_lengthle nx_jpeg_sof_parse nx_jpeg_is_progressive prog_be16 nx_jpeg_prog_decode sys_mmap ↻ prog_be16 ↻ nx_jpeg_dqt_parse nx_jpeg_dht_parse nx_jpeg_dht_build_decode_t nx_jpeg_sos_parse prog_next_marker prog_scan sys_mmap ↻ nx_jpeg_huff_decode_symbol nx_jpeg_ent_extend nx_jpeg_ent_receive prog_refine_nz

structs

none

consts

11const K_MAGIC_1000000007: i64 = 1000000007
12const K_MAGIC_4194304: i64 = 4194304

functions

14func iputs(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
called by 1: main
15func inum(v: i64) -> i64 { if v==0 { sys_write(1,"0" as *u8,1); return 0 } var m: i64=v; if m<0 { sys_write(1,"-" as *u8,1); m=0-m } let t: *u8=sys_mmap(24); var k: i64=0; while m>0 { t[k]=(48+(m%10)) as u8; m=m/10; k=k+1 } let o: *u8=sys_mmap(24); var w: i64=0; var q: i64=k-1; while q>=0 { o[w]=t[q]; w=w+1; q=q-1 } sys_write(1,o,w); return 0 }
called by 1: main
16func ap(buf: *u8, off: i64, s: *u8) -> i64 { var i: i64=0; while s[i]!=(0 as u8) { buf[off+i]=s[i]; i=i+1 } return off+i }
called by 1: main
17func apn(buf: *u8, off: i64, v: i64) -> i64 { if v==0 { buf[off]=0x30 as u8; return off+1 } var m: i64=v; if m<0 { buf[off]=0x2d as u8; off=off+1; m=0-m } let t: *u8=sys_mmap(24); var k: i64=0; while m>0 { t[k]=(48+(m%10)) as u8; m=m/10; k=k+1 } var o: i64=off; var q: i64=k-1; while q>=0 { buf[o]=t[q]; o=o+1; q=q-1 } return o }
called by 1: main
18func aphex(buf: *u8, off: i64, v: i64) -> i64 { let tmp: *u8=sys_mmap(16); var m: i64=v; var k: i64=0; while k<16 { let nib: i64=m&0xf; var c: i64=nib+0x30; if nib>9 { c=nib+0x57 } tmp[k]=c as u8; m=m>>4; k=k+1 } var j: i64=0; while j<16 { buf[off+j]=tmp[15-j]; j=j+1 } return off+16 }
called by 1: main
19func apslice(dst: *u8, off: i64, src: *u8, so: i64, sl: i64) -> i64 { var i: i64=0; while i<sl { dst[off+i]=src[so+i]; i=i+1 } return off+sl }
called by 1: main
20func save_file(path: *u8, buf: *u8, n: i64) -> i64 { let fd: i64=sys_openat_wr(path, 0x1a4); if fd<0 { return 0 } var off: i64=0; while off<n { let w: i64=sys_write(fd, ((buf as i64)+off) as *u8, n-off); if w<=0 { sys_close(fd); return 0 } off=off+w } sys_close(fd); return 1 }
called by 1: main calls 1: sys_openat_wr
22func decode_any(path: *u8, wh: *i64) -> *u8
30func cid_hash(buf: *u8, n: i64) -> i64 { var h: i64=0; var i: i64=0; while i<n { h=(h*131+(buf[i] as i64))%K_MAGIC_1000000007; i=i+1 } return h }
called by 1: main
32func main() -> i64