code wiki / (root) / nx_media_sniff.nx

nx_media_sniff.nx

buildroot/runtime/nx_media_sniff.nx

52799 B1200 linesdepth 3pulls 3 transitivereach 19 importersview sourcekind librarytopic media
docsdependenciesstructsconstsfunctions

about

nx_media_sniff.nx -- determine media type from magic bytes / MIME / extension. Four-tier detection (highest trust first): 1. Magic-byte signature (binary formats; reads actual content) 2. MIME-string parsing (when the source provided Content-Type) 3. URL/path extension (text formats + container disambiguation) 4. mostly-printable (LAST-RESORT fallback -> TEXT) Returns NX_MEDIA_TYPE_* (see nx_media_pool.nx). Returns NX_MEDIA_TYPE_UNKNOWN when all four tiers fail. ===== 2026-07-30 REWRITE (rule 3: rewrite, do not patch-cascade) ===== ROOT DEFECT MEASURED: the old sniffer knew only 6 magics (PNG/JPEG/WebP/GIF/ MP4/WebM + MP3/WAV/OGG). It had NO MPEG-TS detector and no ".ts" extension row, so the ENTIRE 53,567-file cam recording corpus migrated into the vault as type=unknown (proven by reading live NXR1 records in knowledge/store/mvault-seg-1785089367.docs: every _cam.ts record showed type=unknown while _cam.jpg posters showed image). MV_TYPE_MODEL3D and MV_TYPE_BOOK were likewise unreachable from bytes -- there was no sniff code to return. This rewrite closes the door properly: STL/PLY/GLB/FBX 3D, PDF/EPUB/MOBI/DJVU books, WARC web captures, and the full A/V container set. TRUST-ORDER FIX: "mostly printable" is a FALLBACK HEURISTIC, not a magic. The old code returned it from inside the magic tier, which meant an ASCII STL or a .obj mesh was sealed as TEXT before the extension tier ever ran. nx_sniff_bytes_strict() omits that fallback so the composite can order the tiers honestly; nx_sniff_bytes() keeps its original contract for existing callers. CONTAINER REFINEMENT: ZIP and generic-TEXT are CONTAINER verdicts, not final ones -- .epub/.cbz/.3mf/.wacz are all "PK\x03\x04", and .obj/.gcode/.dae are all plain text. For those two verdicts ONLY, the extension tier refines the answer. Every other magic still wins outright. Per the boundary cardinal: sniffer is a TRUST BOUNDARY -- treats every byte as adversarial. Always reads through bounded loops per the JPL Rule 2 cardinal. No const arrays (the CONST[i] trap compiles clean then reads garbage); every signature is a literal. See: docs/NISHI_MEDIA_INGESTION_ROADMAP.md

dependencies 2 imports · 8 importers

nx_syscalls.nx nx_media_pool.nx nx_media_sniff.nx nx_entity_media.nx nx_media_fetch.nx nx_media_gather.nx nx_mvault.nx nx_mvault_ingest.nx nx_mvault_reindex.nx nx_mvault_walk.nx nx_text_ingest_test.nx

imports: nx_syscalls.nxnx_media_pool.nx

imported by: nx_entity_media.nxnx_media_fetch.nxnx_media_gather.nxnx_mvault.nxnx_mvault_ingest.nxnx_mvault_reindex.nxnx_mvault_walk.nxnx_text_ingest_test.nx

structs

none

consts

none

functions

72func nx_sniff_load_u8(p: *u8, i: i64, n: i64) -> i64
81func nx_sniff_at(b: *u8, n: i64, off: i64, lit: *u8, llen: i64) -> i64
95func nx_sniff_find(b: *u8, n: i64, limit: i64, lit: *u8, llen: i64) -> i64
108func nx_sniff_u32le(b: *u8, n: i64, off: i64) -> i64
121func nx_sniff_is_png(b: *u8, n: i64) -> i64
135func nx_sniff_is_jpeg(b: *u8, n: i64) -> i64
144func nx_sniff_is_gif(b: *u8, n: i64) -> i64
159func nx_sniff_is_webp(b: *u8, n: i64) -> i64
173func nx_sniff_is_bmp(b: *u8, n: i64) -> i64
calls 1: nx_sniff_at
180func nx_sniff_is_tiff(b: *u8, n: i64) -> i64
200func nx_sniff_is_ico(b: *u8, n: i64) -> i64
213func nx_sniff_is_psd(b: *u8, n: i64) -> i64
called by 1: nx_sniff_bytes_strict calls 1: nx_sniff_at
219func nx_sniff_is_qoi(b: *u8, n: i64) -> i64
called by 1: nx_sniff_bytes_strict calls 1: nx_sniff_at
225func nx_sniff_is_dds(b: *u8, n: i64) -> i64
called by 1: nx_sniff_bytes_strict calls 1: nx_sniff_at
231func nx_sniff_is_exr(b: *u8, n: i64) -> i64
241func nx_sniff_is_jxl(b: *u8, n: i64) -> i64
249func nx_sniff_is_netpbm(b: *u8, n: i64) -> i64
267func nx_sniff_is_mp4(b: *u8, n: i64) -> i64
279func nx_sniff_isobmff_kind(b: *u8, n: i64) -> i64
313func nx_sniff_is_webm(b: *u8, n: i64) -> i64
328func nx_sniff_is_mpegts(b: *u8, n: i64) -> i64
338func nx_sniff_is_m2ts(b: *u8, n: i64) -> i64
347func nx_sniff_is_mpegps(b: *u8, n: i64) -> i64
359func nx_sniff_is_avi(b: *u8, n: i64) -> i64
called by 1: nx_sniff_bytes_strict calls 1: nx_sniff_at
367func nx_sniff_is_flv(b: *u8, n: i64) -> i64
375func nx_sniff_is_asf(b: *u8, n: i64) -> i64
391func nx_sniff_is_mp3(b: *u8, n: i64) -> i64
408func nx_sniff_is_wav(b: *u8, n: i64) -> i64
422func nx_sniff_is_ogg(b: *u8, n: i64) -> i64
432func nx_sniff_is_flac(b: *u8, n: i64) -> i64
called by 1: nx_sniff_bytes_strict calls 1: nx_sniff_at
438func nx_sniff_is_aiff(b: *u8, n: i64) -> i64
called by 1: nx_sniff_bytes_strict calls 1: nx_sniff_at
449func nx_sniff_is_midi(b: *u8, n: i64) -> i64
called by 1: nx_sniff_bytes_strict calls 1: nx_sniff_at
455func nx_sniff_is_ape(b: *u8, n: i64) -> i64
called by 1: nx_sniff_bytes_strict calls 1: nx_sniff_at
467func nx_sniff_is_glb(b: *u8, n: i64) -> i64
called by 1: nx_sniff_bytes_strict calls 1: nx_sniff_at
473func nx_sniff_is_ply(b: *u8, n: i64) -> i64
485func nx_sniff_is_stl_ascii(b: *u8, n: i64) -> i64
497func nx_sniff_is_stl_binary(b: *u8, n: i64, filesize: i64) -> i64
510func nx_sniff_is_fbx(b: *u8, n: i64) -> i64
called by 1: nx_sniff_bytes_strict calls 1: nx_sniff_at
516func nx_sniff_is_blend(b: *u8, n: i64) -> i64
called by 1: nx_sniff_bytes_strict calls 1: nx_sniff_at
522func nx_sniff_is_vox(b: *u8, n: i64) -> i64
called by 1: nx_sniff_bytes_strict calls 1: nx_sniff_at
528func nx_sniff_is_step(b: *u8, n: i64) -> i64
called by 1: nx_sniff_bytes_strict calls 1: nx_sniff_at
536func nx_sniff_is_pdf(b: *u8, n: i64) -> i64
called by 1: nx_sniff_bytes_strict calls 1: nx_sniff_at
543func nx_sniff_is_epub(b: *u8, n: i64) -> i64
called by 1: nx_sniff_bytes_strict calls 1: nx_sniff_at
551func nx_sniff_is_mobi(b: *u8, n: i64) -> i64
called by 1: nx_sniff_bytes_strict calls 1: nx_sniff_at
557func nx_sniff_is_djvu(b: *u8, n: i64) -> i64
called by 1: nx_sniff_bytes_strict calls 1: nx_sniff_at
563func nx_sniff_is_chm(b: *u8, n: i64) -> i64
called by 1: nx_sniff_bytes_strict calls 1: nx_sniff_at
569func nx_sniff_is_rtf(b: *u8, n: i64) -> i64
582func nx_sniff_is_warc(b: *u8, n: i64) -> i64
called by 1: nx_sniff_bytes_strict calls 1: nx_sniff_at
588func nx_sniff_is_mhtml(b: *u8, n: i64) -> i64
called by 1: nx_sniff_bytes_strict calls 1: nx_sniff_at
598func nx_sniff_is_zip(b: *u8, n: i64) -> i64
608func nx_sniff_is_rar(b: *u8, n: i64) -> i64
called by 1: nx_sniff_bytes_strict calls 1: nx_sniff_at
614func nx_sniff_is_7z(b: *u8, n: i64) -> i64
629func nx_sniff_is_html_token(b: *u8, n: i64) -> i64
653func nx_sniff_is_svg_token(b: *u8, n: i64) -> i64
660func nx_sniff_is_mostly_printable(b: *u8, n: i64) -> i64
691func nx_sniff_bytes_strict(b: *u8, n: i64, filesize: i64) -> i64
768func nx_sniff_bytes(b: *u8, n: i64) -> i64
782func nx_sniff_mime_eq(mime: *u8, mlen: i64, lit: *u8, llen: i64) -> i64
called by 1: nx_sniff_mime calls 1: nx_sniff_load_u8
800func nx_sniff_mime(mime: *u8, mlen: i64) -> i64
called by 2: nx_sniff_fullmain calls 1: nx_sniff_mime_eq
869func nx_sniff_ext_eq(p: *u8, plen: i64, off: i64,
882func nx_sniff_ext_off(path: *u8, plen: i64) -> i64
903func nx_sniff_ext_image(p: *u8, plen: i64, off: i64) -> i64
called by 1: nx_sniff_extension calls 1: nx_sniff_ext_eq
959func nx_sniff_ext_av(p: *u8, plen: i64, off: i64) -> i64
called by 1: nx_sniff_extension calls 1: nx_sniff_ext_eq
1029func nx_sniff_ext_model3d(p: *u8, plen: i64, off: i64) -> i64
called by 1: nx_sniff_extension calls 1: nx_sniff_ext_eq
1075func nx_sniff_ext_doc(p: *u8, plen: i64, off: i64) -> i64
called by 1: nx_sniff_extension calls 1: nx_sniff_ext_eq
1147func nx_sniff_extension(path: *u8, plen: i64) -> i64
1169func nx_sniff_full(b: *u8, n: i64, filesize: i64,
1196func nx_sniff(b: *u8, n: i64,