From: Robert Dober Date: 2009-08-19T16:31:25+09:00 Subject: Re: fromdos dos2unix in ruby On Wed, Aug 19, 2009 at 12:38 AM, Xavier Noria wrote: > On Tue, Aug 18, 2009 at 11:39 PM, Robert Dober wrote: > >> Yup, I thought my code solved the issue, tell Ruby that a line ends >> with "\n" ( that was tough to type ;) in each and replace a potential >> "\r" before? >> But maybe this does not work on binary files under Windows, no way to >> test, sorry. > > The idea is good, but this topic is brittle (though easy when you get > the facts straight). > > Problem is on CRLF platforms the I/O system filters out the CR of any > pair CRLF before the string arrives to Ruby land. That is, if you work > in text-mode. In fact that is the definition of text-mode, that the > conversion is on. > > When you write in text mode in a CRLF platform, the I/O system > monitors the stream of bytes, and inserts a CR every time he sees an > LF. Unconditionally. > > On Unix these conversions do not happen, text-mode and binary-mode are > the same, and Unix uses LF on disk to mean a newline. > > And the point is those conversions happen in text-mode *no matter > which is the input record separator*, so in those solution the file > opened for reading should be opened in binary mode anyway. If you > don't do this, a file that has on disk But I did open it in binary mode, did I not? Anyway, if I had a typo in my snippet, thanx for the correction. The only issue I can see is the following Newline = "\n" || 10.chr || "\012" || ";-)" file.open( "...", "rb"){ | f | f.each( Newline ) { ... ####### ^ ####### Does this work on Windows? Cheers Robert