On Thursday, February 7, 2019 at 1:56:13 PM UTC-8, Jim Newton wrote:
> I have opened a file with :element-type 'unsigned byte, and I want
> to copy some of the bytes I read into as string, so I can read them
> back out using a different :element-type.
Perhaps you should use READ-SEQUENCE to read the data from the file into a
sequence with the element type 'unsigned-byte. You can then do various things
with that data, including extracting some of the bytes and converting them
to some different type.
Depending on what sort of type conversion you need to do, you may have to
handle the coercion yourself or else perhaps use the library Pascal suggested.
A simple example, where /tmp/foo.text contains
This is some data.
(defvar *buffer* (make-array 1000 :element-type 'unsigned-byte))
(with-open-file (f "/tmp/foo.text" :element-type 'unsigned-byte)
(read-sequence *buffer* f))
(with-output-to-string (s)
(write-sequence (map 'list #'code-char (subseq *buffer* 2 10)) s))
=> "is is da"