4

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)))
4

3 に答える 3

8

解決策は、の2つのオプションパラメータを使用するのを忘れたことです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-26T17:44:21.267 に答える
1

AWHILEはパッケージARNESIに含まれています。

于 2012-09-29T12:27:45.203 に答える
1
(ql:quickload "trivial-download")
(trivial-download:download URL FILE)

; コードとほぼ同じように動作しますが、チャンクが大きくなり、プログレスバーが表示される場合があります。

; QuickLispはhttp://QuickLisp.orgで見つけることができます。

于 2017-11-07T20:33:06.990 に答える