Convert a size in octets to a human string representation
(x, fmt=".1f")
| 3386 | |
| 3387 | |
| 3388 | def human_size(x, fmt=".1f"): |
| 3389 | # type: (int, str) -> str |
| 3390 | """ |
| 3391 | Convert a size in octets to a human string representation |
| 3392 | """ |
| 3393 | units = ['K', 'M', 'G', 'T', 'P', 'E'] |
| 3394 | if not x: |
| 3395 | return "0B" |
| 3396 | i = int(math.log(x, 2**10)) |
| 3397 | if i and i < len(units): |
| 3398 | return format(x / 2**(10 * i), fmt) + units[i - 1] |
| 3399 | return str(x) + "B" |
| 3400 | |
| 3401 | |
| 3402 | def __make_table( |
no outgoing calls
no test coverage detected