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>2015-05-21 01:32:36 +0300
committerFeross Aboukhadijeh <feross@feross.org>2015-05-21 01:32:36 +0300
commit63f48e99843242e4de3da27a8b10155376d2c24e (patch)
tree02c655a21069b1c5fa7a9f8627aaf61decdd3100 /lib
parente8783fec76bb965605875101399096d4ee2aa57d (diff)
cleanup torrent.torrentFileURL blob on destroy
For #322
Diffstat (limited to 'lib')
-rw-r--r--lib/torrent.js8
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) })