UNPKG

416 BPlain TextView Raw
1import fs from 'fs'
2import { CID, IPFS } from 'ipfs-core'
3import { CarBlockIterator } from '@ipld/car'
4
5export async function loadCAR(filepath: string, ipfs: IPFS): Promise<CID[]> {
6 const inStream = fs.createReadStream(filepath)
7 const cids = []
8 for await (const { cid, bytes } of await CarBlockIterator.fromIterable(inStream)) {
9 cids.push(cid)
10 await ipfs.block.put(bytes, { cid })
11 }
12 return cids
13}
14