Files
vaiola/modules/shared/format_bytes.py
bsakaguchi 3a88bdad3a Harden image fetch algorithm
Prepare for database integration
2025-09-24 20:07:19 +07:00

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"