summaryrefslogtreecommitdiffstats
path: root/player
diff options
context:
space:
mode:
authorJulian <MyFakeAcc.4@googlemail.com>2017-12-26 17:53:22 +0100
committerMartin Herkt <652892+lachs0r@users.noreply.github.com>2017-12-26 18:40:43 +0100
commita4eda0c9844586c10e3804f4a8e5e809aebb6569 (patch)
treef5f5d62a9bba1515bdd4c537517eb05f33f14f95 /player
parent8b7da7a8e50764e750a0507cc4b72687203bba89 (diff)
downloadmpv-a4eda0c9844586c10e3804f4a8e5e809aebb6569.tar.bz2
mpv-a4eda0c9844586c10e3804f4a8e5e809aebb6569.tar.xz
lua: implement mp_utils.format_bytes_humanized
Diffstat (limited to 'player')
-rw-r--r--player/lua/defaults.lua10
1 files changed, 10 insertions, 0 deletions
diff --git a/player/lua/defaults.lua b/player/lua/defaults.lua
index 1320522b26..32dfed9948 100644
--- a/player/lua/defaults.lua
+++ b/player/lua/defaults.lua
@@ -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 {}