diff options
author | Feross Aboukhadijeh <feross@feross.org> | 2021-01-29 04:03:45 +0300 |
---|---|---|
committer | Feross Aboukhadijeh <feross@feross.org> | 2021-01-29 04:03:45 +0300 |
commit | 85dad90d30208ef788e691456cbf4319616bc6a0 (patch) | |
tree | 38c7910eb42b084a9a8cd68408abd72a190ec568 /lib | |
parent | 3a1ea54f9cfbb7a358ef6f4afb65646a65a1672c (diff) |
correctly calculate file downloaded progress
Diffstat (limited to 'lib')
-rw-r--r-- | lib/file.js | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/lib/file.js b/lib/file.js index d9a10e0..abd4f5d 100644 --- a/lib/file.js +++ b/lib/file.js @@ -60,9 +60,10 @@ class File extends EventEmitter { } } - // We don't know the end offset, so return this.length if it's oversized. - // e.g. One small file can fit in the middle of a piece. - return Math.min(downloaded, this.length) + const irrelevantLastPieceBytes = pieceLength - ((this.offset + this.length) % pieceLength) + downloaded -= irrelevantLastPieceBytes + + return downloaded } get progress () { |