From: Tim Hammerquist Date: 2003-09-23T00:10:06+09:00 Subject: Re: Trouble with binary files? Benjamin Peterson graced us by uttering: > Tim Hammerquist wrote: >> However, (for backward compatibility?) when the ^Z *is* >> encountered in a textmode file, > > ...or, better yet, when any text character whose encoding > happens to include an 0x1a is encountered! My, that *was* > annoying. Multi-byte encodings weren't recognized as "text files" by DOS/Win until fairly recently, if currently (I don't use them), so I probably wouldn't have tried to get away with it. >> As someone else mentioned above, this isn't an issue on Unix >> or many other systems, > > Or indeed on Windows, provided you avoid ruby :I No, Perl has a binmode() function as well, for exactly this issue. This question's asked on c.l.p.m almost weekly. >> The moral of the story is: >> >> Always call fh.binmode() before reading >> any non-text file on non-Unix platforms. > > You have to call it before reading *any* file, unless you just > know that only ASCII was used, for the reason above. I think > ruby is the only software I've ever used that has this issue. > I suppose ruby must check for the 0x1a *before* allowing for > the encoding system. AFAIK, Ruby just calls the system read calls, as do all the other scripting languages. If there's any "magic" in the Ruby implementation, that would be interesting to see. How about: | Always call fh.binmode() before reading any non-7-bit-clean | file on non-Unix platforms. Cheers, Tim Hammerquist -- It's there as a sop to former Ada programmers. :-) -- Larry Wall regarding 10_000_000 in <11556@jpl-devvax.JPL.NASA.GOV>