diff --git a/lib/file.js b/lib/file.js index c73fc386..ff19a1c1 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 }