Created
January 9, 2012 20:01
-
-
Save ijp/1584643 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; rough conception - chunks output only | |
(use-modules (ice-9 q)) | |
(define (q-for-each f q) | |
(while (not (q-empty? q)) | |
(f (deq! q)))) | |
(define f! #f) | |
(define (port->chunking-port port) | |
(define queue (make-q)) | |
(define (put-char c) | |
(enq! queue c)) | |
(define (put-string s) | |
(string-for-each (lambda (c) (enq! queue c)) | |
s)) | |
(define (flush) | |
(let ((len (q-length queue))) | |
(display (number->string len 16) port) | |
(display "\r\n" port) | |
(q-for-each (lambda (elem) (write-char elem port)) | |
queue) | |
(display "\r\n" port))) | |
(define (get-char) | |
(read-char port)) | |
(define (close) | |
(flush) | |
(flush) ;; this way a zero chunk gets written | |
(close-port port)) | |
(set! f! flush) | |
(make-soft-port | |
(vector | |
put-char | |
put-string | |
flush | |
get-char | |
close) | |
"rw")) | |
(call-with-output-string | |
(lambda (out-raw) | |
(let ((out-chunked (port->chunking-port out-raw))) | |
(display "First chunk" out-chunked) | |
(flush-all-ports) | |
(f!) | |
;(force-output out-chunked) | |
(display "Second chunk" out-chunked) | |
(f!) | |
;(force-output out-chunked) | |
(display "Third chunk" out-chunked) | |
(f!) | |
(f!) | |
;(close-port out-chunked) | |
))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment