2012-09-26 3 views
4

PDF를 다운로드하고 저장하려고하지만 EOF 오류로 쓰는 동안 오류가 발생합니다. 이 작업을 수행하는 올바른 방법은 무엇입니까?drakma : http-request 및 flexistreams를 사용하여 파일을 다운로드하고 저장하는 방법

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

답변

7

해결책은 두 개의 선택적 매개 변수 read-byte을 사용하는 것을 잊었습니다.

(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))) 
+1

출력하는 중이므로': direction : output'을 사용해야합니다. – Svante

1

잠시이 패키지 ARNESI에서 발견된다 :

올바른 방법은 eof-error-peof-valuenil로 설정하는 것입니다.

0
(ql:quickload "trivial-download") 
(trivial-download:download URL FILE) 

; 코드가하는 일을 꽤 많이 수행하지만 더 큰 덩어리로 진행 막대를 표시 할 수 있습니다.

; QuickLisp은 http://QuickLisp.org에서 찾을 수 있습니다.