Hanze_Surfnet_Data_POC/Enquete/enquete/storage/utils.py
2022-02-17 14:35:54 +01:00

9 lines
273 B
Python

def human_filesize(nbytes):
suffixes = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB']
i = 0
while nbytes >= 1024 and i < len(suffixes) - 1:
nbytes /= 1024.
i += 1
f = ('%.2f' % nbytes).rstrip('0').rstrip('.')
return '%s %s' % (f, suffixes[i])