Skip to content

Commit

Permalink
fix: list links of a block that _is a_ CID (#226)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Shaw authored Jan 2, 2023
1 parent df7a276 commit c17673d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ function * links (source, base) {
if (source == null || source instanceof Uint8Array) {
return
}
const cid = CID.asCID(source)
if (cid) {
yield [base.join('/'), cid]
}
for (const [key, value] of Object.entries(source)) {
const path = /** @type {[string|number, string]} */ ([...base, key])
yield * linksWithin(path, value)
Expand Down
11 changes: 11 additions & 0 deletions test/test-block.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,17 @@ describe('block', () => {
})
})

it('links of a block that is a CID', async () => {
const block = await main.encode({ value: link, codec, hasher })
const links = []
for (const link of block.links()) {
links.push(link)
}
assert.equal(links.length, 1)
assert.equal(links[0][0], '')
assert.equal(links[0][1].toString(), link.toString())
})

it('kitchen sink', () => {
const sink = { one: { two: { arr: [true, false, null], three: 3, buff, link } } }
const block = main.createUnsafe({
Expand Down

0 comments on commit c17673d

Please sign in to comment.