I am trying to download and save a PDF but it fails while writing with an EOF-Error. What would be the correct way of doing this?
(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)))
The solution was that I forgot to use the two optional parameters of read-byte
.
The correct way would be to set eof-error-p
and eof-value
to 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)))
(ql:quickload "trivial-download")
(trivial-download:download URL FILE)
; Does pretty much exactly what your code does but in bigger chunks and can show a progress bar.
; QuickLisp can be found at http://QuickLisp.org.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With