1 | import fs from 'fs'
|
2 | import { CID, IPFS } from 'ipfs-core'
|
3 | import { CarBlockIterator } from '@ipld/car'
|
4 |
|
5 | export 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 |
|