video-stream/program/utils/formatters.py

11 lines
274 B
Python
Raw Normal View History

2022-01-31 12:41:47 +00:00
def bytes(size: float) -> str:
if not size:
return ""
power = 1024
t_n = 0
power_dict = {0: " ", 1: "Ki", 2: "Mi", 3: "Gi", 4: "Ti"}
while size > power:
size /= power
t_n += 1
return "{:.2f} {}B".format(size, power_dict[t_n])