From: Eric Hodel Date: 2006-12-24T07:07:43+09:00 Subject: Re: Question: Downloading files with open(-uri)? On Dec 23, 2006, at 07:35, Mariano Kamp wrote: > Edwin Fine wrote: >> William James wrote: >> urls.each do |url| >> puts "downloading #{url}" >> out_file = url.split(/\//).last >> puts "Writing to #{out_file}" >> >> open(url, "r", >> :content_length_proc => lambda {|content_length| puts "Content >> length: #{content_length} bytes" }, >> :progress_proc => lambda { |size| printf("Read %010d bytes\r", >> size.to_i) }) do |input| >> open(out_file, "wb") do |output| >> while (buffer = input.read(BUFFER_SIZE)) >> 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. ri OpenURI::OpenRead#open -- Eric Hodel - drbrain@segment7.net - http://blog.segment7.net I LIT YOUR GEM ON FIRE!