12 lines
328 B
Python
12 lines
328 B
Python
def format_bytes(bytes_size):
|
|
"""Convert bytes to human readable format"""
|
|
if bytes_size < 1024:
|
|
return f"{bytes_size} B"
|
|
|
|
for unit in ['B', 'KB', 'MB', 'GB', 'TB']:
|
|
if bytes_size < 1024.0:
|
|
return f"{bytes_size:.1f} {unit}"
|
|
bytes_size /= 1024.0
|
|
|
|
return f"{bytes_size:.1f} PB"
|