Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit ccca6ce

Browse files
committed
fix: add support for resolving to the middle of an IPLD block
see: ipfs-inactive/interface-js-ipfs-core#385
1 parent 748fccf commit ccca6ce

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

src/core/components/resolve.js

+10-14
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,15 @@ module.exports = (self) => {
3434

3535
const path = split.slice(3).join('/')
3636

37-
resolve(cid, path, (err, cid) => {
37+
resolve(cid, path, (err, cid, remainder) => {
3838
if (err) return cb(err)
39-
if (!cid) return cb(new Error('found non-link at given path'))
40-
cb(null, `/ipfs/${cidToString(cid, { base: opts.cidBase })}`)
39+
cb(null, `/ipfs/${cidToString(cid, { base: opts.cidBase })}${!remainder ? '/' + remainder : ''}`)
4140
})
4241
})
4342

4443
// Resolve the given CID + path to a CID.
4544
function resolve (cid, path, callback) {
4645
let value
47-
4846
doUntil(
4947
(cb) => {
5048
self.block.get(cid, (err, block) => {
@@ -65,22 +63,20 @@ module.exports = (self) => {
6563
})
6664
},
6765
() => {
68-
const endReached = !path || path === '/'
69-
70-
if (endReached) {
71-
return true
72-
}
73-
74-
if (value) {
66+
if (value && value['/']) {
67+
// If we've hit a CID, replace the current CID.
7568
cid = new CID(value['/'])
69+
} else {
70+
// We've hit a value. Return the current CID and the remaining path.
71+
return false
7672
}
7773

78-
return false
74+
// Continue resolving unless the path is empty.
75+
return !path || path === '/'
7976
},
8077
(err) => {
8178
if (err) return callback(err)
82-
if (value && value['/']) return callback(null, new CID(value['/']))
83-
callback()
79+
callback(null, cid, path)
8480
}
8581
)
8682
}

0 commit comments

Comments
 (0)