Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

Commit

Permalink
Merge pull request #314 from ipfs/fix/files-add-promises
Browse files Browse the repository at this point in the history
fix files.add promises
  • Loading branch information
daviddias authored Jul 2, 2016
2 parents db2315f + a4a9e3f commit 36519a2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"aegir": "^3.2.0",
"chai": "^3.5.0",
"gulp": "^3.9.1",
"interface-ipfs-core": "^0.3.0",
"interface-ipfs-core": "^0.4.3",
"ipfsd-ctl": "^0.14.0",
"pre-commit": "^1.1.2",
"stream-equal": "^0.1.8",
Expand Down Expand Up @@ -94,4 +94,4 @@
"url": "https://github.com/ipfs/js-ipfs-api/issues"
},
"homepage": "https://github.com/ipfs/js-ipfs-api"
}
}
16 changes: 6 additions & 10 deletions src/api/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,20 @@

const isStream = require('isstream')
const addToDagNodesTransform = require('../add-to-dagnode-transform')
const promisify = require('promisify-es6')

module.exports = (send) => {
return function add (files, opts, cb) {
if (typeof (opts) === 'function' && cb === undefined) {
cb = opts
opts = {}
}

return promisify((files, callback) => {
const good = Buffer.isBuffer(files) ||
isStream.isReadable(files) ||
Array.isArray(files)

if (!good) {
return cb(new Error('"files" must be a buffer, readable stream, or array of objects'))
callback(new Error('"files" must be a buffer, readable stream, or array of objects'))
}

var sendWithTransform = send.withTransform(addToDagNodesTransform)
const sendWithTransform = send.withTransform(addToDagNodesTransform)

return sendWithTransform('add', null, opts, files, cb)
}
sendWithTransform('add', null, {}, files, callback)
})
}

0 comments on commit 36519a2

Please # to comment.