happy-opfs
    Preparing search index...

    Function writeFile

    • Writes content to a file at the specified path. Creates the file and parent directories if they don't exist (unless create: false).

      Overwriting inside a Worker is written to a temporary file in /tmp first and moved into place on success, so an interrupted write leaves the previous content untouched. The main thread's createWritable writes a swap file instead and needs no temp file. Appending always writes in place.

      Parameters

      • filePath: string

        The absolute path of the file to write to.

      • contents: WriteFileContent

        The content to write (string, ArrayBuffer, TypedArray, Blob, or ReadableStream).

      • Optionaloptions: WriteOptions

        Optional write options.

        Options for writing files, including flags for creation and appending.

        • Optionalappend?: boolean

          Whether to append to the file if it already exists.

          false

        • Optionalcreate?: boolean

          Whether to create the file if it does not exist.

          true

      Returns AsyncVoidIOResult

      A promise that resolves to an AsyncVoidIOResult indicating success or failure.

      1.0.0

      // Write string content
      await writeFile('/path/to/file.txt', 'Hello, World!');

      // Write binary content
      await writeFile('/path/to/file.bin', new Uint8Array([1, 2, 3]));

      // Append to existing file
      await writeFile('/path/to/file.txt', '\nMore content', { append: true });