@ atcute/ repo
改为 AT 协议寄存器导出.
npm install @atcute/repo
AT 协议将用户数据存储在存储库 -- -- 包含记录的默克勒树结构
以收集方式进行。 此软件包读取仓库 CAR 导出( 从 com.atproto.sync.getRepo 或账户
并且对记录进行重复.
使用量
流式使用量
[注]
PDS 执行,包括参考PDS, 可能不会按有效顺序发出块 由 同步 v1.1流体读取器通过内部缓冲来补偿,所以 内存使用率可能高于预期.当响应事项( 如想要显示的 web app) 时, 流化仍然有用 记录他们到达时 而不是等待整个CAR装载.
此库打算在Sync v1.1完成后执行高效的块命令 .
import { fromStream } from '@atcute/repo';
const stream = new ReadableStream({/* ... */});
await using repo = fromStream(stream);
for await (const entry of repo) {
entry;
// ^? RepoEntry { collection: 'app.bsky.feed.post', rkey: '3lprcc55bb222', ... }
}
repo.missingBlocks;
// ^? []
流媒体使用量(无运行时间) await using 还没有)
const repo = fromStream(stream);
try {
for await (const entry of repo) {
entry;
// ^? RepoEntry
}
} finally {
await repo.dispose();
}
同步使用
const buffer = Uint8Array.from([/* ... */]);
const repo = fromUint8Array(buffer);
for (const entry of repo) {
entry;
// ^? RepoEntry { collection: 'app.bsky.feed.post', rkey: '3lprcc55bb222', ... }
}
repo.missingBlocks;
// ^? []
核查记录
验证记录是否包含在可选的签名验证库中:
import { verifyRecord } from '@atcute/repo';
const { cid, record } = await verifyRecord({
collection: 'app.bsky.feed.post',
rkey: '3lprcc55bb222',
carBytes: carBytes,
// optional: verify commit signature
publicKey: key,
// optional: verify DID matches
did: 'did:plc:...',
});
转换流
通过变换管道寄存器数据:
import { repoEntryTransform } from '@atcute/repo';
const { readable, writable } = repoEntryTransform();
// pipe CAR data in, get RepoEntry objects out
response.body.pipeTo(writable);
for await (const entry of readable) {
console.log(entry.collection, entry.rkey);
}