-19
src/pds.js
-19
src/pds.js
···
982
982
return blocks
983
983
}
984
984
985
-
// Build CAR-style block bytes (without header, just block entries)
986
-
buildBlocksBytes(blocks) {
987
-
const parts = []
988
-
for (const block of blocks) {
989
-
const cidBytes = block.cid instanceof Uint8Array ? block.cid : cidToBytes(block.cid)
990
-
const blockLen = cidBytes.length + block.data.length
991
-
// Varint encode the length
992
-
let len = blockLen
993
-
while (len >= 0x80) {
994
-
parts.push((len & 0x7f) | 0x80)
995
-
len >>= 7
996
-
}
997
-
parts.push(len)
998
-
parts.push(...cidBytes)
999
-
parts.push(...block.data)
1000
-
}
1001
-
return new Uint8Array(parts)
1002
-
}
1003
-
1004
985
async createRecord(collection, record, rkey = null) {
1005
986
const did = await this.getDid()
1006
987
if (!did) throw new Error('PDS not initialized')