Store all blocks that make up one or more DAGs in a car file.
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.
Optional
options: AbortOptions & ProgressOptions<PutManyBlocksProgressEvents>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)
Returns an AsyncGenerator that yields CAR file bytes.
Optional
options: AbortOptions & ProgressOptions<GetBlockProgressEvents>import { createHelia } from 'helia'
import { car } from '@helia/car
import { CID } from 'multiformats/cid'
const helia = await createHelia()
const cid = CID.parse('QmFoo...')
const c = car(helia)
for (const buf of c.stream(cid)) {
// store or send `buf` somewhere
}
The Car interface provides operations for importing and exporting Car files from Helia's underlying blockstore.