Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
;; 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
Something went wrong with that request. Please try again.