将 drakma http-request 数组写入文件
我想做的: 获取 (drakma:http-request "someURL.jpg")
的输出并将其写入文件。输出由字节数组组成。
我想到了什么:
(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))))
我得到的错误:
debugger invoked on a SIMPLE-ERROR in thread #<THREAD "initial thread" RUNNING
{1002978FB1}>:
could not find any output routine for :FULL buffered BINARY
我使用 SBCL 1.0.49。 如果您想要任何其他信息或发现我的问题不清楚,请询问:)。
编辑: 问题是:元素类型,它应该是“无符号字节”。 您可以在 Common Lisp Hyper Spec 的
附言。我无法回复作为答案,因为我的声誉太低。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如 Xach 所说,你最好使用
'(unsigned-byte 8)
(或进行类型定义,例如(deftype binary () '(unsigned-byte 8))< /代码>)。
此外,您可以通过调用 write-sequence 来替换数组上的循环并逐字节写入
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