shorter common.ByteCount for shorter logs #433

This commit is contained in:
Alex Sharov 2022-04-28 09:56:26 +07:00 committed by GitHub
parent 14f53eefaf
commit 42355b17ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -21,14 +21,14 @@ import "fmt"
func ByteCount(b uint64) string {
const unit = 1024
if b < unit {
return fmt.Sprintf("%d B", b)
return fmt.Sprintf("%db", b)
}
div, exp := uint64(unit), 0
for n := b / unit; n >= unit; n /= unit {
div *= unit
exp++
}
return fmt.Sprintf("%.1f %ciB",
return fmt.Sprintf("%.1f%cb",
float64(b)/float64(div), "KMGTPE"[exp])
}