diff options
-rw-r--r-- | lib/torrent.js | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/torrent.js b/lib/torrent.js index e34041f..3bb44a0 100644 --- a/lib/torrent.js +++ b/lib/torrent.js @@ -75,6 +75,7 @@ function Torrent (torrentId, opts) { self._selections = [] self._critical = [] self._storageImpl = opts.storage || Storage + this._torrentFileURL = null var parsedTorrent try { @@ -213,9 +214,12 @@ Object.defineProperty(Torrent.prototype, 'torrentFile', { Object.defineProperty(Torrent.prototype, 'torrentFileURL', { get: function () { - return window.URL.createObjectURL( + if (typeof window === 'undefined') throw new Error('browser-only property') + if (this._torrentFileURL) return this._torrentFileURL + this._torrentFileURL = window.URL.createObjectURL( new window.Blob([ this.torrentFile ], { type: 'application/x-bittorrent' }) ) + return this._torrentFileURL } }) @@ -361,6 +365,8 @@ Torrent.prototype.destroy = function (cb) { self._rechokeIntervalId = null } + if (self._torrentFileURL) window.URL.revokeObjectURL(self._torrentFileURL) + var tasks = [] if (self.swarm) tasks.push(function (cb) { self.swarm.destroy(cb) }) if (self.discovery) tasks.push(function (cb) { self.discovery.stop(cb) }) |