VE Lua Documentation

Press F to search!

bytes_to_string

Definition


-- @/lua/common/utils.lua:251

-- converts a byte count to a human readable string
function bytes_to_string(bytes)
    if bytes >= 1000 * 1000 * 1000 then
      return ("%.2f GB"):format(bytes / (1000 * 1000 * 1000))
    elseif bytes >= 1000 * 1000 then
      return ("%.2f MB"):format(bytes / (1000 * 1000))
    elseif bytes >= 1000 then
      return ("%.2f KB"):format(bytes / 1000)
    end
    return ("%.2f B"):format(bytes)
  end

Callers

@/lua/ge/extensions/util/screenshotCreator.lua
        local rawSize = x * y * 3 -- RGB = 3 byte
        im.TextUnformatted('Raw image size = ' .. (bytes_to_string(rawSize)))
        im.TextUnformatted('Estimated JPG file size = ' .. (bytes_to_string(rawSize * 0.14)))
        im.TextUnformatted('Raw image size = ' .. (bytes_to_string(rawSize)))
        im.TextUnformatted('Estimated JPG file size = ' .. (bytes_to_string(rawSize * 0.14)))
@/lua/ge/extensions/editor/fileDialog.lua
    im.NextColumn()
    im.TextUnformatted(bytes_to_string(selectedFile.filesize))
    im.NextColumn()
        if file.filesize then
          im.TextUnformatted(bytes_to_string(file.filesize))
        end