X-Git-Url: http://git.kpe.io/?p=kmrcl.git;a=blobdiff_plain;f=io.lisp;h=aedca9942a166d716bf11f44c227d711176ee105;hp=75ee65087b1c3ccd78ed37749818e5de5c6c3556;hb=f03310d76a2458e5efb45b89f8e6b087db7f4ed1;hpb=7808e314e1cc884ca3b86cc6936138f97b4f2a2e diff --git a/io.lisp b/io.lisp index 75ee650..aedca99 100644 --- a/io.lisp +++ b/io.lisp @@ -43,6 +43,17 @@ (with-open-file (in file :direction :input) (read-stream-to-string in)))) +(defun read-file-to-usb8-array (file) + "Opens a reads a file. Returns the contents as single unsigned-byte array" + (with-open-file (in file :direction :input) + (let* ((file-len (file-length in)) + (usb8 (make-array file-len :element-type '(unsigned-byte 8))) + (pos (read-sequence usb8 in))) + (unless (= file-len pos) + (error "Length read (~D) doesn't match file length (~D)~%" pos file-len)) + usb8))) + + (defun read-stream-to-strings (in) (let ((lines '()) (eof (gensym))) @@ -311,4 +322,9 @@ (write-char #\: stream) (write-string (aref +datetime-number-strings+ minute) stream))) +(defun copy-binary-stream (in out &key (chunk-size 4096)) + (do* ((buf (make-array chunk-size :element-type '(unsigned-byte 8))) + (pos (read-sequence buf in) (read-sequence buf in))) + ((zerop pos)) + (write-sequence buf out :end pos)))