[plt-scheme] Re: gzipped file + pipe hangs at the end
Okay -
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
http://docs.plt-scheme.org/reference/pipeports.html#(def._((quote._~23~25kernel)._make-pipe)).
Problem solved - thanks.
yc
On Thu, Sep 3, 2009 at 8:47 PM, YC <yinso.chen at gmail.com> wrote:
> Update -
>
> I was able to isolate the problem to just the pipe.
>
> (define-values (in out)
> (make-pipe #f))
> (write-bytes #"this is a test" out)
> (read-bytes 14 in) ;; reads out #"this is a test"
> (read-bytes 1 in) ;; hangs.
>
> It seems that unlike regular input-port, pipe does not produce #<eof> in
> this situation. How can I make the pipe generate #<eof>?
>
> Thanks,
> yc
>
>
> On Thu, Sep 3, 2009 at 7:37 PM, YC <yinso.chen at gmail.com> wrote:
>
>> 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/891059a5/attachment.html>