[racket] Question about open-output-file

From: YC (yinso.chen at gmail.com)
Date: Sun Dec 5 04:11:18 EST 2010

Another approach is to read the port in line by line via read-line with
'any, which removes the line terminator for you, and then you can add the
os-specific line terminator, below shows how to do so with +:windows.

(require (planet bzlib/os)) ;; use +:windows to specify os-based branching

(define (copy-lines in out) ;; out is in binary mode
  (let loop ((line (read-line in 'any)))
    (unless (eof-object? line)
      (write-string (format (+:windows "~a\r\n" "~a\n") ;; if windows use
\r\n, else use \n
                            line) out)
      (loop (read-line in 'any)))))


On Sun, Dec 5, 2010 at 12:42 AM, Noel Welsh <noelwelsh at gmail.com> wrote:

> My guess is the LF in the source is being converted to CRLF, and
> indeed this is what the docs state. I think doing a regexp-replace*
> directly on the port is probably the easiest and most efficient thing
> to do.
> HTH,
> N.
> On Sun, Dec 5, 2010 at 8:01 AM, Michael Coppola
> <coppola.mi at husky.neu.edu> wrote:
> > Hi everyone,
> >
> > I am using the function "open-output-file" in conjunction with
> > "copy-port" to take incoming data from a TCP port and write it to a
> > file, but I am running into an issue.  In my code, I offer the user the
> > option of saving the file by means o...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20101205/f307f247/attachment.html>

Posted on the users mailing list.