# std/storage

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.

## writeAtomic

`fn`, at line 25.

```vyrn
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.

---

From https://vyrn-lang.github.io/docs/std/storage.html — generated by `site/export.vyrn` from the Vyrn repository.
