[plt-scheme] gzipped file + pipe hangs at the end

From: YC (yinso.chen at gmail.com)
Date: Thu Sep 3 22:37:59 EDT 2009

Hi -

I am trying to pipe a gzipped file and it seems to hang at the end when I am
trying to read the data.  It's unclear to me why it hangs at the end (I
observed this by seeing it hangs immediately with small files, read quite a
bit of data with medium files, and read lots of data with large files before
it hangs), and hopefully others can see what I am missing here.

Thanks,
yc

;; gzip.ss
#lang scheme/base
(require file/gunzip file/gzip mzlib/trace scheme/port)

(define (open-gzip-file path)
  (let-values (((in out)
                (make-pipe-with-specials #f path)))
    (thread (lambda ()
              (call-with-input-file path
                (lambda (in)
                  (gunzip-through-ports in out)))))
    in))

(define (read-bytes* num in)
    (read-bytes num in))

(trace read-bytes*)

(define (reader in)
  (let loop ((b (read-bytes* 4096 in)))
    (if (eof-object? b)
        ;; (reverse acc)
        (void)
        (loop (read-bytes* 4096 in)))))

(provide reader open-gzip-file)

;; test ;; uncomment and run the two lines below in REPL
;; (require "gzip.ss")
;; (reader (open-gzip-file path-to-gzipped-file))
;; observe the it eventually hangs on calling read-bytes*.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20090903/51955696/attachment.html>

Posted on the users mailing list.