@opfs.js/core
    Preparing search index...

    Class OPFile

    Represents a file in OPFS (Origin Private File System). Provides create, read, write, copy, move operations.

    import { file } from "@opfs.js/core";

    const myFile = file("/docs/example.txt");

    // Create
    await myFile.create();

    // Write
    const rw = await myFile.open({ mode: "readwrite" });
    await rw.write("Hello OPFS!");
    await rw.flush();
    await rw.close();

    // Read
    const ro = await myFile.open({ mode: "read-only" });
    const buffer = await ro.read(1024);
    await ro.close();

    // Move file
    const destDir = await navigator.storage.getDirectory();
    await myFile.moveTo(destDir);

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    fullPath: string

    Full path of the file system object

    kind: "file"

    File kind: always "file"

    name: string

    Name of the file or directory

    parents: string[]

    Parent directories as an array of strings

    Methods

    • Read the file as ArrayBuffer.

      Returns Promise<ArrayBuffer>

    • Copy the file to a destination directory, file handle, or OPFile.

      Parameters

      • dest: FileSystemFileHandle | FileSystemDirectoryHandle | default

        Destination

      Returns Promise<void>

    • Create the file if it does not exist.

      Returns Promise<FileSystemFileHandle>

    • Get the underlying File object.

      Returns Promise<undefined | File>

    • Move the file to a destination directory, file handle, or OPFile.

      Parameters

      • dest: FileSystemFileHandle | FileSystemDirectoryHandle | default

        Destination

      Returns Promise<void>

    • Get a ReadableStream for the file content.

      Returns Promise<ReadableStream<BufferSource>>

    • Read the file as text.

      Returns Promise<string>