Skip to content

Commit

Permalink
Update progress.cr
Browse files Browse the repository at this point in the history
  • Loading branch information
mamantoha committed Oct 23, 2023
1 parent a131334 commit ebe63b0
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions samples/progress.cr
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
require "../src/crest"

url = "https://releases.ubuntu.com/23.04/ubuntu-23.04-desktop-amd64.iso"
url = "https://releases.ubuntu.com/mantic/ubuntu-23.10.1-desktop-amd64.iso"
buffer_size = 4096
downloaded_size = 0

Crest.get(url) do |response|
output_file = response.filename || "ubuntu-23.04-desktop-amd64.iso"
output_file = response.filename || url.split('/').last
content_length = response.content_length

File.open(output_file, "w") do |file|
Expand All @@ -21,8 +21,10 @@ Crest.get(url) do |response|
downloaded_size += bytes_read
downloaded_in_percents = ((downloaded_size / content_length) * 100).round(0)

print "Received data: #{downloaded_size.humanize_bytes} (#{downloaded_in_percents}%)"
print "\r"
line = "Received data: #{downloaded_size.humanize_bytes}/#{content_length.humanize_bytes} (#{downloaded_in_percents}%)"

print "\r#{" " * (line.size + 10)}\r"
print line
end
end

Expand Down

0 comments on commit ebe63b0

Please sign in to comment.