UNPKG

@ipld/car

Version:

Content Addressable aRchive format reader and writer

116 lines 3.98 kB
/** * @typedef {import('multiformats').CID} CID * @typedef {import('./api').Block} Block * @typedef {import('./api').CarBufferReader} ICarBufferReader * @typedef {import('./coding').CarHeader} CarHeader * @typedef {import('./coding').CarV2Header} CarV2Header */ /** * Provides blockstore-like access to a CAR. * * Implements the `RootsBufferReader` interface: * {@link ICarBufferReader.getRoots `getRoots()`}. And the `BlockBufferReader` interface: * {@link ICarBufferReader.get `get()`}, {@link ICarBufferReader.has `has()`}, * {@link ICarBufferReader.blocks `blocks()`} and * {@link ICarBufferReader.cids `cids()`}. * * Load this class with either `import { CarBufferReader } from '@ipld/car/buffer-reader'` * (`const { CarBufferReader } = require('@ipld/car/buffer-reader')`). Or * `import { CarBufferReader } from '@ipld/car'` (`const { CarBufferReader } = require('@ipld/car')`). * The former will likely result in smaller bundle sizes where this is * important. * * @name CarBufferReader * @class * @implements {ICarBufferReader} * @property {number} version The version number of the CAR referenced by this * reader (should be `1` or `2`). */ export class CarBufferReader implements ICarBufferReader { /** * Instantiate a {@link CarBufferReader} from a `Uint8Array` blob. This performs a * decode fully in memory and maintains the decoded state in memory for full * access to the data via the `CarReader` API. * * @static * @memberof CarBufferReader * @param {Uint8Array} bytes * @returns {CarBufferReader} */ static fromBytes(bytes: Uint8Array): CarBufferReader; /** * @constructs CarBufferReader * @param {CarHeader|CarV2Header} header * @param {Block[]} blocks */ constructor(header: CarHeader | CarV2Header, blocks: Block[]); _header: import("./coding").CarHeader | import("./coding").CarV2Header; _blocks: import("./api").Block[]; _cids: import("multiformats").CID<unknown, number, number, import("multiformats").Version>[] | undefined; /** * @property version * @memberof CarBufferReader * @instance */ get version(): 1 | 2; /** * Get the list of roots defined by the CAR referenced by this reader. May be * zero or more `CID`s. * * @function * @memberof CarBufferReader * @instance * @returns {CID[]} */ getRoots(): CID[]; /** * Check whether a given `CID` exists within the CAR referenced by this * reader. * * @function * @memberof CarBufferReader * @instance * @param {CID} key * @returns {boolean} */ has(key: CID): boolean; /** * Fetch a `Block` (a `{ cid:CID, bytes:Uint8Array }` pair) from the CAR * referenced by this reader matching the provided `CID`. In the case where * the provided `CID` doesn't exist within the CAR, `undefined` will be * returned. * * @function * @memberof CarBufferReader * @instance * @param {CID} key * @returns {Block | undefined} */ get(key: CID): Block | undefined; /** * Returns a `Block[]` of the `Block`s (`{ cid:CID, bytes:Uint8Array }` pairs) contained within * the CAR referenced by this reader. * * @function * @memberof CarBufferReader * @instance * @returns {Block[]} */ blocks(): Block[]; /** * Returns a `CID[]` of the `CID`s contained within the CAR referenced by this reader. * * @function * @memberof CarBufferReader * @instance * @returns {CID[]} */ cids(): CID[]; } export const __browser: true; export type CID = import('multiformats').CID; export type Block = import('./api').Block; export type ICarBufferReader = import('./api').CarBufferReader; export type CarHeader = import('./coding').CarHeader; export type CarV2Header = import('./coding').CarV2Header; //# sourceMappingURL=buffer-reader-browser.d.ts.map