From a473f29f34f76981a40cf6c64cb54c298939684e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Rodr=C3=ADguez=20Baquero?= Date: Mon, 4 Jan 2016 00:25:19 -0500 Subject: [PATCH] Fix downloaded property access When bitfield is not yet created, accessing downloaded property will throw an error. --- lib/torrent.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/torrent.js b/lib/torrent.js index 0ed1fa55..0beedc10 100644 --- a/lib/torrent.js +++ b/lib/torrent.js @@ -105,6 +105,7 @@ Object.defineProperty(Torrent.prototype, 'timeRemaining', { // Bytes completed (excluding invalid data) Object.defineProperty(Torrent.prototype, 'downloaded', { get: function () { + if (!this.bitfield) return 0 var downloaded = 0 for (var index = 0, len = this.pieces.length; index < len; ++index) { if (this.bitfield.get(index)) { // verified data