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 'node:stream'
    import { car } from '@helia/car'
    import { CarWriter } from '@ipld/car'
    import { createHelia } from 'helia'
    import { CID } from 'multiformats/cid'
    import { pEvent } from 'p-event'

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

    const c = car(helia)
    const { writer, out } = CarWriter.create(cid)
    const output = fs.createWriteStream('example.car')
    const stream = Readable.from(out).pipe(output)

    await Promise.all([
    c.export(cid, writer),
    pEvent(stream, 'close')
    ])

    Deprecated

    Use stream instead. In a future release stream will be renamed export.

  • 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)