node-progress
node-progress copied to clipboard
Support rate formatters
Hello!
Thank you for this great library!
Right now, library gives no control to how :rate
is actually formatted. It's pretty standard use case (it's actually used in the README) when bytes are used for total and tick values. However, the library would output rate in plain bytes, which is absolutely unpractical for end users.
I would suggest to introduce a rate formatter function, e.g.:
import prettyBytes from 'pretty-bytes';
const bar = new ProgressBar(' downloading [:bar] :rate/sec :percent :etas', {
complete: '=',
incomplete: ' ',
width: 20,
total: totalBytes,
rateFormat: prettyBytes, // <--- using third-party formatter
});
This will output byte rate in a user-friendly fashion, e.g.: 1.56 MB/sec
.
Thanks!
I couldn't really find a solution for this. As the lib seems abandoned, I decided to rewrite it.
If the people reading this in the future want to use it, my version includes this functionality
This is a gravely needed feature. Every now and then I come across a need to display download progress, and I have to copy & paste some boilerplate to add faux tokens to my progress bar:
data.on('data', (chunk) => {
let curr = progress.curr + chunk.length;
progress.tick(chunk.length, {'currM': (curr / 1000000).toFixed(2)})
})
@NathanPB's version definitely provides an elegant way to specify these formatters and even includes a library of standard formatters. It is a bit more verbose though for the "regular" tokens and also it cannot be used as a drop-in replacement for progress
in other contexts.