Wanting to check out the clsql mailing list
(let ((stream (drakma:http-request "http://lists.b9.com/pipermail/
clsql/2008-August.txt.gz"
:want-stream t)))
(with-open-file (f "/tmp/mails.gz" :direction :output :element-
type '(unsigned-byte 8) :if-exists :supersede :if-does-not-
exist :create)
(loop for c = (read-byte stream)
while c do
(write-byte c f)))
(close stream))
Which should write the http://lists.b9.com/pipermail/clsql/2008-August.txt.gz
conten into the file /tmp/mails.gz
Or so I thought.
I've got an end of file error. Doesn't
while c
handle eof?
I finally let drakma:http-request return an array and wrote that array
into a file, no problem there.
However I'm wondering how to copy a stream into a file
i) correctly and
ii) possible faster than byte by byte
···············@gmail.com writes:
> (loop for c = (read-byte stream)
> while c do
> (write-byte c f)))
> (close stream))
...
> I've got an end of file error. Doesn't
> while c
> handle eof?
Well, yes. But the default handling of EOF by READ-BYTE is to signal an
error. See
<http://www.lispworks.com/documentation/HyperSpec/Body/f_rd_by.htm>
What you want is
(read-byte stream nil nil)
One rationale for that is that in the normal case, the return value
from READ-BYTE will always be a byte value.
> I finally let drakma:http-request return an array and wrote that array
> into a file, no problem there.
> However I'm wondering how to copy a stream into a file
> i) correctly and
a) Use the suggestion above
b) Use HANDLER-CASE to handle the EOF condition.
> ii) possible faster than byte by byte
use READ-SEQUENCE and WRITE-SEQUENCE
--
Thomas A. Russ, USC/Information Sciences Institute