Function: COPY-FILE

Source

(defun copy-file (from to &key (if-to-exists :supersede)
                               (element-type '(unsigned-byte 8)))
  (with*
   (with-input-from-file (input  from :element-type element-type))
   (with-output-to-file  (output to   :element-type element-type
                                      :if-exists if-to-exists))
   (progn
     (loop
        with buffer-size = 4096
        with buffer = (make-array buffer-size :element-type element-type)
        for bytes-read = (read-sequence buffer input)
        while (= bytes-read buffer-size)
        do (write-sequence buffer output)
        finally (write-sequence buffer output :end bytes-read)))))
Source Context