Détail du package

carstream

alanshaw21.9kApache-2.0 OR MIT2.3.0

Web stream CAR reader and writer.

CAR, stream, web, CID

readme

carstream

Build JavaScript Style Guide npm bundle size

Web stream CAR reader and writer.

Install

npm install carstream

Usage

Read a CAR

import fs from 'node:fs'
import { Readable } from 'node:stream'
import { CARReaderStream } from 'carstream'

Readable.toWeb(fs.createReadStream('path/to/my.car'))
  .pipeThrough(new CARReaderStream())
  .pipeTo(new WritableStream({ write: block => console.log(block.cid.toString()) }))

Write a CAR

import fs from 'node:fs'
import { Writable } from 'node:stream'
import * as raw from 'multiformats/codecs/raw'
import { sha256 as hasher } from 'multiformats/hashes/sha2'
import * as Block from 'multiformats/block'
import { CARWriterStream } from 'carstream'

const readable = new ReadableStream({
  async pull (controller) {
    const block = await Block.encode({ value: new Uint8Array(), codec: raw, hasher })
    controller.enqueue(block)
    controller.close()
  }
})

await readable
  .pipeThrough(new CARWriterStream())
  .pipeTo(Writable.toWeb(fs.createWriteStream('path/to/my.car')))

Contributing

Feel free to join in. All welcome. Open an issue!

License

Dual-licensed under MIT / Apache 2.0