From: Tim Hunter Date: 2008-09-03T22:22:12+09:00 Subject: Re: downloading files Marcelo Barbudas wrote: > Hi, > > Which is the proper way to download a binary file? > > Trying: > open(temp_path,"w").write(open(http_path).read) > > returns truncated files > > Cheers, > M. > > Are you on Windows? Try opening the output file as "wb" instead of just "w". Here's a snippet from my RMagick OS X installer script. Ara Howard gave me the code. 'uri' is the input URI, something like "http://rubyforge.org/frs/download.php/39890/RMagick-2.5.2.tar.gz" begin open(uri) do |fin| open(File.basename(uri), "w") do |fout| while (buf = fin.read(8192)) fout.write buf end end end rescue Timeout::Error abort <<-END_HTTP_DL_TIMEOUT A timeout occurred while downloading #{uri}. Probably this is a temporary problem with the host. Try again later. END_HTTP_DL_TIMEOUT end -- RMagick: http://rmagick.rubyforge.org/