[racket] Question about open-output-file

From: Michael Coppola (coppola.mi at husky.neu.edu)
Date: Sun Dec 5 12:43:44 EST 2010

Thanks Noel and YC for your quick replies.

I'm testing out your code, YC, and it seems like it's exactly what I
need.  I wasn't aware of bzlib/os, so that was really helpful.  Thank you!


On 12/05/2010 04:11 AM, YC wrote:
> 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)))))
> Cheers,
> yc
> On Sun, Dec 5, 2010 at 12:42 AM, Noel Welsh <noelwelsh at gmail.com
> <mailto: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 <mailto: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/7eb08eaf/attachment.html>

Posted on the users mailing list.