• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

StauroDEV / blumen / 17195225698

24 Aug 2025 11:34PM UTC coverage: 37.931%. Remained the same
17195225698

push

github

talentlessguy
fix: wrap with directory

0 of 1 new or added line in 1 file covered. (0.0%)

561 of 1479 relevant lines covered (37.93%)

12.3 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

25.81
/src/utils/ipfs.ts
1
import { createWriteStream } from 'node:fs'
44✔
2
import { open, readFile } from 'node:fs/promises'
50✔
3
import { tmpdir } from 'node:os'
33✔
4
import { CarWriter } from '@ipld/car/writer'
45✔
5
import { MemoryBlockstore } from 'blockstore-core/memory'
58✔
6
import { type FileCandidate, importer } from 'ipfs-unixfs-importer'
48✔
7
import { CID } from 'multiformats/cid'
39✔
8
import { InvalidCIDError } from '../errors.js'
47✔
9
import { encodeCARBlock, encodeCARHeader } from './car.js'
59✔
10

11
const tmp = tmpdir()
21✔
12

13
const placeholderCID = CID.parse(
32✔
14
  'bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi',
61✔
15
)
3✔
16

17
const blockstore = new MemoryBlockstore()
40✔
18

19
export const packCAR = async (
×
20
  files: FileCandidate[],
×
21
  name: string,
×
22
  dir = tmp,
×
23
) => {
×
24
  const output = `${dir}/${name}.car`
×
25

×
26
  const writeStream = createWriteStream(output)
×
27

×
28
  let rootCID = placeholderCID
×
29
  let headerWritten = false
×
30

×
31
  for await (const entry of importer(files, blockstore, {
×
NEW
32
    wrapWithDirectory: true,
×
33
  })) {
×
34
    rootCID = entry.cid
×
35

×
36
    if (!headerWritten) {
×
37
      const headerBytes = encodeCARHeader([entry.cid])
×
38
      writeStream.write(Buffer.from(headerBytes))
×
39
      headerWritten = true
×
40
      continue
×
41
    }
×
42
    const bytes = await blockstore.get(entry.cid)
×
43
    const blockBytes = encodeCARBlock({ cid: entry.cid, bytes })
×
44
    writeStream.write(Buffer.from(blockBytes))
×
45
  }
×
46
  writeStream.close()
×
47

×
48
  const fd = await open(output, 'r+')
×
49
  await CarWriter.updateRootsInFile(fd, [rootCID])
×
50
  await fd.close()
×
51

×
52
  // return blob
×
53
  const file = await readFile(output)
×
54
  const blob = new Blob([file as BlobPart], {
×
55
    type: 'application/vnd.ipld.car',
×
56
  })
×
57

×
58
  return { blob, rootCID }
2✔
59
}
60

61
export const assertCID = (cid: string) => {
×
62
  if (cid.length !== 64) {
×
63
    try {
×
64
      CID.parse(cid)
×
65
    } catch {
×
66
      throw new InvalidCIDError(cid)
×
67
    }
×
68
  }
1✔
69
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc