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
path: root/lib
diff options
context:
space:
mode:
authorJohn Hiesey <john@hiesey.com>2018-07-18 02:17:02 +0300
committerJohn Hiesey <john@hiesey.com>2018-07-18 10:12:00 +0300
commit7d242dc034564776b3607ad06d2749bb71a15775 (patch)
tree0337a50934ea98867510eb4334245595a9604b5d /lib
parent71fa2641df8e431b8ec4a46d240bb9bc5ad07932 (diff)
Add opts.skipVerify to skip verifying existing data
Diffstat (limited to 'lib')
-rw-r--r--lib/torrent.js59
1 files changed, 33 insertions, 26 deletions
diff --git a/lib/torrent.js b/lib/torrent.js
index 6d53ee9..a7253f6 100644
--- a/lib/torrent.js
+++ b/lib/torrent.js
@@ -74,6 +74,7 @@ function Torrent (torrentId, client, opts) {
this.urlList = opts.urlList
this.path = opts.path
+ this.skipVerify = !!opts.skipVerify
this._store = opts.store || FSChunkStore
this._getAnnounceOpts = opts.getAnnounceOpts
@@ -542,29 +543,33 @@ Torrent.prototype._onMetadata = function (metadata) {
self._onWireWithMetadata(wire)
})
- self._debug('verifying existing torrent data')
- if (self._fileModtimes && self._store === FSChunkStore) {
- // don't verify if the files haven't been modified since we last checked
- self.getFileModtimes(function (err, fileModtimes) {
- if (err) return self._destroy(err)
-
- var unchanged = self.files.map(function (_, index) {
- return fileModtimes[index] === self._fileModtimes[index]
- }).every(function (x) {
- return x
- })
+ if (self.skipVerify) {
+ // Skip verifying exisitng data and just assume it's correct
+ self._markAllVerified()
+ self._onStore()
+ } else {
+ self._debug('verifying existing torrent data')
+ if (self._fileModtimes && self._store === FSChunkStore) {
+ // don't verify if the files haven't been modified since we last checked
+ self.getFileModtimes(function (err, fileModtimes) {
+ if (err) return self._destroy(err)
+
+ var unchanged = self.files.map(function (_, index) {
+ return fileModtimes[index] === self._fileModtimes[index]
+ }).every(function (x) {
+ return x
+ })
- if (unchanged) {
- for (var index = 0; index < self.pieces.length; index++) {
- self._markVerified(index)
+ if (unchanged) {
+ self._markAllVerified()
+ self._onStore()
+ } else {
+ self._verifyPieces()
}
- self._onStore()
- } else {
- self._verifyPieces()
- }
- })
- } else {
- self._verifyPieces()
+ })
+ } else {
+ self._verifyPieces()
+ }
}
self.emit('metadata')
@@ -623,6 +628,12 @@ Torrent.prototype._verifyPieces = function () {
})
}
+Torrent.prototype._markAllVerified = function () {
+ for (var index = 0; index < this.pieces.length; index++) {
+ this._markVerified(index)
+ }
+}
+
Torrent.prototype._markVerified = function (index) {
this.pieces[index] = null
this._reservations[index] = null
@@ -1625,11 +1636,7 @@ Torrent.prototype.load = function (streams, cb) {
pump(readable, writable, function (err) {
if (err) return cb(err)
- self.pieces.forEach(function (piece, index) {
- self.pieces[index] = null
- self._reservations[index] = null
- self.bitfield.set(index, true)
- })
+ self._markAllVerified()
self._checkDone()
cb(null)
})