vyrn

std/storage

1 export, from std/storage.vyrn.

Crash-safe persistence, where a save replaces the whole file or leaves the old one.

writeAtomic writes a sibling temp file and renames it over the target, so a crash leaves the whole old file or the whole new one; writeFile truncates first and can leave a torn file. The global forms save, load and loadOr expand at the call site, where the type is concrete: save(path, value) is writeAtomic(path, toJson(value)), so a module that calls save imports writeAtomic. load yields the prelude LoadResult<T> = Missing | Corrupt(Array<Issue>) | Loaded(T).

writeAtomic is crash-consistent but not power-loss-durable: without an fsync the rename may not reach the disk. For durability, call fsyncFile yourself (fsync temp, rename, fsync dir); an fsync per save is a latency cost most programs do not want.

Dependencies

The import graph shows the whole library.

Imports
Imported by
fn writeAtomic(path: String, content: String) -> Result<Bool, String>

Writes content to path atomically, through a temp in the same directory. A failed write leaves path untouched. A host effect, so generators and comptime code cannot call it.

The temp is <path>.tmp.<seed> with a per-call seed, so concurrent writers never share a temp; the last rename wins. There is no delete primitive, so a failed rename leaves its temp behind: clean <path>.tmp.* out of band.

Tests

2 test blocks in std/storage.vyrn. CI runs all of them.

Test names
  • temp names differ per call, so two writers never share a temp
  • a failed save reports why and leaves the target untouched

Examples

2 programs in examples/ import this module. Each runs as WebAssembly and as a native binary.