humanBytes formats a byte count as a short human-readable string. Mirrors the carrier's helper but kept package-local to avoid an inter-package dependency just for one tiny formatter.
(n uint64)
| 56 | // the carrier's helper but kept package-local to avoid an inter-package |
| 57 | // dependency just for one tiny formatter. |
| 58 | func humanBytes(n uint64) string { |
| 59 | const k = 1024 |
| 60 | switch { |
| 61 | case n < k: |
| 62 | return fmt.Sprintf("%dB", n) |
| 63 | case n < k*k: |
| 64 | return fmt.Sprintf("%.1fKB", float64(n)/float64(k)) |
| 65 | case n < k*k*k: |
| 66 | return fmt.Sprintf("%.1fMB", float64(n)/float64(k*k)) |
| 67 | default: |
| 68 | return fmt.Sprintf("%.2fGB", float64(n)/float64(k*k*k)) |
| 69 | } |
| 70 | } |