UNPKG

@atcute/car

Version:

lightweight DASL CAR and atproto repository decoder for AT Protocol.

30 lines (29 loc) 1.32 kB
import * as CID from '@atcute/cid'; import * as CarReader from '../car-reader/index.js'; export type BlockMap = Map<string, CarReader.CarEntry>; /** * collects entries from a CAR archive into a mapping of CID string -> actual bytes * @param iterator a generator that yields objects with a `cid` and `bytes` property * @returns a mapping of CID string -> actual bytes */ export declare const collectBlock: (iterator: Iterable<CarReader.CarEntry>) => BlockMap; /** * reads a block from the blockmap and validates it against the provided validation function * @param map a mapping of CID string -> actual bytes * @param link a CID link to read * @param validate a validation function to validate the decoded data * @returns the decoded and validated data */ export declare const readBlock: <T>(map: BlockMap, link: CID.CidLink, validate: (value: unknown) => value is T) => T; /** node entry object */ export interface NodeEntry { key: string; cid: CID.CidLink; } /** * walks the entries of a Merkle Sorted Tree (MST) in a depth-first manner * @param map a mapping of CID string -> actual bytes * @param pointer a CID link to the root of the MST * @returns a generator that yields the entries of the MST */ export declare function walkMstEntries(map: BlockMap, pointer: CID.CidLink): Generator<NodeEntry>;