lua: implement mp_utils.format_bytes_humanized

This commit is contained in:
Julian 2017-12-26 17:53:22 +01:00 committed by Martin Herkt
parent 8b7da7a8e5
commit a4eda0c984
1 changed files with 10 additions and 0 deletions

View File

@ -589,4 +589,14 @@ function mp_utils.getcwd()
return mp.get_property("working-directory")
end
function mp_utils.format_bytes_humanized(b)
local d = {"Bytes", "KiB", "MiB", "GiB", "TiB", "PiB"}
local i = 1
while b >= 1024 do
b = b / 1024
i = i + 1
end
return string.format("%0.2f %s", b, d[i] and d[i] or "*1024^" .. (i-1))
end
return {}