Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/webtorrent/webtorrent.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFeross Aboukhadijeh <feross@feross.org>2016-02-10 09:05:01 +0300
committerFeross Aboukhadijeh <feross@feross.org>2016-02-10 09:44:08 +0300
commitacebfcf38ea2d7a17286522d9ed71d751f88bee5 (patch)
treeb589e27f6903f150f706625f1fd12634765c59df /index.js
parentf251050f6cb96f622c390b7ebc49ca007ed8c0e1 (diff)
client.seed: fix stream input type
convert streams to buffer, since we need to consume the stream twice.
Diffstat (limited to 'index.js')
-rw-r--r--index.js47
1 files changed, 33 insertions, 14 deletions
diff --git a/index.js b/index.js
index 3b8694a..8a02678 100644
--- a/index.js
+++ b/index.js
@@ -15,6 +15,7 @@ var Peer = require('simple-peer')
var speedometer = require('speedometer')
var zeroFill = require('zero-fill')
+var concatStream = require('./lib/concat-stream')
var Torrent = require('./lib/torrent')
module.exports.WEBRTC_SUPPORT = Peer.WEBRTC_SUPPORT
@@ -237,22 +238,31 @@ WebTorrent.prototype.seed = function (input, opts, onseed) {
})
})
- createTorrent.parseInput(input, opts, function (err, files) {
+ if (!Array.isArray(input)) input = [ input ]
+ parallel(input.map(function (item) {
+ return function (cb) {
+ if (isReadable(item)) concatStream(item, cb)
+ else cb(null, item)
+ }
+ }), function (err, input) {
if (err) return self.emit('error', err)
- streams = files.map(function (file) { return file.getStream })
-
- createTorrent(input, opts, function (err, torrentBuf) {
+ createTorrent.parseInput(input, opts, function (err, files) {
if (err) return self.emit('error', err)
- if (self.destroyed) return
-
- var existingTorrent = self.get(torrentBuf)
- if (existingTorrent) {
- torrent.destroy()
- _onseed()
- return
- } else {
- torrent._onTorrentId(torrentBuf)
- }
+ streams = files.map(function (file) { return file.getStream })
+
+ createTorrent(input, opts, function (err, torrentBuf) {
+ if (err) return self.emit('error', err)
+ if (self.destroyed) return
+
+ var existingTorrent = self.get(torrentBuf)
+ if (existingTorrent) {
+ torrent.destroy()
+ _onseed()
+ return
+ } else {
+ torrent._onTorrentId(torrentBuf)
+ }
+ })
})
})
@@ -303,3 +313,12 @@ WebTorrent.prototype.destroy = function (cb) {
parallel(tasks, cb)
}
+
+/**
+ * Check if `obj` is a node Readable stream
+ * @param {*} obj
+ * @return {boolean}
+ */
+function isReadable (obj) {
+ return typeof obj === 'object' && obj != null && typeof obj.pipe === 'function'
+}