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

Commit

Permalink
fix(files.add): error on invalid input (#782)
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddias committed Mar 9, 2017
1 parent fe71013 commit c851ca0
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/core/components/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const unixfsEngine = require('ipfs-unixfs-engine')
const importer = unixfsEngine.importer
const exporter = unixfsEngine.exporter
const UnixFS = require('ipfs-unixfs')
const isStream = require('isstream')
const promisify = require('promisify-es6')
const multihashes = require('multihashes')
const pull = require('pull-stream')
Expand All @@ -13,6 +12,7 @@ const toStream = require('pull-stream-to-stream')
const toPull = require('stream-to-pull-stream')
const CID = require('cids')
const waterfall = require('async/waterfall')
const isStream = require('isstream')

module.exports = function files (self) {
const createAddPullStream = (options) => {
Expand Down Expand Up @@ -43,6 +43,12 @@ module.exports = function files (self) {
callback = noop
}

if (typeof data !== 'object' &&
!Buffer.isBuffer(data) &&
!isStream(data)) {
return callback(new Error('Invalid arguments, data must be an object, Buffer or readable stream'))
}

pull(
pull.values(normalizeContent(data)),
importer(self._ipldResolver, options),
Expand Down

0 comments on commit c851ca0

Please sign in to comment.