[racket] "Streaming" gunzip-through-ports hangs?
On Tue, Jan 22, 2013 at 12:40 PM, Greg Hendershott
<greghendershott at gmail.com> wrote:
> I'd like to take an input-port that I know has gzip encoded bytes, and
> return a new input-port port that will return the decoded bytes. I
> don't want to suck the entire bytes into memory. Instead I want to
> "stream" them as-needed.
>
> It _seems_ like I could do this is with a combination of `make-pipe`
> and `gunzip-through-ports`.
>
> But at the end, instead of getting `eof` the program hangs.
>
> Does anyone see what I'm doing wrong?
You may want to add a call to close-output-port after the gunzip;
otherwise, the pipe's still open, and blocking for additional
content.
;;;;;;;;;;;;;;
(define (make-gzip-decoding-input-port in [limit #f])
(define-values (pin pout) (make-pipe limit 'gunzip-pipe 'gunzip-pipe))
(thread (lambda ()
(gunzip-through-ports in pout)
(close-output-port pout))) ;; <--- here
pin)
;;;;;;;;;;;;;;
Best of wishes!