[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: can't flush I know why, but no fix

T. Onoma

11/14/2003 6:14:00 AM

> However, it might be worthwhile modifying open_uri to allow the asynchronous download and progress notification you want, and then submit a patch, so this can end up in the core code.

Thanks Harry! I took your advice. Its not quite asynchronous download, but what i did was add in a hook. So now you can do this:

require 'open_uri'
progress_proc = proc { |b| print "Downloaded #{b} bytes so far." }
open(url, progress_proc) { |f| print "Done" }

This of course will print many lines like:

Downloaded 1 bytes so far.
Downloaded 2 bytes so far.
Downloaded 3 bytes so far.
Downloaded 4 bytes so far.
Downloaded 5 bytes so far.
...
Done.

Not sure the exact count of bytes for each cycle. This really works well with Ruby/ProgressBar though (which moves back to the same line with each pass).

It probably could be made a tad more robust but I am pretty sure i covered all the base in the code. The this lib's in the distribution of Ruby, so how/who do i give the new version to now?

-t0