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

Commit f7d8f63

Browse files
StebalienAlan Shaw
authored and
Alan Shaw
committed
fix: add support for resolving to the middle of an IPLD block
see: ipfs-inactive/interface-js-ipfs-core#385
1 parent fc08243 commit f7d8f63

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

src/core/components/resolve.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ module.exports = (self) => {
4444
// Resolve the given CID + path to a CID.
4545
function resolve (cid, path, callback) {
4646
let value, remainderPath
47+
4748
doUntil(
4849
(cb) => {
4950
self.block.get(cid, (err, block) => {

test/core/resolve.spec.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/* eslint max-nested-callbacks: ["error", 8] */
2+
/* eslint-env mocha */
3+
'use strict'
4+
5+
const chai = require('chai')
6+
const dirtyChai = require('dirty-chai')
7+
const expect = chai.expect
8+
chai.use(dirtyChai)
9+
10+
const IPFSFactory = require('ipfsd-ctl')
11+
const IPFS = require('../../src/core')
12+
13+
describe('resolve', () => {
14+
let ipfsd, ipfs
15+
16+
before(function (done) {
17+
this.timeout(20 * 1000)
18+
19+
const factory = IPFSFactory.create({ type: 'proc' })
20+
21+
factory.spawn({
22+
exec: IPFS,
23+
initOptions: { bits: 512 },
24+
config: { Bootstrap: [] }
25+
}, (err, _ipfsd) => {
26+
expect(err).to.not.exist()
27+
ipfsd = _ipfsd
28+
ipfs = _ipfsd.api
29+
done()
30+
})
31+
})
32+
33+
after((done) => {
34+
if (ipfsd) {
35+
ipfsd.stop(done)
36+
} else {
37+
done()
38+
}
39+
})
40+
41+
it('should resolve an IPFS path non-link', (done) => {
42+
const content = { path: { to: { file: 'foobar' } } }
43+
const options = { format: 'dag-cbor', hashAlg: 'sha2-256' }
44+
45+
ipfs.dag.put(content, options, (err, cid) => {
46+
expect(err).to.not.exist()
47+
48+
// FIXME: This should be /ipld/... but that's not supported yet.
49+
const path = `/ipfs/${cid.toBaseEncodedString()}/path/to/file`
50+
ipfs.resolve(path, (err, resolved) => {
51+
expect(err).to.not.exist()
52+
expect(resolved).to.equal(path)
53+
done()
54+
})
55+
})
56+
})
57+
})

0 commit comments

Comments
 (0)