Created
October 8, 2009 08:25
-
-
Save g000001/204860 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defpackage :home | |
(:use :cl) | |
(:export :wget)) | |
(in-package :home) | |
(defun wget (uri &optional (dir "./")) | |
(let* ((file-name (aref (nth-value 1 (ppcre:scan-to-strings ".*/([^/]*)$" uri)) 0)) | |
(out-file (concatenate 'string dir file-name))) | |
(format t "~A ==> ~A~%" uri out-file) | |
(with-open-file (out out-file | |
:direction :output | |
:if-exists :supersede | |
:element-type 'unsigned-byte) | |
(with-open-stream (str (drakma:http-request uri :want-stream 'T)) | |
(do ((s (read-byte str nil -1) (read-byte str nil -1)) | |
(cnt 0 (1+ cnt))) | |
((= -1 s) (format t "end ~A.~%" cnt)) | |
(write-byte s out) | |
(when (and (zerop (rem cnt 1024)) (not (zerop cnt))) | |
(princ ".") | |
(when (zerop (rem cnt (* 100 1024))) | |
(format t "~A~%" cnt)))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment