Okay - <br><br>I found out the issue and solution - the output-port has to be explicitly closed in order for the pipe to know there are no more data coming through. I guess I misconstrue the meaning of "The ports do not need
to be explicitly closed" in <a href="http://docs.plt-scheme.org/reference/pipeports.html#(def._((quote._~23~25kernel)._make-pipe))">http://docs.plt-scheme.org/reference/pipeports.html#(def._((quote._~23~25kernel)._make-pipe))</a> .<br>
<br>Problem solved - thanks.<br>yc<br><br><div class="gmail_quote">On Thu, Sep 3, 2009 at 8:47 PM, YC <span dir="ltr"><<a href="mailto:yinso.chen@gmail.com">yinso.chen@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Update - <br><br>I was able to isolate the problem to just the pipe.<br><br><div style="margin-left: 40px;">(define-values (in out)<br> (make-pipe #f))<br>(write-bytes #"this is a test" out)<br>(read-bytes 14 in) ;; reads out #"this is a test"<br>
(read-bytes 1 in) ;; hangs. <br></div><br>It seems that unlike regular input-port, pipe does not produce #<eof> in this situation. How can I make the pipe generate #<eof>?<br><br>Thanks,<br><font color="#888888">yc</font><div>
<div></div><div class="h5"><br><br><div class="gmail_quote">
On Thu, Sep 3, 2009 at 7:37 PM, YC <span dir="ltr"><<a href="mailto:yinso.chen@gmail.com" target="_blank">yinso.chen@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi - <br><br>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. <br>
<br>Thanks,<br>yc<br><br>;; gzip.ss <br>#lang scheme/base<br>(require file/gunzip file/gzip mzlib/trace scheme/port)<br><br>(define (open-gzip-file path)<br> (let-values (((in out)<br> (make-pipe-with-specials #f path)))<br>
(thread (lambda ()<br> (call-with-input-file path<br> (lambda (in)<br> (gunzip-through-ports in out)))))<br> in))<br><br>(define (read-bytes* num in)<br> (read-bytes num in))<br>
<br>(trace read-bytes*)<br><br>(define (reader in)<br> (let loop ((b (read-bytes* 4096 in)))<br> (if (eof-object? b)<br> ;; (reverse acc)<br> (void)<br> (loop (read-bytes* 4096 in)))))<br><br>(provide reader open-gzip-file)<br>
<br>;; test ;; uncomment and run the two lines below in REPL <br>;; (require "gzip.ss")<br>;; (reader (open-gzip-file path-to-gzipped-file))<br>;; observe the it eventually hangs on calling read-bytes*.<br><br>
</blockquote></div><br>
</div></div></blockquote></div><br>