diff options
author | Feross Aboukhadijeh <feross@feross.org> | 2016-07-27 08:44:21 +0300 |
---|---|---|
committer | Feross Aboukhadijeh <feross@feross.org> | 2016-07-27 08:44:21 +0300 |
commit | af0189ff2183ad04d35e6ec89de83d498e8719fa (patch) | |
tree | 28afbf0f7609c5fb8896e34cbafc76b16c71ab55 /index.js | |
parent | 6fd258d171cf7f12587687cf887c2fdc1ca24190 (diff) |
Fix support for FileList input to client.seed()
Fixes #848
Diffstat (limited to 'index.js')
-rw-r--r-- | index.js | 13 |
1 files changed, 13 insertions, 0 deletions
@@ -1,3 +1,5 @@ +/* global FileList */ + module.exports = WebTorrent var Buffer = require('safe-buffer').Buffer @@ -300,7 +302,9 @@ WebTorrent.prototype.seed = function (input, opts, onseed) { var torrent = self.add(null, opts, onTorrent) var streams + if (isFileList(input)) input = Array.prototype.slice.call(input) if (!Array.isArray(input)) input = [ input ] + parallel(input.map(function (item) { return function (cb) { if (isReadable(item)) concat(item, cb) @@ -448,3 +452,12 @@ WebTorrent.prototype._onListening = function () { function isReadable (obj) { return typeof obj === 'object' && obj != null && typeof obj.pipe === 'function' } + +/** + * Check if `obj` is a W3C `FileList` object + * @param {*} obj + * @return {boolean} + */ +function isFileList (obj) { + return typeof FileList !== 'undefined' && obj instanceof FileList +} |