How to read in portions of a file as bit-vectors
Posted: Tue Apr 06, 2010 9:52 pm
Hi,
I've been redoing all of my introductory CS assignments in LISP, and have arrived at Huffman compression. It seems to me that the most obvious way to deal with sequences of bits is to put them in a bit vector. This works nicely until I want to read or write to files. I have not been able to figure out how to read or write data from an file a bit vector. Ideally I would like to read the entire file into one large bit vector (or write a large bit vector into a file), but I realize that this is obviously unrealistic. So what I am trying to to is find a way to read small portions of the file at a time, something akin to the following:
From what I have been able to discover, the only way to do this is to perform bit twiddling on integers using #'LDB and #'DPB, however that seems cumbersome.
Is what I want possible?
I've been redoing all of my introductory CS assignments in LISP, and have arrived at Huffman compression. It seems to me that the most obvious way to deal with sequences of bits is to put them in a bit vector. This works nicely until I want to read or write to files. I have not been able to figure out how to read or write data from an file a bit vector. Ideally I would like to read the entire file into one large bit vector (or write a large bit vector into a file), but I realize that this is obviously unrealistic. So what I am trying to to is find a way to read small portions of the file at a time, something akin to the following:
Code: Select all
(defparameter *file* (open "foo"))
(read-bits *file* 6) ; read 6 bits
(read-bits *file* 3) ; read 3 bits
Is what I want possible?