diff options
-rw-r--r-- | lib/torrent.js | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/lib/torrent.js b/lib/torrent.js index e13ee48..3f41c09 100644 --- a/lib/torrent.js +++ b/lib/torrent.js @@ -449,6 +449,7 @@ Torrent.prototype.destroy = function (cb) { */ Torrent.prototype.addPeer = function (peer) { var self = this + if (self.destroyed) throw new Error('torrent is destroyed') function addPeer () { self.swarm.addPeer(peer) @@ -473,9 +474,9 @@ Torrent.prototype.addPeer = function (peer) { * @param {string} url web seed url */ Torrent.prototype.addWebSeed = function (url) { - var self = this + if (this.destroyed) throw new Error('torrent is destroyed') debug('add web seed %s', url) - self.swarm.addWebSeed(url, self) + this.swarm.addWebSeed(url, this) } /** @@ -488,6 +489,8 @@ Torrent.prototype.addWebSeed = function (url) { */ Torrent.prototype.select = function (start, end, priority, notify) { var self = this + if (self.destroyed) throw new Error('torrent is destroyed') + if (start > end || start < 0 || end >= self.pieces.length) { throw new Error('invalid selection ', start, ':', end) } @@ -519,6 +522,8 @@ Torrent.prototype.select = function (start, end, priority, notify) { */ Torrent.prototype.deselect = function (start, end, priority) { var self = this + if (self.destroyed) throw new Error('torrent is destroyed') + priority = Number(priority) || 0 debug('deselect %s-%s (priority %s)', start, end, priority) @@ -541,6 +546,8 @@ Torrent.prototype.deselect = function (start, end, priority) { */ Torrent.prototype.critical = function (start, end) { var self = this + if (self.destroyed) throw new Error('torrent is destroyed') + debug('critical %s-%s', start, end) for (var i = start; i <= end; ++i) { @@ -1180,6 +1187,8 @@ Torrent.prototype._checkDone = function () { Torrent.prototype.load = function (streams, cb) { var self = this + if (self.destroyed) throw new Error('torrent is destroyed') + if (!Array.isArray(streams)) streams = [ streams ] if (!cb) cb = noop @@ -1199,10 +1208,11 @@ Torrent.prototype.load = function (streams, cb) { } Torrent.prototype.createServer = function (opts) { - var self = this + if (this.destroyed) throw new Error('torrent is destroyed') + if (typeof Server !== 'function') throw new Error('node.js-only method') - var server = new Server(self, opts) - self._servers.push(server) + var server = new Server(this, opts) + this._servers.push(server) return server } |