carstream
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

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

Readme

Keywords

Package Sidebar

Install

npm i carstream

Weekly Downloads

189

Version

2.0.0

License

Apache-2.0 OR MIT

Unpacked Size

27.1 kB

Total Files

19

Last publish

Collaborators

  • alanshaw