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-------+
| |
+---2---+ +---9---+
| | | |
+-3-+ +-6-+ +-a-+ +-d-+
| | | | | | | |
4 5 7 8 b c e f
This library will create a CAR with blocks arranged in the following order:
4,5,7,8,b,c,e,f,r,1,2,9
When the root block (r) is encountered there are no more leaves in the DAG.
npm install lecarfy
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
}
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
.
The included IPLD decoders are dag-pb
, dag-json
and raw
. Push onto this array to add decoders.
Feel free to dive in! Open an issue or submit PRs.
Dual-licensed under MIT + Apache 2.0