feat: add file size in popup (#1049)
This commit is contained in:
committed by
GitHub
parent
5015e7226c
commit
ceadf83809
@@ -245,4 +245,19 @@ function M.table_create_missing(tbl, sub)
|
||||
return t
|
||||
end
|
||||
|
||||
function M.format_bytes(bytes)
|
||||
local units = {'B', 'K', 'M', 'G', 'T'}
|
||||
|
||||
bytes = math.max(bytes, 0)
|
||||
local pow = math.floor((bytes and math.log(bytes) or 0) / math.log(1024))
|
||||
pow = math.min(pow, #units)
|
||||
|
||||
local value = bytes / (1024 ^ pow)
|
||||
value = math.floor((value * 10) + 0.5) / 10
|
||||
|
||||
pow = pow + 1
|
||||
|
||||
return (units[pow] == nil) and (bytes .. 'B') or (value .. units[pow])
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
Reference in New Issue
Block a user