Created
October 29, 2021 22:05
-
-
Save juan-reynoso/9f2e137cd3b32d33068c674e4896db42 to your computer and use it in GitHub Desktop.
Creating streams on files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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