From c42934d07b03d727ea436c37ef0ced2b4a8d9fff Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Wed, 26 Oct 2011 19:11:41 -0400 Subject: [PATCH] Uncook newlines into CRLFs on the way out. --- cook-port.rkt | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/cook-port.rkt b/cook-port.rkt index d7246eb..cbca4d9 100644 --- a/cook-port.rkt +++ b/cook-port.rkt @@ -64,4 +64,19 @@ (lambda (new-b feedback) (write-string feedback raw-out) (loop new-b)))))))))) - (values cooked-in raw-out)) + (values cooked-in (cook-output raw-out))) + +(define (cook-output raw-out) + (define-values (cooked-in cooked-out) (make-pipe)) + (thread + (lambda () + (define buffer (make-bytes 4096)) + (let loop () + (define count (read-bytes-avail! buffer cooked-in)) + (if (eof-object? count) + (begin (close-input-port cooked-in) + (close-output-port raw-out)) + (let ((raw-data (regexp-replace* #"\n" (subbytes buffer 0 count) #"\r\n"))) + (write-bytes raw-data raw-out) + (loop)))))) + cooked-out)