1
0
mirror of https://github.com/yt-dlp/yt-dlp synced 2025-07-04 04:52:52 -05:00

[utils] Fix format_bytes output for Bytes (#2132)

Authored by: pukkandan, mdawar
This commit is contained in:
Pierre Mdawar
2021-12-28 03:38:31 +05:30
committed by pukkandan
parent ceb98323f2
commit f02d24d8d2
2 changed files with 15 additions and 2 deletions

View File

@ -2118,11 +2118,11 @@ def format_decimal_suffix(num, fmt='%d%s', *, factor=1000):
exponent = 0 if num == 0 else int(math.log(num, factor))
suffix = ['', *'KMGTPEZY'][exponent]
converted = num / (factor ** exponent)
return fmt % (converted, suffix)
return fmt % (converted, f'{suffix}i' if suffix and factor == 1024 else suffix)
def format_bytes(bytes):
return format_decimal_suffix(bytes, '%.2f%siB', factor=1024) or 'N/A'
return format_decimal_suffix(bytes, '%.2f%sB', factor=1024) or 'N/A'
def lookup_unit_table(unit_table, s):