首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用drakma下载和保存文件:http-request和flexistreams

如何使用drakma下载和保存文件:http-request和flexistreams
EN

Stack Overflow用户
提问于 2012-09-27 01:30:09
回答 3查看 1.1K关注 0票数 4

我正在尝试下载并保存PDF,但在写入时失败,并出现EOF错误。这样做的正确方法是什么?

代码语言:javascript
复制
(with-open-file (file "/home/*/test.pdf"
                      :direction :io
                      :if-does-not-exist :create
                      :if-exists :supersede
                      :element-type '(unsigned-byte 8))
  (let ((input (drakma:http-request "http://www.fractalconcept.com/ex.pdf"
                                    :want-stream t)))
    (awhile (read-byte input)
      (write-byte it file))
    (close input)))
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2012-09-27 01:44:21

解决方案是我忘记使用read-byte的两个可选参数。

正确的方法是将eof-error-peof-value设置为nil

代码语言:javascript
复制
(with-open-file (file "/home/*/test.pdf"
                      :direction :output
                      :if-does-not-exist :create
                      :if-exists :supersede
                      :element-type '(unsigned-byte 8))
  (let ((input (drakma:http-request "http://www.fractalconcept.com/ex.pdf"
                                    :want-stream t)))
    (awhile (read-byte input nil nil)
      (write-byte it file))
    (close input)))
票数 8
EN

Stack Overflow用户

发布于 2012-09-29 20:27:45

在ARNESI包中可以找到一段时间。

票数 1
EN

Stack Overflow用户

发布于 2017-11-08 04:33:07

代码语言:javascript
复制
(ql:quickload "trivial-download")
(trivial-download:download URL FILE)

与您的代码几乎完全相同,但代码块更大,并且可以显示进度条。

;QuickLisp可以在http://QuickLisp.org上找到。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12607210

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档