Forum: Ruby Download progress

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
2160f04d1ee1ee303eb528580e8830d7?d=identicon&s=25 Daniel Vartanov (daniel-vartanov)
on 2009-04-29 07:48
(Received via mailing list)
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
58479f76374a3ba3c69b9804163f39f4?d=identicon&s=25 Eric Hodel (Guest)
on 2009-04-29 08:57
(Received via mailing list)
On Apr 28, 2009, at 22:45, Daniel Vartanov 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
4828d528e2e46f7c8160c336eb332836?d=identicon&s=25 Robert Heiler (shevegen)
on 2009-04-29 12:33
Cool, I also did not know that, but I wondered about this for a long
time.

Nice to see such snippets. :)
54404bcac0f45bf1c8e8b827cd9bb709?d=identicon&s=25 7stud -- (7stud)
on 2009-04-29 17:07
Marc Heiler wrote:
> 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. :)
0075c9c01267b117ac97b7a02f97dbd4?d=identicon&s=25 Mathspeedy (Guest)
on 2009-04-30 01:40
(Received via mailing list)
You could use the "progressbar" library ..
This topic is locked and can not be replied to.