我正在尝试下载并保存PDF,但在使用EOF-Error写入时失败。 这样做的正确方法是什么?
(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)))
答案 0 :(得分:7)
解决方案是我忘了使用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)))
答案 1 :(得分:1)
AWHILE包含在ARNESI包中。
答案 2 :(得分:1)
(ql:quickload "trivial-download")
(trivial-download:download URL FILE)
几乎完全是你的代码所做的,但是在更大的块中,并且可以显示进度条。
可以在http://QuickLisp.org找到QuickLisp。