将 drakma http-request 数组写入文件

发布于 2024-11-27 06:43:07 字数 893 浏览 1 评论 0原文

我想做的: 获取 (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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苦笑流年记忆 2024-12-04 06:43:08

正如 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文