Abuse filter editor, Bureaucrats, Check users, Interface administrators, Staff, Suppressors, Administrators, Translation Reviewer
2,193
edits
No edit summary |
No edit summary |
||
Line 25: | Line 25: | ||
function p.raw_mib_to_blocks(mib) | function p.raw_mib_to_blocks(mib) | ||
return math.ceil(mib * 8) | return math.ceil(mib * 8) | ||
end | |||
function get_display_unit(size) | |||
if size >= 1024 * 1024 * 1024 then | |||
return size / 1024 / 1024 / 1024, 'GiB' | |||
elseif size >= 1024 * 1024 then | |||
return size / 1024 / 1024, 'MiB' | |||
elseif size >= 1024 then | |||
return size / 1024, 'KiB' | |||
else | |||
return size, 'bytes' | |||
end | |||
end | end | ||
function p.raw_format_bytes(bytes) | function p.raw_format_bytes(bytes) | ||
-- this needs to do bytes, kib, and gib too | -- this needs to do bytes, kib, and gib too | ||
return string.format("%.2f", | local formatted_size, unit = get_display_unit(bytes) | ||
return string.format("%.2f", formatted_size) .. ' ' .. unit | |||
end | end | ||