@atcute/car
Version:
lightweight DASL CAR (content-addressable archives) codec for AT Protocol.
82 lines (58 loc) • 1.36 kB
Markdown
content-addressable archive (CAR) codec for AT Protocol.
```sh
npm install @atcute/car
```
this library implements DASL's [CAR][dasl-car] format used by AT Protocol to store and transfer
repository data.
[dasl-car]: https://dasl.ing/car.html
## usage
### streaming usage
```ts
import { fromStream } from '@atcute/car';
const stream = new ReadableStream({
/* ... */
});
await using car = fromStream(stream);
const roots = await car.roots();
for await (const entry of car) {
entry;
// ^? CarEntry { cid: CidLink {}, bytes: Uint8Array {}, ... }
}
```
```ts
const car = fromStream(stream);
try {
for await (const entry of car) {
entry;
// ^? CarEntry { ... }
}
} finally {
await car.dispose();
}
```
```ts
const buffer = Uint8Array.from([
/* ... */
]);
// read generic CAR archives
const car = fromUint8Array(buffer);
const roots = car.roots;
for (const entry of car) {
entry;
// ^? CarEntry { cid: CidLink {}, bytes: Uint8Array {}, ... }
}
```
```ts
import { writeCarStream } from '@atcute/car';
const blocks = async function* () {
yield { cid: commitCid.bytes, data: commitBytes };
yield { cid: nodeCid.bytes, data: nodeBytes };
};
for await (const chunk of writeCarStream([rootCid], blocks())) {
stream.write(chunk);
}
```