mirror of https://github.com/mpv-player/mpv
lua: implement mp_utils.format_bytes_humanized
This commit is contained in:
parent
8b7da7a8e5
commit
a4eda0c984
|
@ -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 {}
|
||||
|
|
Loading…
Reference in New Issue