From efc4b54f1ec3aa5cd0e2f60da74a67049f70de44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Rodr=C3=ADguez=20Baquero?= Date: Tue, 29 Dec 2015 22:37:08 -0500 Subject: [PATCH] Fix timeRemaining issue When the swarm hasn't been created but the timeRemaining property is accessed, it causes an error. --- lib/torrent.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/torrent.js b/lib/torrent.js index 8af4b681..671e825f 100644 --- a/lib/torrent.js +++ b/lib/torrent.js @@ -97,7 +97,7 @@ function Torrent (torrentId, opts) { Object.defineProperty(Torrent.prototype, 'timeRemaining', { get: function () { if (this.done) return 0 - if (this.swarm.downloadSpeed() === 0) return Infinity + if (this.swarm === undefined || this.swarm.downloadSpeed() === 0) return Infinity else return ((this.length - this.downloaded) / this.swarm.downloadSpeed()) * 1000 } })