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:
authorFeross Aboukhadijeh <feross@feross.org>2016-05-29 03:35:51 +0300
committerFeross Aboukhadijeh <feross@feross.org>2016-05-29 03:35:51 +0300
commit78cd54797310f3b3993425019baba0dd68ed4b23 (patch)
tree46004a443c4cf954103176d997a9ff17c0230a4a /lib
parent7673f6cfa3552c150d07d87cc2350ef8e6fdba4c (diff)
Fix exception in file.js
If file is destroyed and stream ends afterwards, then an exception is thrown because self._torrent is undefined.
Diffstat (limited to 'lib')
-rw-r--r--lib/file.js3
1 files changed, 3 insertions, 0 deletions
diff --git a/lib/file.js b/lib/file.js
index c73fc38..ff19a1c 100644
--- a/lib/file.js
+++ b/lib/file.js
@@ -16,6 +16,7 @@ function File (torrent, file) {
EventEmitter.call(this)
this._torrent = torrent
+ this._destroyed = false
this.name = file.name
this.path = file.path
@@ -61,6 +62,7 @@ File.prototype.createReadStream = function (opts) {
fileStream._notify()
})
eos(fileStream, function () {
+ if (self._destroyed) return
if (!self._torrent.destroyed) {
self._torrent.deselect(fileStream._startPiece, fileStream._endPiece, true)
}
@@ -89,5 +91,6 @@ File.prototype.renderTo = function (elem, cb) {
}
File.prototype._destroy = function () {
+ this._destroyed = true
this._torrent = null
}