r10035:
authorKevin M. Rosenberg <kevin@rosenberg.net>
Sat, 25 Sep 2004 13:32:14 +0000 (13:32 +0000)
committerKevin M. Rosenberg <kevin@rosenberg.net>
Sat, 25 Sep 2004 13:32:14 +0000 (13:32 +0000)
io.lisp
package.lisp
strings.lisp

diff --git a/io.lisp b/io.lisp
index ba68048739c57e4ff55b4138d8e48e6308af95cc..aedca9942a166d716bf11f44c227d711176ee105 100644 (file)
--- a/io.lisp
+++ b/io.lisp
     (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)))             
     (write-char #\: stream)
     (write-string (aref +datetime-number-strings+ minute) stream)))
 
-(defun copy-binary-stream (in out)
-  (do* ((buf (make-array 4096 :element-type '(unsigned-byte 8)))
+(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)))
index fe5e7a4ecb8b73d99cf31d00423adad3f8c7d6ab..5f10fb9a8071370d3de7d415d2e49e68dc351cde 100644 (file)
    #:print-file-contents
    #:read-stream-to-string
    #:read-file-to-string
+   #:read-file-to-usb8-array
    #:read-stream-to-strings
    #:read-file-to-strings
    
index 0c5ae7c4ec47407e0e77b358a1bf4c713dee89b2..a9b3d0f9b320a95126b206348e852d812ea8a9b2 100644 (file)
@@ -227,17 +227,20 @@ list of characters and replacement strings."
 (defun make-usb8-array (len)
   (make-array len :element-type '(unsigned-byte 8)))
 
-(defun usb8-array-to-string (vec)
-  (declare (type (simple-array (unsigned-byte 8) (*)) vec))
-  (let* ((len (length vec))
+(defun usb8-array-to-string (vec &key (start 0) end)
+  (declare (type (simple-array (unsigned-byte 8) (*)) vec)
+          (fixnum start))
+  (unless end
+    (setq end (length vec)))
+  (let* ((len (- end start))
         (str (make-string len)))
     (declare (fixnum len)
             (simple-string str)
-            (optimize (speed 3)))
+            (optimize (speed 3) (safety 0)))
     (do ((i 0 (1+ i)))
        ((= i len) str)
       (declare (fixnum i))
-      (setf (schar str i) (code-char (aref vec i))))))
+      (setf (schar str i) (code-char (aref vec (the fixnum (+ i start))))))))
 
 (defun string-to-usb8-array (str)
   (declare (simple-string str))