Suppose I have some utility functions defined as:
(defun write-bytes-to-file (bytes file-path bits)
(with-open-file (stream file-path
:direction :output
:if-does-not-exist :create
:if-exists :append
:element-type (list 'unsigned-byte bits))
(dolist (b bytes))
(write-byte b stream))))
(defun read-file-bytes-to-list (file-path bits)
(with-open-file (stream file-path :direction :input :element-type (list 'unsigned-byte bits))
(read-bytes-to-list stream nil)))
Furthermore, let's say I run:
(write-bytes-to-file '(65 65 65) "foo.txt" 8)
(write-bytes-to-file '(512) "foo.txt" 9)
Now this leaves me with a variable byte-width file with three 8-bit bytes, and one with 9-bit width. Normally I'd use my read-file-bytes-to-list function with a bit-width input to read the file with the correct alignment, but in this case I can't really do that. Is there a built-in way I can change the byte alignment mid-stream in Common LISP? Essentially I'd like to read the integers back as intended (65, 65, 65, and 512). Thanks for your help. I'm using the SBCL implementation.
EDIT: If there is no convenient way to handle this using the standard LISP libraries/utilities, I realize that I most likely will have to handle this with bit-wise operations; that's fine. I was just wondering if there is a better way to do it, before doing so.