'Fixed' downloads failing at point due to Excon shared connection and threads, added byte size formatter

This commit is contained in:
2021-11-16 11:31:47 -06:00
parent db97b5a3ab
commit dab16e7663
3 changed files with 24 additions and 3 deletions

18
lib/common.rb Normal file
View File

@@ -0,0 +1,18 @@
class W3DHub
def self.format_size(bytes)
case bytes
when 0..1023 # Bytes
"#{bytes} B"
when 1024..1_048_575 # KiloBytes
"#{format_size_number(bytes / 1024.0)} KB"
when 1_048_576..1_073_741_999 # MegaBytes
"#{format_size_number(bytes / 1_048_576.0)} MB"
else # GigaBytes
"#{format_size_number(bytes / 1_073_742_000.0)} GB"
end
end
def self.format_size_number(i)
format("%0.1f", i)
end
end