(size)
| 139 | |
| 140 | |
| 141 | def format_size(size): |
| 142 | try: |
| 143 | size = float(size) |
| 144 | except Exception: |
| 145 | return "0 B" |
| 146 | units = ["B", "KB", "MB", "GB", "TB"] |
| 147 | index = 0 |
| 148 | while size >= 1024 and index < len(units) - 1: |
| 149 | size = size / 1024 |
| 150 | index += 1 |
| 151 | if index == 0: |
| 152 | return f"{int(size)} {units[index]}" |
| 153 | return f"{size:.2f} {units[index]}" |
| 154 | |
| 155 | |
| 156 | def normalize_ext(ext): |
no outgoing calls
no test coverage detected