Class NodeFileIO

A Node.js-specific implementation of the FileIO interface.

This class supports reading and writing files from/to the filesystem, as well as loading resources over HTTP(S).

Implements

Constructors

Methods

Constructors

Methods

  • Loads data from a given URL or local file path.

    • If the input starts with "http://" or "https://", it fetches the resource over the network.
    • Otherwise, it reads the file from the local filesystem.

    Parameters

    • url: string

      The HTTP(S) URL or local file path to load.

    Returns Promise<Buffer>

    A promise that resolves to a Buffer containing the loaded data.

    An error if the fetch or file read fails.

  • Saves data to the specified target path on the local filesystem.

    • Supports saving both Node.js Buffers and Blobs.
    • Automatically creates directories if they do not exist.

    Parameters

    • data: CrossPlatformBlob | Buffer

      The data to save, as a Buffer or CrossPlatformBlob.

    • targetPath: string

      The absolute or relative file path where data should be written.

    Returns Promise<void>

    A promise that resolves when the file is successfully written.

    An error if the data type is unsupported or the write fails.