New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dl: show the download progress in megabytes (mebibytes) instead of bytes #45556
Comments
Sorry, but I'm missing what exactly "dl" is. The only reference I can find is the subset of |
It is the In some other issues is referenced as |
This seems like a somewhat beginner-friendly issue to solve. (Have used Go a lot, but never contributed) I would like to help out in case nobody else is working on it. |
Change https://golang.org/cl/310016 mentions this issue: |
@Hallicopter, I was sure to have already submitted the cl; sorry if you have already started working on it. |
That's not a problem at all! Just wanted to contribute back to Go in some way since it has helped me so much. I can always find something else. |
Bytes is much nicer to re-use though. It's more precise and there is no possible confusion with regard to M vs. Mi unit prefixes. You can always convert to displaying MB using a trivial filter while the opposite direction is not possible (the proposed patch throws away information). I don't think this change is a net improvement. |
If it needs to be precise I can replace To make the progress more precise we can choose the best unit, between KiB and MiB (again, as it is done by pacman). Thanks. |
sample.txt shows the output with the latest patchset in https://golang.org/cl/310016. The size is formatted in KiB without decimal digits when less then 2 MiB, and in MiB otherwise with 2 decimal digits. This ensures that the max width in KiB (2048) and the min width in MiB (2.00) are the same (4). The code changes are minimal and simple. |
Here is an alternative implementation: func fmtsize(size int64) string {
switch {
case size < 10000:
return strconv.FormatInt(size, 10) + " B"
case size < 1000000:
return strconv.FormatFloat(float64(size)/float64(KiB), 'f', 1, 64) + " KiB"
}
return strconv.FormatFloat(float64(size)/float64(MiB), 'f', 1, 64) + " MiB"
} This works correctly only if the download size is greater than 100 MB (decimal). |
This is probably the best version. The formatting is similar to the one in func fmtsize(size int64) string {
// When formatted in KiB there are no decimal digits and when formatted in
// MiB there is 1 decimal digit. This ensures that the max width in KiB
// and the min width in MiB are the same.
switch {
case size < 10*KiB:
return strconv.FormatInt(int64(size), 10) + " B"
case size < 10*MiB:
return strconv.FormatFloat(float64(size)/float64(KiB), 'f', 0, 64) + " KiB"
}
return strconv.FormatFloat(float64(size)/float64(MiB), 'f', 1, 64) + " MiB"
} |
Change https://golang.org/cl/339869 mentions this issue: |
Please note that this change is almost the same as the one I proposed: https://golang.org/cl/310016. The difference is in the formatting. |
Why using decimal units instead of binary units? |
Showing the download progress in bytes is not very convenient. The current and total sizes should be in megabytes (mebibytes).
The text was updated successfully, but these errors were encountered: