The Wayback Machine - https://web.archive.org/web/20220915111354/https://github.com/alanshaw/lecarfy
Skip to content

alanshaw/lecarfy

main
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

lecarfy

Build JavaScript Style Guide npm bundle size

A CAR file creator/formatter that creates CAR files with leaf blocks appearing first, in depth first traversal order.

Given the following DAG:

      +-------R-------+
      |               |
  +---1---+       +---8---+
  |       |       |       |
+-2-+   +-5-+   +-9-+   +-c-+
|   |   |   |   |   |   |   |
3   4   6   7   a   b   d   e

This library will create a CAR with blocks arranged in the following order:

3,4,6,7,a,b,d,e,R,1,2,5,8,9,c

When the root block (R) is encountered there are no more leaves in the DAG.

Install

npm install lecarfy

Usage

import { format } from 'lecarfy'
import { CarReader } from '@ipld/car'

const car = await CarReader.fromBytes(/* ...CAR file bytes... */)
const [rootCid] = await car.getRoots()

const formattedCar = format(rootCid, car)

for await (const bytes of formattedCar) {
  // bytes is a Uint8Array
}

API

format (root: CID, blocks: BlockGetter): AsyncIterable<Uint8Array>

Format the passed DAG rooted by the passed CID in the lecarfy style. The blocks parameter is an object that implements a method get (key: CID): Promise<Block | undefined> so does not have to be a CarReader.

decoders: BlockDecoder<any, any>[]

The included IPLD decoders are dag-pb, dag-json and raw. Push onto this array to add decoders.

Contribute

Feel free to dive in! Open an issue or submit PRs.

License

Dual-licensed under MIT + Apache 2.0

About

A CAR file creator/formatter that creates CAR files with leaf blocks appearing first, in depth first traversal order.

Resources

License

Stars

Watchers

Forks

Packages

No packages published