Added util.getFormattedSize() (#3383)

pull/3384/head
poire-z 7 years ago committed by Frans de Jonge
parent ba6cc87424
commit ecaeb4b6d7

@ -52,7 +52,9 @@ function BookInfo:show(file, book_props)
local directory, filename = util.splitFilePathName(file)
local filename_without_suffix, filetype = util.splitFileNameSuffix(filename) -- luacheck: no unused
local file_size = lfs.attributes(file, "size") or 0
local size = util.getFriendlySize(file_size)
local size_f = util.getFriendlySize(file_size)
local size_b = util.getFormattedSize(file_size)
local size = string.format("%s (%s bytes)", size_f, size_b)
table.insert(kv_pairs, { _("Filename:"), filename })
table.insert(kv_pairs, { _("Format:"), filetype:upper() })
table.insert(kv_pairs, { _("Size:"), size })

@ -369,6 +369,16 @@ function util.getFriendlySize(size)
return s
end
--- Gets formatted size as string (1273334 => "1,273,334")
---- @int size (bytes)
---- @treturn string
function util.getFormattedSize(size)
local s = tostring(size)
s = s:reverse():gsub("(%d%d%d)", "%1,")
s = s:reverse():gsub("^,", "")
return s
end
--- Adds > to touch menu items with a submenu
function util.getMenuText(item)
local text

Loading…
Cancel
Save