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

fix files.add promises #314

Merged
merged 1 commit into from
Jul 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
})
}