diff options
author | Feross Aboukhadijeh <feross@feross.org> | 2016-03-19 01:46:18 +0300 |
---|---|---|
committer | Feross Aboukhadijeh <feross@feross.org> | 2016-03-19 01:46:18 +0300 |
commit | 1b9b4a6b9cbe384c8c04099d778d46e936fbc84c (patch) | |
tree | 39d507bf484a3bd7f6a697f867091c8898de26d8 /lib/file-stream.js | |
parent | 18f985a645d1ab808efaf81abd458e93a86049d3 (diff) |
filestream.destroy(): accept onclose callback instead of error
Diffstat (limited to 'lib/file-stream.js')
-rw-r--r-- | lib/file-stream.js | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/file-stream.js b/lib/file-stream.js index 9402573..55355ea 100644 --- a/lib/file-stream.js +++ b/lib/file-stream.js @@ -60,7 +60,7 @@ FileStream.prototype._notify = function () { self._torrent.store.get(p, function (err, buffer) { self._notifying = false if (self.destroyed) return - if (err) return self.destroy(err) + if (err) return self._destroy(err) debug('read %s (length %s) (err %s)', p, buffer.length, err && err.message) if (self._offset) { @@ -82,9 +82,15 @@ FileStream.prototype._notify = function () { self._piece += 1 } -FileStream.prototype.destroy = function (err) { +FileStream.prototype.destroy = function (onclose) { + this._destroy(null, onclose) +} + +FileStream.prototype._destroy = function (err, onclose) { if (this.destroyed) return + if (onclose) this.once('close', onclose) this.destroyed = true + if (!this._torrent.destroyed) { this._torrent.deselect(this._startPiece, this._endPiece, true) } |