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

Commit

Permalink
Improve input checking on "add".
Browse files Browse the repository at this point in the history
  • Loading branch information
hackergrrl committed May 24, 2016
1 parent 29c2c83 commit 7835215
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"flatmap": "0.0.3",
"glob": "^7.0.3",
"ipfs-merkle-dag": "^0.6.0",
"isstream": "^0.1.2",
"multiaddr": "^2.0.0",
"multipart-stream": "^2.0.1",
"ndjson": "^1.4.3",
Expand Down
9 changes: 9 additions & 0 deletions src/api/add.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict'

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

Expand All @@ -10,6 +11,14 @@ module.exports = (send) => {
opts = {}
}

var 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'))
}

var sendWithTransform = send.withTransform(addToDagNodesTransform)

return sendWithTransform('add', null, opts, files, cb)
Expand Down

0 comments on commit 7835215

Please sign in to comment.