From: Austin Ziegler Date: 2005-10-26T01:03:52+09:00 Subject: Re: ruby gives different answer for checksum of files on windows and FreeBSD? On 10/25/05, Michael Campbell wrote: > "Ara.T.Howard" writes: >> On Tue, 25 Oct 2005, Yukihiro Matsumoto wrote: >>> Hi, >>> In message "Re: ruby gives different answer for checksum of files on >>> windows and FreeBSD?" on Tue, 25 Oct 2005 17:37:02 +0900, Ralph >>> Smith writes: >>>| f = File.new(fname) >>> Try >>> >>> f = File.new(fname, "rb") >>> >>> and see how it works. >> this comes up so often - would it make sense to be the default mode >> on windows? > I'm guessing here, but my guess is that reading text files with ruby > is more common than non-text files. Does "rb" affect that? Some. I *always* open files in Ruby with "rb" or "wb" on Windows. Here's the difference, though: irb(main):001:0> File.open("test.txt", "w") { |ff| irb(main):002:1* ff.write <<-EOS irb(main):003:1" Now is the time irb(main):004:1" for all good people irb(main):005:1" to rock. irb(main):006:1" EOS irb(main):007:1> } => 47 irb(main):008:0> a = File.open("test.txt", "r") { |ff| ff.read } => "Now is the time\n for all good people\nto rock.\n" irb(main):009:0> b = File.open("test.txt", "rb") { |ff| ff.read } => "Now is the time\r\n for all good people\r\nto rock.\r\n" Note that a has only \n and b has \r\n. With "r", Ruby translates away the \r\n to \n only; with "rb" you have to look out for it yourself. A simple #chomp (or #chomp!) operation, however, will eliminate both \n and \r\n. -austin -- Austin Ziegler * halostatue@gmail.com * Alternate: austin@halostatue.ca