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

Commit

Permalink
feat: attach mfs through proxy object to avoid circular dep
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddias authored and Alan Shaw committed Nov 19, 2018
1 parent 5a2973e commit e0f63bf
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 35 deletions.
67 changes: 33 additions & 34 deletions src/core/components/files-mfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,37 @@
const promisify = require('promisify-es6')
const mfs = require('ipfs-mfs/core')

module.exports = self => {
const mfsSelf = Object.assign({}, self)

// A patched dag API to ensure preload doesn't happen for MFS operations
// (MFS is preloaded periodically)
mfsSelf.dag = Object.assign({}, self.dag, {
get: promisify((cid, path, opts, cb) => {
if (typeof path === 'function') {
cb = path
path = undefined
}

if (typeof opts === 'function') {
cb = opts
opts = {}
}

opts = Object.assign({}, opts, { preload: false })

return self.dag.get(cid, path, opts, cb)
}),
put: promisify((node, opts, cb) => {
if (typeof opts === 'function') {
cb = opts
opts = {}
}

opts = Object.assign({}, opts, { preload: false })

return self.dag.put(node, opts, cb)
})
})

return mfs(mfsSelf, mfsSelf._options)
module.exports = (self) => {
const proxy = {
add: self.add,
dag: {
get: promisify((cid, path, opts, cb) => {
if (typeof path === 'function') {
cb = path
path = undefined
}

if (typeof opts === 'function') {
cb = opts
opts = {}
}

opts = Object.assign({}, opts, { preload: false })

return self.dag.get(cid, path, opts, cb)
}),
put: promisify((node, opts, cb) => {
if (typeof opts === 'function') {
cb = opts
opts = {}
}

opts = Object.assign({}, opts, { preload: false })

return self.dag.put(node, opts, cb)
})
}
}

return mfs(proxy, self._options)
}
2 changes: 1 addition & 1 deletion test/core/files.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const pull = require('pull-stream')
const IPFSFactory = require('ipfsd-ctl')
const IPFS = require('../../src/core')

describe('files', () => {
describe.only('files', () => {
let ipfsd, ipfs

before(function (done) {
Expand Down

0 comments on commit e0f63bf

Please sign in to comment.