Common lisp 如何使用drakma:http请求和flexistreams下载和保存文件
我正在尝试下载并保存PDF,但在写入时失败,出现EOF错误。 正确的做法是什么Common lisp 如何使用drakma:http请求和flexistreams下载和保存文件,common-lisp,binary-data,Common Lisp,Binary Data,我正在尝试下载并保存PDF,但在写入时失败,出现EOF错误。 正确的做法是什么 (with-open-file (file "/home/*/test.pdf" :direction :io :if-does-not-exist :create :if-exists :supersede :element-type '(u
(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)))
解决方案是我忘记使用两个可选参数
readbyte
正确的方法是将eof-error-p
和eof值
设置为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)))
在ARNESI包中发现了一段时间
(ql:quickload "trivial-download")
(trivial-download:download URL FILE)
);它的功能与代码的功能几乎完全相同,但更大的块可以显示进度条
);QuickLisp位于。因为您只是在输出,所以应该使用
:方向:输出
。