Eric Hodel
4/29/2009 6:57:00 AM
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