Format byte count as human-readable string. Args: bytes_count: Number of bytes Returns: Formatted string (e.g., "1.5 GB", "234 MB")
(bytes_count: int)
| 115 | |
| 116 | |
| 117 | def format_bytes(bytes_count: int) -> str: |
| 118 | """Format byte count as human-readable string. |
| 119 | |
| 120 | Args: |
| 121 | bytes_count: Number of bytes |
| 122 | |
| 123 | Returns: |
| 124 | Formatted string (e.g., "1.5 GB", "234 MB") |
| 125 | """ |
| 126 | if bytes_count == 0: |
| 127 | return "0 B" |
| 128 | |
| 129 | units = ["B", "KB", "MB", "GB", "TB"] |
| 130 | unit_index = 0 |
| 131 | size = float(bytes_count) |
| 132 | |
| 133 | while size >= 1024.0 and unit_index < len(units) - 1: |
| 134 | size /= 1024.0 |
| 135 | unit_index += 1 |
| 136 | |
| 137 | return f"{size:.1f} {units[unit_index]}" |
| 138 | |
| 139 | |
| 140 | def format_duration(seconds: float) -> str: |
no outgoing calls