Entries with a identity codec CID return identity entries.

These are entries where the data payload is stored in the CID itself, otherwise they are identical to RawNodes.

interface IdentityNode {
    cid: CID<unknown, number, number, Version>;
    depth: number;
    name: string;
    node: Uint8Array;
    path: string;
    size: bigint;
    type: "identity";
    content(options?): AsyncGenerator<Uint8Array, void, unknown>;
}

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: "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<Uint8Array, 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