In article <E1AKrZK-00059j-Kd / odie.runbox.com>,
  "T. Onoma" <transami / runbox.com> writes:

> could you show example? hmm...wouldn't the expected length be in the proc already if it were needed? that's what i did with my progressbar.

For example:

% ruby -rlib/open-uri -e 'open("http://www.ruby-lang.org/en/",:progress_proc => lambda {|pos, total| p [pos, total]})'
[720, 15324]
[1144, 15324]
...
[15200, 15324]
[15324, 15324]

If Content-Length is not given:

% ruby -rlib/open-uri -e 'open("http://www.ruby-lang.org/cgi-bin/cvsweb.cgi/",:progress_proc => lambda {|pos, total| p [pos, total]})'
[837, nil]
...
[5534, nil]

But http://www.ruby-lang.org/ reminds me redirection.

% ruby -rlib/open-uri -e 'open("http://www.ruby-lang.org/",:progress_proc => lambda {|pos, total| p [pos, total]})'
[242, nil]
[232, nil]
[720, 15324]
[1144, 15324]
...
[15200, 15324]
[15324, 15324]

First two lines which total is nil are about redirection response.
Hm.  It shouldn't be called with this interface.

But it may mean this interface is not so nice...

Anyone have idea?

> ugh, my typo. what i meant was:
>
>   open(url, {:pos => proc {|b| ...}})
>
> so that if, method_key = :pos and progress_prco = proc {|b| ...}
>
> would end up something like
>
>   ...
>       http.get(uri.to_s, header) { |str|
>           buf << str
>           progress_proc.call(buf.io.method(method_key).call) if progress_proc
>         }
>       }
>   ...
>
>
> but maybe that's too odd?

I don't like that.

* It's too generic without use cases.
* It may conflict with other options in future.
-- 
Tanaka Akira