Skip to content

Instantly share code, notes, and snippets.

@juan-reynoso
Created October 29, 2021 22:05
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 juan-reynoso/9f2e137cd3b32d33068c674e4896db42 to your computer and use it in GitHub Desktop.
Save juan-reynoso/9f2e137cd3b32d33068c674e4896db42 to your computer and use it in GitHub Desktop.
Creating streams on files
(defun copy-a-file (origin-path new-path)
"Copy a file"
(let ((value-from-read-byte nil))
;; create a stream which reads a file
(with-open-file (origin-file origin-path :direction :input
:element-type 'unsigned-byte)
;; create a stream which write into a file
(with-open-file (new-file new-path :direction :output
:element-type 'unsigned-byte
:if-exists :supersede)
;; Here we read the origin file and writing into the new file
(loop
;; exit when get :eof "end of file"
(when (equal value-from-read-byte :eof) (return nil))
;; reading the data
(setf value-from-read-byte (read-byte origin-file nil :eof))
;; writing the data; in other words copy a file
(unless (equal value-from-read-byte :eof)
(write-byte value-from-read-byte new-file)))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment