From: "Mauricio Fernández" Date: 2004-05-16T20:17:42+09:00 Subject: [PATCH] tempfile.rb (was Re: Bug in open-uri under win32 (?)) On Sun, May 16, 2004 at 05:00:33PM +0900, Mauricio Fern�ndez wrote: > I'm told that this doesn't download the file correctly under windows > (only a few KB are dled). On visual inspection, the associated Tempfile > is not complete either, so the same behavior is observed when using > is.gets(nil) or a loop with eof?. The bug has been traced back to Tempfile, which doesn't use the binary mode for the underlying file. IMHO it should since the tempfile isn't meant to be seen by other processes, so CRLF translation (and other oddities such as ETB) makes no sense. --- tempfile.rb 2004-04-17 20:41:57.000000000 +0200 +++ tempfile.rb.new 2004-05-16 13:16:08.000000000 +0200 @@ -52,7 +52,9 @@ @clean_proc = Tempfile.callback(@data) ObjectSpace.define_finalizer(self, @clean_proc) - @tmpfile = File.open(tmpname, File::RDWR|File::CREAT|File::EXCL, 0600) + @tmpfile = File.open(tmpname, + File::RDWR|File::CREAT|File::EXCL| + (File::BINARY rescue 0), 0600) @tmpname = tmpname @@cleanlist << @tmpname @data[1] = @tmpfile @@ -66,10 +68,10 @@ Dir.rmdir(lock) end - # Opens or reopens the file with mode "r+". + # Opens or reopens the file with mode "rb+". def open @tmpfile.close if @tmpfile - @tmpfile = File.open(@tmpname, 'r+') + @tmpfile = File.open(@tmpname, 'rb+') @data[1] = @tmpfile __setobj__(@tmpfile) end -- Running Debian GNU/Linux Sid (unstable) batsman dot geo at yahoo dot com Are Linux users lemmings collectively jumping off of the cliff of reliable, well-engineered commercial software? -- Matt Welsh