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:
authorMikeal Rogers <mikeal.rogers@gmail.com>2016-11-10 10:13:56 +0300
committerMikeal Rogers <mikeal.rogers@gmail.com>2016-11-10 10:13:56 +0300
commit71a79058144b3d3ea4db4923c079645eeeedf8c6 (patch)
tree83e5f976227ad5d77a137069ffa232c11a8e055e /lib
parent604eb699616f2fdc0b83f529f55a5005510e56a6 (diff)
Adding property for downloaded bytes per file.
Diffstat (limited to 'lib')
-rw-r--r--lib/file.js18
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/file.js b/lib/file.js
index 65c9187..d1e72bb 100644
--- a/lib/file.js
+++ b/lib/file.js
@@ -38,6 +38,24 @@ function File (torrent, file) {
}
}
+Object.defineProperty(File.prototype, 'downloaded', {
+ get: function () {
+ if (!this._torrent.bitfield) return 0
+ var downloaded = 0
+ for (var index = this._startPiece; index <= this._endPiece; ++index) {
+ if (this._torrent.bitfield.get(index)) {
+ // verified data
+ downloaded += this._torrent.pieceLength
+ } else {
+ // "in progress" data
+ var piece = this._torrent.pieces[index]
+ downloaded += (piece.length - piece.missing)
+ }
+ }
+ return downloaded
+ }
+})
+
File.prototype.select = function (priority) {
if (this.length === 0) return
this._torrent.select(this._startPiece, this._endPiece, priority)