Skip to content

Commit

Permalink
Improve attachment.utils:convert_size readability
Browse files Browse the repository at this point in the history
  • Loading branch information
rbw committed Oct 14, 2020
1 parent 28dcbfd commit 7911429
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions aiosnow/models/attachment/utils.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import math
from typing import Tuple


def convert_size(size_bytes):
def convert_size(size_bytes: int) -> Tuple[float, str]:
if size_bytes == 0:
return 0, "B"

u = ("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB")
i = int(math.floor(math.log(size_bytes, 1024)))
p = math.pow(1024, i)
s = round(size_bytes / p, 2)
return s, u[i]
units = ("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB")
log = int(math.floor(math.log(size_bytes, 1024)))
power = math.pow(1024, log)
size = round(size_bytes / power, 2)
return size, units[log]

0 comments on commit 7911429

Please sign in to comment.