Skip to content
Snippets Groups Projects
Commit 700ed97b authored by Attila Lendvai's avatar Attila Lendvai
Browse files

added read-file-into-byte-vector and write-byte-vector-into-file (until io.lisp's fate is decided)

parent 61cc0148
No related branches found
No related tags found
No related merge requests found
......@@ -77,6 +77,24 @@ unless it's NIL, which means the system default."
:external-format external-format)
(write-sequence string file-stream)))
(defun read-file-into-byte-vector (pathname)
"Read PATHNAME into a freshly allocated (unsigned-byte 8) vector."
(with-input-from-file (stream pathname :element-type '(unsigned-byte 8))
(let ((length (file-length stream)))
(assert length)
(let ((result (make-array length :element-type '(unsigned-byte 8))))
(read-sequence result stream)
result))))
(defun write-byte-vector-into-file (bytes pathname &key (if-exists :error)
if-does-not-exist)
"Write BYTES to PATHNAME."
(check-type bytes (vector (unsigned-byte 8)))
(with-output-to-file (stream pathname :if-exists if-exists
:if-does-not-exist if-does-not-exist
:element-type '(unsigned-byte 8))
(write-sequence bytes stream)))
(defun copy-file (from to &key (if-to-exists :supersede)
(element-type '(unsigned-byte 8)) finish-output)
(with-input-from-file (input from :element-type element-type)
......
......@@ -222,6 +222,8 @@
#:with-output-to-file
#:read-file-into-string
#:write-string-into-file
#:read-file-into-byte-vector
#:write-byte-vector-into-file
#:copy-stream
#:copy-file
;; new additions collected at the end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment