Skip to content

Commit

Permalink
fix: do not show "100%" progress when dowload first starts
Browse files Browse the repository at this point in the history
  • Loading branch information
lightpohl committed May 24, 2020
1 parent f0c0886 commit 3bc3152
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions bin/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,22 @@ let getImageUrl = ({ image, itunes }) => {
};

let BYTES_IN_MB = 1000000;
let printProgress = ({ percent, total }) => {
let printProgress = ({ percent, total, transferred }) => {
let line = "downloading...";
let percentRounded = (percent * 100).toFixed(2);
let line = `downloading... ${percentRounded}%`;

if (total) {
let totalMBs = total / BYTES_IN_MB;
let roundedTotalMbs = totalMBs.toFixed(2);
line += ` of ${roundedTotalMbs} MB`;
if (transferred > 0) {
/*
* Got has a bug where it'll set percent to 1 when the download first starts.
* Ignore percent until transfer has started.
*/
line += ` ${percentRounded}%`;

if (total) {
let totalMBs = total / BYTES_IN_MB;
let roundedTotalMbs = totalMBs.toFixed(2);
line += ` of ${roundedTotalMbs} MB`;
}
}

process.stdout.clearLine();
Expand Down

0 comments on commit 3bc3152

Please sign in to comment.