@ac-essentials/misc-util
    Preparing search index...

    Function writeFileAtomic

    • 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.

      Parameters

      • filePath: PathLike

        The path to the file where data should be written.

      • data:
            | string
            | ArrayBufferView<ArrayBufferLike>
            | Iterable<(string | ArrayBufferView<ArrayBufferLike>), any, any>
            | AsyncIterable<(string | ArrayBufferView<ArrayBufferLike>), any, any>
            | Stream

        The data to write to the file. Can be a string or a Buffer.

      • Optionaloptions: {
            encoding?: null | BufferEncoding;
            flag?: OpenMode;
            flush?: boolean;
            mode?: Mode;
            signal?: null | AbortSignal;
        }

        Optional settings for writing the file, including encoding, mode, and flags. If options.signal is provided, it can be used to abort the operation.

        • Optionalencoding?: null | BufferEncoding
        • Optionalflag?: OpenMode
        • Optionalflush?: boolean

          If all data is successfully written to the file, and flush is true, filehandle.sync() is used to flush the data.

          false
          
        • Optionalmode?: Mode
        • Optionalsignal?: null | AbortSignal

          When provided the corresponding AbortController can be used to cancel an asynchronous action.

      Returns Promise<void>

      A promise that resolves when the write operation is complete.

      Will throw an error if the write operation fails.