From: Rajinder Yadav Date: 2010-12-21T04:58:31+09:00 Subject: Re: downloading a file On Mon, Dec 20, 2010 at 2:43 PM, Quintus wrote: > Am 20.12.2010 19:19, schrieb Rajinder Yadav: >> i tired using open-uri, but when i read and then save the file it mess >> up the file? something like this >> >> require 'open-uri' >> url = 'http://www.openssl.org/source/openssl-1.0.0c.tar.gz' >> file = open(url) >> c = file.read >> >> f = File.open('openssl-1.0.0c.tar.gz', 'w') >> f.write c >> f.close > > Try > > file = open(url, "rb") > > instead of > > file = open(url) > > and > > f = File.open('openssl-1.0.0c.tar.gz', 'wb') > > instead of > > f = File.open('openssl-1.0.0c.tar.gz', 'w') > > . You're downloading a binary file, and Ruby will do bad things to > newlines in it if you don't pass the "b" for binary. > Additionally you should have a look at the block form of #open. > > Vale, > Marvin > > Thanks Vale, that makes sense, i also just found out I can use context_type() to figure out the file type! -- Kind Regards, Rajinder Yadav | DevMentor.org | Do Good! ~ Share Freely GNU/Linux: 2.6.35-22-generic Kubuntu x86_64 10.10 | KDE 4.5.1 Ruby 1.9.2p0 | Rails 3.0.1