mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Added util.getFormattedSize() (#3383)
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user