Patrick Plattes wrote:

> Hello people :-),
> 
> i have a question about downloading files. I want to download a file and
> print out how many bytes are downloaded. That's important to me, because
> i want to have a progress bar later.
> 
> The problem is that it looks like my code downloads the whole file and
> after that it executes the while loop -

No, actually, it is that the results are not printed out when you expect
them to be. The code is running as you wrote it, but the result printing is
being delayed. See below for the reason.

> this behavior is useless for me. 
> 
> does anyone know how to fix it or knows a better solution?

This is a very common beginner problem. The issue is that the main thread of
your application is too busy downloading the file to print anything out.
After the file is completely downloaded, your code exits, which gives the
environment freedom to do other things like print some data on the display.

To get a running account of your activity, you need to learn how to use
threads, and even then, because of how Ruby handles threads, showing a
progress bar is not a slam dunk.

-- 
Paul Lutus
http://www.arachnoid.com