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>2015-01-05 08:48:23 +0300
committerFeross Aboukhadijeh <feross@feross.org>2015-01-05 08:56:05 +0300
commitffcd84f07bd161ac424e682a683b09d376eff331 (patch)
tree0005a1023cf720e98373b22aba57faa0800871f7
parent5ab99cc2c2de446f3ddc39e47a20d5ca01ba99e5 (diff)
client.seed: skip piece verification for performance
For https://github.com/feross/webtorrent/issues/235
-rw-r--r--index.js5
-rw-r--r--lib/storage.js8
2 files changed, 9 insertions, 4 deletions
diff --git a/index.js b/index.js
index 0d83b7b..f6d98a8 100644
--- a/index.js
+++ b/index.js
@@ -149,7 +149,8 @@ WebTorrent.prototype.download = function (torrentId, opts, ontorrent) {
opts.client = self
opts.storage = opts.storage || self.storage
- if (opts.tmp) opts.storageOpts = { tmp: opts.tmp }
+ if (!opts.storageOpts) opts.storageOpts = {}
+ if (opts.tmp) opts.storageOpts.tmp = opts.tmp
var torrent = new Torrent(torrentId, extend({ client: self }, opts))
self.torrents.push(torrent)
@@ -192,6 +193,8 @@ WebTorrent.prototype.seed = function (input, opts, onseed) {
opts = {}
}
if (!opts) opts = {}
+ if (!opts.storageOpts) opts.storageOpts = {}
+ opts.storageOpts.noVerify = true
createTorrent.parseInput(input, opts, function (err, files) {
if (err) return self.emit('error', err)
diff --git a/lib/storage.js b/lib/storage.js
index df87305..2964f2f 100644
--- a/lib/storage.js
+++ b/lib/storage.js
@@ -28,14 +28,16 @@ inherits(Piece, EventEmitter)
* @param {number} index piece index
* @param {string} hash sha1 hash (hex) for this piece
* @param {Buffer|number} buffer backing buffer for this piece or length of piece if the backing buffer is lazy
+ * @param {boolean=} noVerify skip piece verification (used when seeding a new file)
*/
-function Piece (index, hash, buffer) {
+function Piece (index, hash, buffer, noVerify) {
var self = this
EventEmitter.call(self)
if (!debug.enabled) self.setMaxListeners(0)
self.index = index
self.hash = hash
+ self.noVerify = !!noVerify
if (typeof buffer === 'number') {
// alloc buffer lazily
@@ -130,7 +132,7 @@ Piece.prototype.verify = function (buffer) {
return
}
- self.verified = (sha1(buffer) === self.hash)
+ self.verified = self.noVerify || (sha1(buffer) === self.hash)
if (self.verified) {
self.emit('done')
} else {
@@ -333,7 +335,7 @@ function Storage (parsedTorrent, opts) {
// otherwise, the piece's buffer will be lazily created on demand
var buffer = (self.buffer ? self.buffer.slice(start, end) : end - start)
- var piece = new Piece(index, hash, buffer)
+ var piece = new Piece(index, hash, buffer, !!opts.noVerify)
piece.on('done', self._onPieceDone.bind(self, piece))
return piece
})