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

Commit e0f63bf

Browse files
daviddiasAlan Shaw
authored and
Alan Shaw
committed
feat: attach mfs through proxy object to avoid circular dep
1 parent 5a2973e commit e0f63bf

File tree

2 files changed

+34
-35
lines changed

2 files changed

+34
-35
lines changed

src/core/components/files-mfs.js

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,37 @@
33
const promisify = require('promisify-es6')
44
const mfs = require('ipfs-mfs/core')
55

6-
module.exports = self => {
7-
const mfsSelf = Object.assign({}, self)
8-
9-
// A patched dag API to ensure preload doesn't happen for MFS operations
10-
// (MFS is preloaded periodically)
11-
mfsSelf.dag = Object.assign({}, self.dag, {
12-
get: promisify((cid, path, opts, cb) => {
13-
if (typeof path === 'function') {
14-
cb = path
15-
path = undefined
16-
}
17-
18-
if (typeof opts === 'function') {
19-
cb = opts
20-
opts = {}
21-
}
22-
23-
opts = Object.assign({}, opts, { preload: false })
24-
25-
return self.dag.get(cid, path, opts, cb)
26-
}),
27-
put: promisify((node, opts, cb) => {
28-
if (typeof opts === 'function') {
29-
cb = opts
30-
opts = {}
31-
}
32-
33-
opts = Object.assign({}, opts, { preload: false })
34-
35-
return self.dag.put(node, opts, cb)
36-
})
37-
})
38-
39-
return mfs(mfsSelf, mfsSelf._options)
6+
module.exports = (self) => {
7+
const proxy = {
8+
add: self.add,
9+
dag: {
10+
get: promisify((cid, path, opts, cb) => {
11+
if (typeof path === 'function') {
12+
cb = path
13+
path = undefined
14+
}
15+
16+
if (typeof opts === 'function') {
17+
cb = opts
18+
opts = {}
19+
}
20+
21+
opts = Object.assign({}, opts, { preload: false })
22+
23+
return self.dag.get(cid, path, opts, cb)
24+
}),
25+
put: promisify((node, opts, cb) => {
26+
if (typeof opts === 'function') {
27+
cb = opts
28+
opts = {}
29+
}
30+
31+
opts = Object.assign({}, opts, { preload: false })
32+
33+
return self.dag.put(node, opts, cb)
34+
})
35+
}
36+
}
37+
38+
return mfs(proxy, self._options)
4039
}

test/core/files.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const pull = require('pull-stream')
1111
const IPFSFactory = require('ipfsd-ctl')
1212
const IPFS = require('../../src/core')
1313

14-
describe('files', () => {
14+
describe.only('files', () => {
1515
let ipfsd, ipfs
1616

1717
before(function (done) {

0 commit comments

Comments
 (0)