mirror of
https://github.com/chromebrew/chromebrew.git
synced 2026-01-10 07:57:59 -05:00
* Use net http (#3) * Add user agent header * Update crew * Update downloader.rb * Update const.rb * Fix const.rb crash. Co-authored-by: Satadru Pramanik <satadru@umich.edu> Co-authored-by: Satadru Pramanik <satadru@gmail.com>
23 lines
479 B
Ruby
23 lines
479 B
Ruby
def human_size (bytes)
|
|
kilobyte = 1024.0
|
|
megabyte = kilobyte * kilobyte
|
|
gigabyte = megabyte * kilobyte
|
|
if bytes < kilobyte
|
|
units = 'B'
|
|
size = bytes
|
|
end
|
|
if bytes >= kilobyte and bytes < megabyte
|
|
units = 'KB'
|
|
size = bytes / kilobyte
|
|
end
|
|
if bytes >= megabyte and bytes < gigabyte
|
|
units = 'MB'
|
|
size = bytes / megabyte
|
|
end
|
|
if bytes >= gigabyte
|
|
units = 'GB'
|
|
size = bytes / gigabyte
|
|
end
|
|
return sprintf('%.2f %s', size, units)
|
|
end
|