From 33397267f84eff456cc585aae86a58b52a6854b8 Mon Sep 17 00:00:00 2001 From: Ash Date: Thu, 1 Jun 2017 14:28:10 -0500 Subject: [PATCH] added file.progress property, along with documentation --- docs/api.md | 4 ++++ lib/file.js | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/docs/api.md b/docs/api.md index e6805b6d..cb713d82 100644 --- a/docs/api.md +++ b/docs/api.md @@ -469,6 +469,10 @@ File length (in bytes), as specified by the torrent. *Example: 12345* Total *verified* bytes received from peers, for this file. +## `file.progress` + +File download progress, from 0 to 1. + ## `file.select()` Selects the file to be downloaded, but at a lower priority than files with streams. diff --git a/lib/file.js b/lib/file.js index d1e72bbe..d912faa4 100644 --- a/lib/file.js +++ b/lib/file.js @@ -56,6 +56,10 @@ Object.defineProperty(File.prototype, 'downloaded', { } }) +Object.defineProperty(File.prototype, 'progress', { + get: function () { return this.length ? this.downloaded / this.length : 0 } +}) + File.prototype.select = function (priority) { if (this.length === 0) return this._torrent.select(this._startPiece, this._endPiece, priority)