UNPKG

@ipld/car

Version:

Content Addressable aRchive format reader and writer

87 lines 3.51 kB
/** * @typedef {import('./api').Block} Block * @typedef {import('./api').BlockHeader} BlockHeader * @typedef {import('./api').BlockIndex} BlockIndex * @typedef {import('./coding').BytesReader} BytesReader * @typedef {import('./coding').CarHeader} CarHeader * @typedef {import('./coding').CarV2Header} CarV2Header * @typedef {import('./coding').CarV2FixedHeader} CarV2FixedHeader * @typedef {import('./coding').CarDecoder} CarDecoder */ /** * Reads header data from a `BytesReader`. The header may either be in the form * of a `CarHeader` or `CarV2Header` depending on the CAR being read. * * @name async decoder.readHeader(reader) * @param {BytesReader} reader * @param {number} [strictVersion] * @returns {Promise<CarHeader|CarV2Header>} */ export function readHeader(reader: BytesReader, strictVersion?: number | undefined): Promise<CarHeader | CarV2Header>; /** * Reads the leading data of an individual block from CAR data from a * `BytesReader`. Returns a `BlockHeader` object which contains * `{ cid, length, blockLength }` which can be used to either index the block * or read the block binary data. * * @name async decoder.readBlockHead(reader) * @param {BytesReader} reader * @returns {Promise<BlockHeader>} */ export function readBlockHead(reader: BytesReader): Promise<BlockHeader>; /** * Creates a `CarDecoder` from a `BytesReader`. The `CarDecoder` is as async * interface that will consume the bytes from the `BytesReader` to yield a * `header()` and either `blocks()` or `blocksIndex()` data. * * @name decoder.createDecoder(reader) * @param {BytesReader} reader * @returns {CarDecoder} */ export function createDecoder(reader: BytesReader): CarDecoder; /** * Creates a `BytesReader` from a `Uint8Array`. * * @name decoder.bytesReader(bytes) * @param {Uint8Array} bytes * @returns {BytesReader} */ export function bytesReader(bytes: Uint8Array): BytesReader; /** * @ignore * reusable reader for streams and files, we just need a way to read an * additional chunk (of some undetermined size) and a way to close the * reader when finished * @param {() => Promise<Uint8Array|null>} readChunk * @returns {BytesReader} */ export function chunkReader(readChunk: () => Promise<Uint8Array | null>): BytesReader; /** * Creates a `BytesReader` from an `AsyncIterable<Uint8Array>`, which allows for * consumption of CAR data from a streaming source. * * @name decoder.asyncIterableReader(asyncIterable) * @param {AsyncIterable<Uint8Array>} asyncIterable * @returns {BytesReader} */ export function asyncIterableReader(asyncIterable: AsyncIterable<Uint8Array>): BytesReader; /** * Wraps a `BytesReader` in a limiting `BytesReader` which limits maximum read * to `byteLimit` bytes. It _does not_ update `pos` of the original * `BytesReader`. * * @name decoder.limitReader(reader, byteLimit) * @param {BytesReader} reader * @param {number} byteLimit * @returns {BytesReader} */ export function limitReader(reader: BytesReader, byteLimit: number): BytesReader; export type Block = import('./api').Block; export type BlockHeader = import('./api').BlockHeader; export type BlockIndex = import('./api').BlockIndex; export type BytesReader = import('./coding').BytesReader; export type CarHeader = import('./coding').CarHeader; export type CarV2Header = import('./coding').CarV2Header; export type CarV2FixedHeader = import('./coding').CarV2FixedHeader; export type CarDecoder = import('./coding').CarDecoder; //# sourceMappingURL=decoder.d.ts.map