INNER CODE UNIT · Python
format_size
etchdroid/etchdroid · misc/ostream-trace-log-analyzer.py:136
def format_size(size):
units = [
("bytes", 0),
("kB", 0),
("MB", 1),
("GB", 2),
("TB", 2),
("PB", 2)
]
if size < 0:
raise ValueError("Negative size not allowed")
if size == 0:
return "0 bytes"
if size == 1:
return "1 byte"
exponent = min(int(log(size, 1024)), len(units) - 1)