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

Commit c851ca0

Browse files
authored
fix(files.add): error on invalid input (#782)
1 parent fe71013 commit c851ca0

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/core/components/files.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const unixfsEngine = require('ipfs-unixfs-engine')
44
const importer = unixfsEngine.importer
55
const exporter = unixfsEngine.exporter
66
const UnixFS = require('ipfs-unixfs')
7-
const isStream = require('isstream')
87
const promisify = require('promisify-es6')
98
const multihashes = require('multihashes')
109
const pull = require('pull-stream')
@@ -13,6 +12,7 @@ const toStream = require('pull-stream-to-stream')
1312
const toPull = require('stream-to-pull-stream')
1413
const CID = require('cids')
1514
const waterfall = require('async/waterfall')
15+
const isStream = require('isstream')
1616

1717
module.exports = function files (self) {
1818
const createAddPullStream = (options) => {
@@ -43,6 +43,12 @@ module.exports = function files (self) {
4343
callback = noop
4444
}
4545

46+
if (typeof data !== 'object' &&
47+
!Buffer.isBuffer(data) &&
48+
!isStream(data)) {
49+
return callback(new Error('Invalid arguments, data must be an object, Buffer or readable stream'))
50+
}
51+
4652
pull(
4753
pull.values(normalizeContent(data)),
4854
importer(self._ipldResolver, options),

0 commit comments

Comments
 (0)