6.1.0 • Published 13h ago
@atcute/car
Licence
0BSD
Version
6.1.0
Deps
4
Size
23 kB
Vulns
0
Weekly
0
Stars
519
@atcute/car
content-addressable archive (CAR) codec for AT Protocol.
npm install @atcute/car
this library implements DASL's CAR format used by AT Protocol to store and transfer repository data.
usage
streaming usage
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 {}, ... }
}
streaming usage (for runtimes without await using yet)
const car = fromStream(stream);
try {
for await (const entry of car) {
entry;
// ^? CarEntry { ... }
}
} finally {
await car.dispose();
}
sync usage
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 {}, ... }
}
writing
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);
}