Format a byte count as a human-readable string.
(nbytes: int)
| 60 | |
| 61 | |
| 62 | def format_bytes(nbytes: int) -> str: |
| 63 | """Format a byte count as a human-readable string.""" |
| 64 | units = ["B", "KiB", "MiB", "GiB", "TiB"] |
| 65 | size = float(nbytes) |
| 66 | for unit in units: |
| 67 | if size < 1024.0: |
| 68 | return f"{size:.2f} {unit}" |
| 69 | size /= 1024.0 |
| 70 | return f"{size:.2f} PiB" |
| 71 | |
| 72 | |
| 73 | def print_driver_info() -> None: |