Store all blocks that make up one or more DAGs in a car file.
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')
])
Use stream
instead. In a future release stream
will be renamed export
.
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.