tgfs / WebStreamer /utils /human_readable.py
S VIVEGANANDAN
Push latest changes from FileStreamBot-1
b0bc1a0
raw
history blame contribute delete
380 Bytes
# This file is a part of TG-FileStreamBot
def humanbytes(size):
# https://stackoverflow.com/a/49361727/4723940
# 2**10 = 1024
if not size:
return ""
power = 2**10
n = 0
Dic_powerN = {0: ' ', 1: 'Ki', 2: 'Mi', 3: 'Gi', 4: 'Ti'}
while size > power:
size /= power
n += 1
return str(round(size, 2)) + " " + Dic_powerN[n] + 'B'