Download progress

D

Daniel Vartanov

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
 
E

Eric Hodel

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
 
M

Marc Heiler

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

Nice to see such snippets. :)
 
7

7stud --

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

Nice to see such snippets. :)

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top