-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(progressBar): Ensures that the progress bar starts running w…
…hen it is able to recognize the file size and move it to a separate function
- Loading branch information
Showing
4 changed files
with
33 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import cliProgress from "cli-progress"; | ||
import colors from "ansi-colors"; | ||
import formatBytes from "./formatBytes.js"; | ||
|
||
const downloadProgressBar = (text) => { | ||
const downloadProgress = new cliProgress.SingleBar({ | ||
// eslint-disable-next-line max-len | ||
format: `${text} | ${colors.cyan("{bar}")} | {percentage}% || {loaded}/{all} MB || Speed: {speed}`, | ||
barCompleteChar: "\u2588", | ||
barIncompleteChar: "\u2591", | ||
hideCursor: true, | ||
}); | ||
|
||
return (progress) => { | ||
if (progress.total) { | ||
downloadProgress.start(progress.total, progress.loaded, { | ||
speed: `${formatBytes(progress.rate, 1)}KB/s` || "N/A", | ||
loaded: formatBytes(progress.loaded, 2) || "??", | ||
all: formatBytes(progress.total, 2) || "??", | ||
}); | ||
downloadProgress.update(progress.loaded, { | ||
speed: `${formatBytes(progress.rate) || "??"}KB/S`, | ||
loaded: formatBytes(progress.loaded) || "??", | ||
all: formatBytes(progress.total) || "??", | ||
}); | ||
} | ||
}; | ||
}; | ||
|
||
export default downloadProgressBar; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters