From: Rajinder Yadav Date: 2010-12-21T05:10:57+09:00 Subject: Re: downloading a file On Mon, Dec 20, 2010 at 2:58 PM, Rajinder Yadav wrote: > 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! > Thanks Marvin, tired eyes got the name wrong =) -- Kind Regards, Rajinder Yadav