Files
chromebrew/lib/convert_size.rb
supechicken 8fc7b84aac Add a downloader based on the net/http library (#6491)
* 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>
2021-12-23 21:53:50 -06:00

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