humanBytes formats a byte count as a short human-readable string. Used for stats lines that an operator scans visually.
(n uint64)
| 173 | // humanBytes formats a byte count as a short human-readable string. Used for |
| 174 | // stats lines that an operator scans visually. |
| 175 | func humanBytes(n uint64) string { |
| 176 | const k = 1024 |
| 177 | switch { |
| 178 | case n < k: |
| 179 | return fmt.Sprintf("%dB", n) |
| 180 | case n < k*k: |
| 181 | return fmt.Sprintf("%.1fKB", float64(n)/float64(k)) |
| 182 | case n < k*k*k: |
| 183 | return fmt.Sprintf("%.1fMB", float64(n)/float64(k*k)) |
| 184 | default: |
| 185 | return fmt.Sprintf("%.2fGB", float64(n)/float64(k*k*k)) |
| 186 | } |
| 187 | } |