Interface Car

The Car interface provides operations for importing and exporting Car files from Helia's underlying blockstore.

interface Car {
    export(root, writer, options?): Promise<void>;
    import(reader, options?): Promise<void>;
    stream(root, options?): AsyncGenerator<Uint8Array, any, unknown>;
}

Methods

  • Store all blocks that make up one or more DAGs in a car file.

    Parameters

    Returns Promise<void>

    Example

    import fs from 'node:fs'
    import { Readable } from 'stream'
    import { createHelia } from 'helia'
    import { car } from '@helia/car
    import { CID } from 'multiformats/cid'
    import pEvent from 'p-event'

    const helia = await createHelia()
    const cid = CID.parse('QmFoo...')

    const c = car(helia)

    const byteStream = await c.export(cid)
    const output = fs.createWriteStream('example.car')
    const eventPromise = pEvent(output, 'end')
    Readable.from(byteStream).pipe(output)

    await eventPromise
  • Add all blocks in the passed CarReader to the blockstore.

    Parameters

    Returns Promise<void>

    Example

    import fs from 'node:fs'
    import { createHelia } from 'helia'
    import { car } from '@helia/car
    import { CarReader } from '@ipld/car'

    const helia = await createHelia()

    const inStream = fs.createReadStream('example.car')
    const reader = await CarReader.fromIterable(inStream)

    const c = car(helia)
    await c.import(reader)