我正在尝试下载并保存PDF,但在写入时失败,并出现EOF错误。这样做的正确方法是什么?
(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)))发布于 2012-09-27 01:44:21
解决方案是我忘记使用read-byte的两个可选参数。
正确的方法是将eof-error-p和eof-value设置为nil
(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)))发布于 2012-09-29 20:27:45
在ARNESI包中可以找到一段时间。
发布于 2017-11-08 04:33:07
(ql:quickload "trivial-download")
(trivial-download:download URL FILE)与您的代码几乎完全相同,但代码块更大,并且可以显示进度条。
;QuickLisp可以在http://QuickLisp.org上找到。
https://stackoverflow.com/questions/12607210
复制相似问题