The path to the file where data should be written.
The data to write to the file. Can be a string or a Buffer.
Optional
options: {Optional settings for writing the file, including encoding, mode, and flags.
If options.signal
is provided, it can be used to abort the operation.
Optional
encoding?: null | BufferEncodingOptional
flag?: OpenModeOptional
flush?: booleanIf all data is successfully written to the file, and flush
is true
, filehandle.sync()
is used to flush the data.
Optional
mode?: ModeOptional
signal?: null | AbortSignalWhen provided the corresponding AbortController
can be used to cancel an asynchronous action.
A promise that resolves when the write operation is complete.
Writes data to a file atomically, ensuring that the file is either fully written or not modified at all.
This function first writes the data to a temporary file and then renames it to the target file path. This approach minimizes the risk of data corruption in case of interruptions during the write process.