Format bytes as text >>> from dask.utils import format_bytes >>> format_bytes(1) '1 B' >>> format_bytes(1234) '1.21 kiB' >>> format_bytes(12345678) '11.77 MiB' >>> format_bytes(1234567890) '1.15 GiB' >>> format_bytes(1234567890000) '1.12 TiB' >>> form
(n: int)
| 1769 | |
| 1770 | |
| 1771 | def format_bytes(n: int) -> str: |
| 1772 | """Format bytes as text |
| 1773 | |
| 1774 | >>> from dask.utils import format_bytes |
| 1775 | >>> format_bytes(1) |
| 1776 | '1 B' |
| 1777 | >>> format_bytes(1234) |
| 1778 | '1.21 kiB' |
| 1779 | >>> format_bytes(12345678) |
| 1780 | '11.77 MiB' |
| 1781 | >>> format_bytes(1234567890) |
| 1782 | '1.15 GiB' |
| 1783 | >>> format_bytes(1234567890000) |
| 1784 | '1.12 TiB' |
| 1785 | >>> format_bytes(1234567890000000) |
| 1786 | '1.10 PiB' |
| 1787 | |
| 1788 | For all values < 2**60, the output is always <= 10 characters. |
| 1789 | """ |
| 1790 | for prefix, k in ( |
| 1791 | ("Pi", 2**50), |
| 1792 | ("Ti", 2**40), |
| 1793 | ("Gi", 2**30), |
| 1794 | ("Mi", 2**20), |
| 1795 | ("ki", 2**10), |
| 1796 | ): |
| 1797 | if n >= k * 0.9: |
| 1798 | return f"{n / k:.2f} {prefix}B" |
| 1799 | return f"{n} B" |
| 1800 | |
| 1801 | |
| 1802 | timedelta_sizes = { |
no outgoing calls