What I want to do:
take the output of (drakma:http-request "someURL.jpg") and write it to a file. The output consists of a byte array.
What I came up with:
(with-open-file (my-stream "thing.jpg"
:direction :output
:element-type 'binary
:if-does-not-exist :create
:if-exists :supersede)
(let ((content (drakma:http-request "someURL.jpg")))
(loop for i across content do
(write-byte i my-stream))))
The error I get:
debugger invoked on a SIMPLE-ERROR in thread #<THREAD "initial thread" RUNNING
{1002978FB1}>:
could not find any output routine for :FULL buffered BINARY
I use SBCL 1.0.49. If you want any other info or find my question unclear then please, ask away :).
EDIT: The problem is the :element-type, it's supposed to be 'unsigned-byte. You can find information on the different possibilities of :element-type over at the Common Lisp Hyper Spec under open . Other than that everything is correct.
PS. I couldn't respond as an answer because my reputation is too low.
As Xach said, you're better off using '(unsigned-byte 8) (or make a type-definition , e.g. (deftype binary () '(unsigned-byte 8))).
In addition, you can probably replace your loop over the array and writing byte by byte with a call to write-sequence
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With