writeFileAtomic
@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:
- Write data to a temporary file in the same directory.
- fsync the temporary file to ensure data is on disk.
- Close the temporary file.
- Rename the temporary file to the target path (atomic operation).
- Optional: fsync the parent directory to ensure metadata is on disk.
Parameters
targetPath
string
data
string | Buffer<ArrayBufferLike>
options?
Returns
Promise<void>