@atproto/repo
Version:
atproto repo and MST implementation
39 lines • 1.13 kB
JavaScript
import { MissingBlockError } from '../error.js';
import { parseObjByDef } from '../parse.js';
import { cborToLexRecord } from '../util.js';
export class ReadableBlockstore {
async attemptRead(cid, def) {
const bytes = await this.getBytes(cid);
if (!bytes)
return null;
return parseObjByDef(bytes, cid, def);
}
async readObjAndBytes(cid, def) {
const read = await this.attemptRead(cid, def);
if (!read) {
throw new MissingBlockError(cid, def.name);
}
return read;
}
async readObj(cid, def) {
const obj = await this.readObjAndBytes(cid, def);
return obj.obj;
}
async attemptReadRecord(cid) {
try {
return await this.readRecord(cid);
}
catch {
return null;
}
}
async readRecord(cid) {
const bytes = await this.getBytes(cid);
if (!bytes) {
throw new MissingBlockError(cid);
}
return cborToLexRecord(bytes);
}
}
export default ReadableBlockstore;
//# sourceMappingURL=readable-blockstore.js.map