Skip to content

Instantly share code, notes, and snippets.

@g000001
Created October 8, 2009 08:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save g000001/204860 to your computer and use it in GitHub Desktop.
Save g000001/204860 to your computer and use it in GitHub Desktop.
(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