如何从Common Lisp/dexador中的http地址下载并保存图像?

Jos*_*hoi 2 http common-lisp

您如何从网站下载图像并将其保存到Common Lisp中的包文件夹中?我很难在dexador的文档中寻找这样的功能.

提前致谢

Sva*_*nte 6

你得到一个字节向量,所以只需保存它:

(let ((bytes (dex:get uri)))
  (with-open-file (out filename
                       :direction :output
                       :if-exists :supersede
                       :if-does-not-exist :create
                       :element-type 'unsigned-byte)
    (write-sequence bytes out)))
Run Code Online (Sandbox Code Playgroud)

如果您有太多数据,则可能需要使用缓冲流副本:

(let ((byte-stream (dex:get uri :want-stream t))
      (buffer (make-array buffer-size :element-type 'unsigned-byte)))
  (with-open-file (out filename
                       :direction :output
                       :if-exists :supersede
                       :if-does-not-exist :create
                       :element-type 'unsigned-byte)
    (loop :for p := (read-sequence buffer byte-stream)
          :while (plusp p)
          :do (write-sequence buffer out :end p))))
Run Code Online (Sandbox Code Playgroud)