lecarfy
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 lecarfyUsage
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

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.
