Interface MFS

The MFS interface allows working with files and directories in a mutable file system.

interface MFS {
    cat(path, options?): AsyncIterable<Uint8Array>;
    chmod(path, mode, options?): Promise<void>;
    cp(source, destination, options?): Promise<void>;
    ls(path?, options?): AsyncIterable<UnixFSEntry>;
    mkdir(path, options?): Promise<void>;
    rm(path, options?): Promise<void>;
    stat(path, options?): Promise<UnixFSStats>;
    touch(path, options?): Promise<void>;
    writeByteStream(bytes, path, options?): Promise<void>;
    writeBytes(bytes, path, options?): Promise<void>;
}

Methods

  • Change the permissions on a file or directory in your MFS

    Parameters

    Returns Promise<void>

    Example

    await fs.writeBytes(Uint8Array.from([0, 1, 2, 3]), '/foo.txt')
    const beforeStats = await fs.stat('/foo.txt')

    await fs.chmod('/foo.txt', 0x755)
    const afterStats = await fs.stat('/foo.txt')

    console.info(beforeStats)
    console.info(afterStats)
  • Add a file or directory to a target directory in your MFS.

    Parameters

    Returns Promise<void>

    Example

    await fs.writeBytes(Uint8Array.from([0, 1, 2, 3]), '/foo.txt')
    await fs.mkdir('/bar')

    await fs.cp('/foo.txt', '/bar')

    Copy a file from one place to another in your MFS.

    Example

    await fs.writeBytes(Uint8Array.from([0, 1, 2, 3]), '/foo.txt')

    await fs.cp('/foo.txt', '/bar.txt')
  • Update the mtime of a UnixFS DAG in your MFS.

    Parameters

    Returns Promise<void>

    Example

    await fs.writeBytes(Uint8Array.from([0, 1, 2, 3]), '/foo.txt')
    const beforeStats = await fs.stat('/foo.txt')

    await fs.touch('/foo.txt')
    const afterStats = await fs.stat(afterCid)

    console.info(beforeStats)
    console.info(afterStats)
  • Add a stream of Uint8Array to your MFS as a file.

    Parameters

    Returns Promise<void>

    Example

    import fs from 'node:fs'

    const stream = fs.createReadStream('./foo.txt')
    await fs.writeByteStream(stream, '/foo.txt')