runtime/fs.ts

File system utilities.

view source

Declarations
#

2 declarations

write_file_atomic
#

runtime/fs.ts view source

(deps: Pick<FsWriteDeps, "rename" | "write_text_file"> & Partial<FsRemoveDeps>, path: string, content: string, options?: WriteFileAtomicOptions | undefined): Promise<...> import {write_file_atomic} from '@fuzdev/fuz_app/runtime/fs.js';

Write a file atomically via temp file + rename.

Writes to a unique .{name}.tmp.{pid}.{counter} sibling with exclusive create (O_EXCL), then renames over path so readers either see the old contents or the full new contents — never a partial write. The unique name + exclusive create are load-bearing for secret files: a fixed temp name would let a crash-leftover temp be reopened O_TRUNC with its old (possibly permissive) mode — mode only applies at creation — and the rename would publish that stale inode. Twin of the Rust spine's fuz_sys::secure_file::write_secure_file naming scheme.

deps

write capabilities; pass remove too for best-effort temp cleanup on failure

type Pick<FsWriteDeps, "write_text_file" | "rename"> & Partial<FsRemoveDeps>

path

destination path

type string

content

full file content

type string

options?

optional mode applied at creation

optional

returns

Promise<void>

throws

  • Error - if `write_text_file` or `rename` rejects (permissions, disk full, cross-device rename, etc.)

mutates

  • filesystem — creates the unique temp file then renames it to `path`

WriteFileAtomicOptions
#

runtime/fs.ts view source

WriteFileAtomicOptions import type {WriteFileAtomicOptions} from '@fuzdev/fuz_app/runtime/fs.js';

Options for write_file_atomic.

mode?

POSIX mode for the written file (e.g. 0o600 for secrets). Applied at temp-file creation, so the published file never exists with a laxer mode. Omitted = the runtime default (umask).

type number

Depends on
#

Imported by
#