← back to roto on ba3a.dev

AtomicFile

object AtomicFile

Writes a file so that it is either fully replaced or left as it was: the content goes to a temporary file beside the target, which is then moved over it in one step. A crash or an exception halfway through never leaves a truncated profile.json or .ase behind. Every codec's write(value, Path) goes through here.

Functions

Link copied to clipboard
fun write(path: Path, body: (OutputStream) -> Unit)

Creates path's parent folders, then replaces path with what body writes.