Added util.getFriendlySize() (#3381)

* Added util.getFriendlySize()

* Allow for GB
This commit is contained in:
poire-z
2017-10-20 17:48:32 +02:00
committed by Frans de Jonge
parent 87a86e0dc1
commit c15915a4ee
4 changed files with 21 additions and 25 deletions

View File

@@ -352,6 +352,23 @@ function util.getFileNameSuffix(file)
return suffix
end
--- Gets human friendly size as string
---- @int size (bytes)
---- @treturn string
function util.getFriendlySize(size)
local s
if size > 1024*1024*1024 then
s = string.format("%4.1f GB", size/1024/1024/1024)
elseif size > 1024*1024 then
s = string.format("%4.1f MB", size/1024/1024)
elseif size > 1024 then
s = string.format("%4.1f KB", size/1024)
else
s = string.format("%d B", size)
end
return s
end
--- Adds > to touch menu items with a submenu
function util.getMenuText(item)
local text