From: Edwin Fine Date: 2006-12-24T01:35:48+09:00 Subject: Re: Question: Downloading files with open(-uri)? Mariano Kamp wrote: > Edwin Fine wrote: >> >> http://downloads.scribemedia.net/rails2006/03_martin_fowler_full.m4v >> puts "downloading #{url}" >> output.write(buffer) >> end >> end >> end >> puts "\ndone." >> end >> puts "All downloads done." > > Wow. Cool. How did you know about the content_length and progress > hooks? I don't see them in the docs. > > Anyway ... That looks nice, but I still don't see the progress on the > console, other than for ibm.com. Do you? > > I can see that I am downloading at 50KBytes/s using a network traffic > monitor, but not on the console. And if I read this right it should > yield a progress update roughly every kilobyte , right? > > This is what I see after ... say ... 5 minutes after launching the > program. > > downloading http://ibm.com > Writing to ibm.com > Content > length: 25348 bytes > Read 0000000822 bytes Read 0000001158 bytes Read 0000002182 bytes > Read 0000002518 bytes Read 0000003542 bytes Read 0000003878 bytes > Read 0000004902 bytes Read 0000005238 bytes Read 0000006262 bytes > Read 0000006598 bytes Read 0000007622 bytes Read 0000007958 bytes > Read 0000008982 bytes Read 0000009318 bytes Read 0000010342 bytes > Read 0000011366 bytes Read 0000012390 bytes Read 0000013398 bytes > Read 0000014422 bytes Read 0000014758 bytes Read 0000015782 bytes > Read 0000016118 bytes Read 0000017142 bytes Read 0000017478 bytes > Read 0000018502 bytes Read 0000018838 bytes Read 0000019862 bytes > Read 0000020198 bytes Read 0000021222 bytes Read 0000021558 bytes > Read 0000022582 bytes Read 0000022918 bytes Read 0000023942 bytes > Read 0000024278 bytes Read 0000025302 bytes Read 0000025348 bytes > done. > downloading http://downloads.scribemedia.net/ > rails2006/03_martin_fowler_full.m4v > Writing to 03_martin_fowler_full.m4v > Content > length: 413031533 bytes > > > Cheers, > Mariano It's documented here: http://www.ruby-doc.org/stdlib/libdoc/open-uri/rdoc/ This is what I am seeing: downloading http://ibm.com Writing to ibm.com Content length: 25348 bytes Read 0000025348 bytes done. downloading http://downloads.scribemedia.net/rails2006/03_martin_fowler_full.m4v Writing to 03_martin_fowler_full.m4v Content length: 413031533 bytes Read 0131826472 bytes It seems to update around every second, based on informal observation. I don't know why your output looks different; did you redirect or tee it to a file? I'm using an old 'C' trick of printing a CR (\r) after each update, which should keep the output on the same line and just overwrite what was there before. I'm running this using Ruby 1.8.5 on Ubuntu Edgy x86_64. Perhaps your OS is different and has some other behavior. I tried everything I could think of to disable or bypass buffering, including $stdout.sync = true, using $stderr, calling $stdout.flush, using syswrite, and so on, to get the output to appear periodically, without success. I think the output is buffered at the OS level, or something like that, so that even calling flush won't always work. The only thing that works for me is the progress hook. -- Posted via http://www.ruby-forum.com/.