From: Bill Kelly Date: 2004-08-25T09:03:15+09:00 Subject: Re: Weird behavior with IO#read Hi, From: "Lennon Day-Reynolds" > > Okay, maybe I just need to take a break from coding for a couple of > hours, but I can't for the life of me figure out what's going wrong > with this code: > > -- > BLOCKSIZE=1024*256 > open('testdata.in') do |input| > open('testdata.out') do |output| > while (chunk = input.read(BLOCKSIZE)) do > output.write(chunk) > end > end > end > -- > > On Linux with 1.8.2-preview2, it works as expected (and much faster > than I anticipated, which is good). On Windows XP using the latest > one-click, it terminates after a single iteration through the 'while' > loop. Changing the blocksize doesn't make a difference; neither does > using a different looping construct. Is there binary data in the files? If so try opening them in binary mode ("rb" and "wb")... Windows sees ^Z as end of file in "text mode"... an artifact stupidly inherited from a filesystem that needed it because it only measured file sizes in blocks and didn't know where the precise end of file was without the marker character. ("Stupidly inherited" because windows has never needed that to know where the true end of file is.) Hope this helps, Regards, Bill