js-ipfs-unixfs
    Preparing search index...

    Interface UnixFSDirectory

    If the entry is a directory, entry.content() returns further entry objects:

    if (entry.type === 'directory') {
    for await (const entry of dir.content()) {
    console.info(entry.name)
    }
    }
    interface UnixFSDirectory {
        cid: CID;
        depth: number;
        name: string;
        node: PBNode;
        path: string;
        size: bigint;
        type: "directory";
        unixfs: UnixFS;
        content(
            options?: ExporterOptions,
        ): AsyncGenerator<UnixFSEntry, void, unknown>;
    }

    Hierarchy (View Summary)

    Index

    Properties

    cid: CID

    The CID of the entry

    depth: number

    How far down the DAG the entry is

    name: string

    The name of the entry

    node: PBNode
    path: string

    The path of the entry within the DAG in which it was encountered

    size: bigint

    The size of the entry

    type: "directory"

    A disambiguator to allow TypeScript to work out the type of the entry.

    if (entry.type === 'file') {
    // access UnixFSFile properties safely
    }

    if (entry.type === 'directory') {
    // access UnixFSDirectory properties safely
    }
    unixfs: UnixFS

    Methods

    • Parameters

      Returns AsyncGenerator<UnixFSEntry, void, unknown>

      When entry is a file or a raw node, offset and/or length arguments can be passed to entry.content() to return slices of data:

      const length = 5
      const data = new Uint8Array(length)
      let offset = 0

      for await (const chunk of entry.content({
      offset: 0,
      length
      })) {
      data.set(chunk, offset)
      offset += chunk.length
      }

      // `data` contains the first 5 bytes of the file
      return data

      If entry is a directory, passing offset and/or length to entry.content() will limit the number of files returned from the directory.

      const entries = []

      for await (const entry of dir.content({
      offset: 0,
      length: 5
      })) {
      entries.push(entry)
      }

      // `entries` contains the first 5 files/directories in the directory