cl-cookbook
cl-cookbook copied to clipboard
Copying a file
This is an efficient way of copying any kind of file, either character or binary.
(defun copy-file (from-file to-file)
"copy the file from-file into to-file"
(with-open-file (input-stream from-file
:direction :input
:element-type '(unsigned-byte 8))
(with-open-file (output-stream to-file
:direction :output
:if-exists :supersede
:if-does-not-exist :create
:element-type '(unsigned-byte 8))
(let ((buf (make-array 4096 :element-type (stream-element-type input-stream))))
(loop for pos = (read-sequence buf input-stream)
while (plusp pos)
do (write-sequence buf output-stream :end pos))))))