The UnixFS interface provides familiar filesystem operations to make working with UnixFS DAGs simple and intuitive.

interface UnixFS {
    addAll(source, options?): AsyncIterable<ImportResult>;
    addByteStream(bytes, options?): Promise<CID<unknown, number, number, Version>>;
    addBytes(bytes, options?): Promise<CID<unknown, number, number, Version>>;
    addDirectory(dir?, options?): Promise<CID<unknown, number, number, Version>>;
    addFile(file, options?): Promise<CID<unknown, number, number, Version>>;
    cat(cid, options?): AsyncIterable<Uint8Array>;
    chmod(cid, mode, options?): Promise<CID<unknown, number, number, Version>>;
    cp(source, target, name, options?): Promise<CID<unknown, number, number, Version>>;
    ls(cid, options?): AsyncIterable<UnixFSEntry>;
    mkdir(cid, dirname, options?): Promise<CID<unknown, number, number, Version>>;
    rm(cid, path, options?): Promise<CID<unknown, number, number, Version>>;
    stat(cid, options?): Promise<UnixFSStats>;
    touch(cid, options?): Promise<CID<unknown, number, number, Version>>;
}

Methods

  • Add all files and directories from the passed stream. This method wraps the importer export from the ipfs-unixfs-importer module - please see the docs for input/output types.

    Parameters

    Returns AsyncIterable<ImportResult>

    Example

    const source = [{
    path: './foo.txt',
    content: Uint8Array.from([0, 1, 2, 3])
    }, {
    path: './bar.txt',
    content: Uint8Array.from([4, 5, 6, 7])
    }]

    for await (const entry of fs.import(source)) {
    console.info(entry)
    }
  • Change the permissions on a file or directory in a DAG

    Parameters

    Returns Promise<CID<unknown, number, number, Version>>

    Example

    const beforeCid = await fs.addBytes(Uint8Array.from([0, 1, 2, 3]))
    const beforeStats = await fs.stat(beforeCid)

    const afterCid = await fs.chmod(cid, 0x755)
    const afterStats = await fs.stat(afterCid)

    console.info(beforeCid, beforeStats)
    console.info(afterCid, afterStats)
  • Add a file or directory to a target directory.

    Parameters

    Returns Promise<CID<unknown, number, number, Version>>

    Example

    const fileCid = await fs.addBytes(Uint8Array.from([0, 1, 2, 3]))
    const directoryCid = await fs.addDirectory()

    const updatedCid = await fs.cp(fileCid, directoryCid, 'foo.txt')

    console.info(updatedCid)
  • Remove a file or directory from an existing directory.

    Parameters

    Returns Promise<CID<unknown, number, number, Version>>

    Example

    const directoryCid = await fs.addDirectory()
    const updatedCid = await fs.mkdir(directoryCid, 'new-dir')

    const finalCid = await fs.rm(updatedCid, 'new-dir')

    console.info(finalCid)
  • Update the mtime of a UnixFS DAG

    Parameters

    Returns Promise<CID<unknown, number, number, Version>>

    Example

    const beforeCid = await fs.addBytes(Uint8Array.from([0, 1, 2, 3]))
    const beforeStats = await fs.stat(beforeCid)

    const afterCid = await fs.touch(beforeCid)
    const afterStats = await fs.stat(afterCid)

    console.info(beforeCid, beforeStats)
    console.info(afterCid, afterStats)