Skip to main content

writeFileAtomic

@hardkas/core


@hardkas/core / writeFileAtomic

Function: writeFileAtomic()

writeFileAtomic(targetPath, data, options?): Promise<void>

Defined in: packages/core/src/fs.ts:30

Writes a file atomically using the temp-file-and-rename pattern. Ensures that either the entire file is written or no changes are made.

Pattern:

  1. Write data to a temporary file in the same directory.
  2. fsync the temporary file to ensure data is on disk.
  3. Close the temporary file.
  4. Rename the temporary file to the target path (atomic operation).
  5. Optional: fsync the parent directory to ensure metadata is on disk.

Parameters​

targetPath​

string

data​

string | Buffer<ArrayBufferLike>

options?​

WriteFileAtomicOptions = {}

Returns​

Promise<void>