format formats bytes integer to human readable string. For example, 31323 bytes will return 30.59KB.
(b int64)
| 358 | // format formats bytes integer to human readable string. |
| 359 | // For example, 31323 bytes will return 30.59KB. |
| 360 | func format(b int64) string { |
| 361 | multiple := "" |
| 362 | value := float64(b) |
| 363 | |
| 364 | switch { |
| 365 | case b >= EB: |
| 366 | value /= float64(EB) |
| 367 | multiple = "EB" |
| 368 | case b >= PB: |
| 369 | value /= float64(PB) |
| 370 | multiple = "PB" |
| 371 | case b >= TB: |
| 372 | value /= float64(TB) |
| 373 | multiple = "TB" |
| 374 | case b >= GB: |
| 375 | value /= float64(GB) |
| 376 | multiple = "GB" |
| 377 | case b >= MB: |
| 378 | value /= float64(MB) |
| 379 | multiple = "MB" |
| 380 | case b >= KB: |
| 381 | value /= float64(KB) |
| 382 | multiple = "KB" |
| 383 | case b == 0: |
| 384 | return "0" |
| 385 | default: |
| 386 | return strconv.FormatInt(b, 10) + "B" |
| 387 | } |
| 388 | |
| 389 | return fmt.Sprintf("%.2f%s", value, multiple) |
| 390 | } |
no outgoing calls
searching dependent graphs…