@ tcute/ car( 车)
aT 协议的可处理档案(CAR)编码器.
npm install @atcute/car
此库执行 DASL 的 中非共和国 aT 协议用于存储和转让的格式 仓库数据.
使用量
流式使用量
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 {}, ... }
}
流媒体使用量(无运行时间) await using 还没有)
const car = fromStream(stream);
try {
for await (const entry of car) {
entry;
// ^? CarEntry { ... }
}
} finally {
await car.dispose();
}
同步使用
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 {}, ... }
}
写作
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);
}