From: Xavier Noria Date: 2003-09-11T06:25:55+09:00 Subject: Re: windows line termination On Wednesday 10 September 2003 21:49, Chris Morris wrote: > Still don't know if that quells my rant. I assume that the default \n > is used in memory at all times, and Ruby will handle the appropriate > translation for *nix/Windows/Mac, freeing me from worrying over that? > And the case I stumbled upon today was a leaky abstraction? When you read/write a text file Ruby (as C or Perl) lets you see a newline as "\n", a single character. Unless you do I/O in binmode that happens transparently behind the scenes, and in some platforms as Unix nothing needs to be done indeed. That way one can easily write text-oriented portable code, print "\n" will do the right thing anywhere. The problem you faced has to do with the HTTP specs. HTTP headers, for instance, have to be separated by CRLF, that is \015\012 because that's required. So if you wrote an HTTP server written in Ruby with code like socket.print("Location: ${location}\n") # broken that server wouldn't be portable. In such cases you have to manually ensure that the CRLF travels well, untouched. And that usually means you put the handle in binmode (which turns off that transalation) and print exactly what's needed. The newlines for the body of an HTTP message with text (i.e., a normal HTML page) need not be CRLF, but in the kind of data you were uploading that's required (in my understanding of the RFC). -- fxn