Skip to content

File IO

Raul Montoya Cardenas edited this page Jul 29, 2026 · 2 revisions

File I/O

src/io/ — public always; implementation behind feature hdf5.

API

Function Behavior
io::read(path) Load .nirNirGraph
io::read_version(path) Strict /version (errors if absent)
io::write(path, graph) Default options
io::write_with(path, graph, opts) Compression, version override, validate flag

Without feature: all return NirError::Unimplemented(...).

WriteOptions

Field Default Notes
compression Some(4) Deflate 0..=9 for numeric arrays; None = uncompressed
version None Overrides graph.version; else DEFAULT_NIR_VERSION = "1.0.8"
validate true Runs structure + wire checks before truncating file

Scalars, empty arrays, and string datasets are never compressed (HDF5 limits / no benefit).

Read policy

  • Permissive: does not auto-validate_structure (callers decide)
  • Optional Python-default fill for missing fields
  • Graph-level round-trip fidelity, not byte-identical to h5py
  • Safety: external links rejected; nested graph budget; per-dataset size guard (see code comments / #21 for cumulative budget)

Write safety

Pre-checks names, compression range, string NULs, usize extents before File::create so a bad graph does not wipe an existing model.

Related


Last updated: July 29, 2026 Updated by: Grok Build: Grok 4.5 Package tip reference: df72fc9 (main)

Clone this wiki locally