Download progress

Let’s consider we’re getting a long file through HTTP:

How to get a progress (percentage of done) of the download process? I
didn’t find such API in Net::HTTP

On Apr 28, 2009, at 22:45, Daniel V. wrote:

Let’s consider we’re getting a long file through HTTP:

How to get a progress (percentage of done) of the download process? I
didn’t find such API in Net::HTTP

You can use Net::HTTP#request_get and Net::HTTPResponse#read_body:

$ ruby -rnet/http
h = Net::HTTP.new ‘blog.segment7.net
h.request_get ‘/’ do |r| r.read_body do |s| p s.length end end
^D
751
184
1024
184
1024
184
[…]
$

There are probably other ways without #request_get

Cool, I also did not know that, but I wondered about this for a long
time.

Nice to see such snippets. :slight_smile:

You could use the “progressbar” library …

Marc H. wrote:

Cool, I also did not know that, but I wondered about this for a long
time.

Nice to see such snippets. :slight_smile:

I also put a note in the margin of my book about this one. :slight_smile:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs