How to download and save a file using drakma: http-request and flexistreams

I am trying to download and save a PDF, but it does not work when writing with EOF-Error. What would be the right way to do 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))) 
+4
source share
3 answers

The solution was that I forgot to use two optional read-byte parameters.

The correct way is 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))) 
+7
source

AWHILE is in the ARNESI package.

+1
source
 (ql:quickload "trivial-download") (trivial-download:download URL FILE) 

; To a large extent, this is exactly what your code does, but in large chunks it can show a progress bar.

; QuickLisp can be found at http://QuickLisp.org .

0
source

Source: https://habr.com/ru/post/1436430/


All Articles