formatBytes formats a byte count as a human-readable string (e.g. 1.5 GiB).
(b int64)
| 295 | |
| 296 | // formatBytes formats a byte count as a human-readable string (e.g. 1.5 GiB). |
| 297 | func formatBytes(b int64) string { |
| 298 | const unit = 1024 |
| 299 | |
| 300 | if b < unit { |
| 301 | return fmt.Sprintf("%d B", b) |
| 302 | } |
| 303 | |
| 304 | div, exp := int64(unit), 0 |
| 305 | |
| 306 | for n := b / unit; n >= unit; n /= unit { |
| 307 | div *= unit |
| 308 | exp++ |
| 309 | } |
| 310 | |
| 311 | return fmt.Sprintf("%.1f %ciB", float64(b)/float64(div), "KMGTPE"[exp]) |
| 312 | } |
| 313 | |
| 314 | // formatUptime formats seconds into a human-readable duration string. |
| 315 | func formatUptime(seconds int64) string { |
no outgoing calls