forked from ipfs/js-ipfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresolve.js
36 lines (29 loc) · 799 Bytes
/
resolve.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
'use strict'
const CID = require('cids')
const { parseArgs } = require('./utils')
const { withTimeoutOption } = require('../../utils')
module.exports = ({ ipld, preload }) => {
return withTimeoutOption(async function resolve (cid, path, options) {
[cid, path, options] = parseArgs(cid, path, options)
if (options.preload !== false) {
preload(cid)
}
let lastCid = cid
let lastRemainderPath = path
if (path) {
for await (const { value, remainderPath } of ipld.resolve(cid, path, {
signal: options.signal
})) {
if (!CID.isCID(value)) {
break
}
lastRemainderPath = remainderPath
lastCid = value
}
}
return {
value: lastCid,
remainderPath: lastRemainderPath || ''
}
})
}