Change readable code

This commit is contained in:
yasirarism 2023-09-11 23:03:35 +07:00 committed by GitHub
parent 9465811244
commit 041b9fe856
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -5,13 +5,10 @@ def get_readable_file_size(size_in_bytes) -> str:
if size_in_bytes is None:
return "0B"
index = 0
while size_in_bytes >= 1024:
while size_in_bytes >= 1024 and index < len(SIZE_UNITS) - 1:
size_in_bytes /= 1024
index += 1
try:
return f"{round(size_in_bytes, 2)}{SIZE_UNITS[index]}"
except IndexError:
return "File too large"
return f"{size_in_bytes:.2f} {SIZE_UNITS[index]}" if index > 0 else f"{size_in_bytes}B"
def get_readable_time(seconds: int) -> str: