interface Exportable<T> {
    cid: CID<unknown, number, number, Version>;
    depth: number;
    name: string;
    path: string;
    size: bigint;
    type: "object" | "file" | "directory" | "raw" | "identity";
    content(options?): AsyncGenerator<T, void, unknown>;
}

Type Parameters

  • T

Hierarchy (view full)

Properties

Methods

Properties

cid: CID<unknown, number, number, Version>

The CID of the entry

depth: number

How far down the DAG the entry is

name: string

The name of the entry

path: string

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

size: bigint

The size of the entry

type: "object" | "file" | "directory" | "raw" | "identity"

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

Example

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

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

Methods

  • Parameters

    Returns AsyncGenerator<T, void, unknown>

    Example: File content

    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

    Example: Directory content

    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