From: Robert Dober Date: 2009-08-19T06:39:29+09:00 Subject: Re: fromdos dos2unix in ruby On Tue, Aug 18, 2009 at 10:39 PM, Xavier Noria wrote: > On Tue, Aug 18, 2009 at 10:15 PM, Robert > Klemme wrote: > >> WIN_LE = "\r\n".freeze >> >> File.open ARGV[0] do |in| >>  File.open ARGV[1], "wb" do |out| >>    in.each do |line| >>      line.chomp! >>      out.print line, WIN_LE > > Hey but this is dos2unix :-). > > You can't read in text-mode just like that in a portable way, because > chomp! only chomps "\n". > > If you can assume the program is gonna run only on Windows then the > solution is trivial: read in text-mode, and write in binary mode. No > chomping or gsubs needed, just read and write. > > If the program has to be portable then you need to deal with the > spurious \015 that may come up. 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. Cheers Robert