Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use buffering to speed up copy-file util. #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions utils.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,14 @@ location."
:test #'string=))

(defun copy-file (input output &key (if-exists :supersede))
(with-open-file (input-stream input)
(with-open-file (output-stream output :direction :output
(with-open-file (input-stream input :element-type '(unsigned-byte 8))
(with-open-file (output-stream output :element-type '(unsigned-byte 8)
:direction :output
:if-exists if-exists)
(loop for char = (read-char input-stream nil)
while char do (write-char char output-stream)))))
(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))))))

(defun file-lines (file)
(with-open-file (stream file)
Expand Down