From: Tobias Peters Date: 2002-12-30T01:11:17+09:00 Subject: Re: WARN: mswin32 build binary file read change of behavior Milan Maksimovic wrote: > Maybe putting it in a FAQ isn't a bad idea. Programmer's have to deal with the automatic [LF] <=> [CRLF] conversion on DOS/Windows based systems regardless of the programming language they use. Your experience is not specific to Ruby. Better start to deal with it, and add the binary file indicator to any binary file opening operation, if your code might be executed on a DOS/Windows system. > On cygwin builds: > > File.open( 'somebinaryfile.bin' ) do | file | > binaryContent = file.read() > end > > worked fine, i.e. it read all that it should have. Cygwin has an installation option how it should handle text files: same as on unix (i.e. all files are effectively treated as binary), or same as on a DOS system. You had luck and chose the unix option. > In mswin32 builds one must explicitly specify "rb" flags. > > File.open( 'somebinaryfile.bin', "rb" ) > > or the file will be truncated. Of course. If you want binary, then by all means say so. It's not ruby's fault that Billyboy had to introduce this trap for you. > I suppose it would be good to have it fixed in mswin32 build, since a major No! Ruby is not the place to fix OS design flaws. We would get user complaints like "I cannot open the textfile output from your ruby script in my notepad editor" if ruby would attempt to "fix" it. (Try it!) > practical consequence is that libraries and programs that don't take this > into consideration (like those done on Unix flavors and used on Win32) will > break. Yes, this is a problem. But the fix for it has to be done in these libraries. Send a bug report to the author of the library. T