[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] stream trouble
From: |
Alejandro Forero Cuervo |
Subject: |
Re: [Chicken-users] stream trouble |
Date: |
Tue, 4 Oct 2005 16:55:16 -0500 |
User-agent: |
Mutt/1.5.9i |
> But it has to allocate the entire string whereas I'd rather "stream"
> the stream out the TCP connection in chunks. So I try this:
>
> <?scheme
> (let ([inp (open-input-file "/var/www/localhost/htdocs/wiki/index.wiki")])
> (require-extension stream-wiki)
> (let loop ([hstr (wiki->html (port->stream inp))])
> (unless (stream-null? hstr)
> (display (stream-car hstr))
> (loop (stream-cdr hstr)))))
> ?>
You can use write-stream, which does exactly this:
<?scheme
(use stream-wiki)
(write-stream (wiki->html (port->stream (open-input-file "somefile"))))
?>
> But if it really sends a character at a time over TCP, it won't be
> very efficient network-wise, and anyway even if it's buffered, maybe
> each call to display is a system call?
I haven't verified whether the output is buffered. I would agree
with you that things would be *extremely* inefficient if it isn't
buffered. If someone confirms it isn't, I suppose we could always
write a write-stream-buffered function that writes things N characters
at a time.
Alejo.
http://azul.freaks-unidos.net/
---=( Comunidad de Usuarios de Software Libre en Colombia )=---
---=( http://bachue.com/colibri )=--=( address@hidden )=---