Sim*_*Sim 4 common-lisp binary-data
我正在尝试下载并保存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)))
Run Code Online (Sandbox Code Playgroud)
解决方案是我忘了使用两个可选参数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)))
Run Code Online (Sandbox Code Playgroud)