Format file size in human-readable format.
(size_bytes: Optional[int])
| 125 | |
| 126 | |
| 127 | def _format_file_size(size_bytes: Optional[int]) -> str: |
| 128 | """Format file size in human-readable format.""" |
| 129 | if size_bytes is None: |
| 130 | return "unknown size" |
| 131 | |
| 132 | if size_bytes < 1024: |
| 133 | return f"{size_bytes} B" |
| 134 | elif size_bytes < 1024 * 1024: |
| 135 | return f"{size_bytes / 1024:.1f} KB" |
| 136 | elif size_bytes < 1024 * 1024 * 1024: |
| 137 | return f"{size_bytes / (1024 * 1024):.1f} MB" |
| 138 | else: |
| 139 | return f"{size_bytes / (1024 * 1024 * 1024):.1f} GB" |
| 140 | |
| 141 | |
| 142 | # Global cache to track PlatformIO installations in this session |