Skip to content

Instantly share code, notes, and snippets.

@g000001 g000001/gist:204860
Created Oct 8, 2009

What would you like to do?
(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
You can’t perform that action at this time.