From ... Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.online.be!newsfeed.esat.net!nslave.kpnqwest.net!nloc.kpnqwest.net!nmaster.kpnqwest.net!nreader3.kpnqwest.net.POSTED!not-for-mail Newsgroups: comp.lang.lisp Subject: Re: Question about open/read-byte... References: <9vgjnd$l8c$1@nntp.itservices.ubc.ca> Mail-Copies-To: never From: Erik Naggum Message-ID: <3217517054278815@naggum.net> Organization: Naggum Software, Oslo, Norway Lines: 35 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.1 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Sun, 16 Dec 2001 18:44:16 GMT X-Complaints-To: newsmaster@KPNQwest.no X-Trace: nreader3.kpnqwest.net 1008528256 193.71.66.49 (Sun, 16 Dec 2001 19:44:16 MET) NNTP-Posting-Date: Sun, 16 Dec 2001 19:44:16 MET Xref: archiver1.google.com comp.lang.lisp:22534 * Cory Spencer | I'm a relative Lisp newbie, and for the past several hours have been | struggling with opening a binary file, and reading the data back as a | series of 6-bit bytes. The line that has been giving me problems is: | | (setq stream (open "foo" :element-type '(unsigned-byte 6))) | | and whever it executes, always prints something along the lines of: | | *** - file #P"/home/cspencer/foo" is not an integer file | | Grr. Could someone please point out the error of my ways? You seem to be using CLISP, but have not used CLISP to write the file. CLISP supports arbitrarily sized bytes in a file by starting the file with the number of bytes as a 32-bit binary number. It is so sad that Unix does not support file meta-information. It does not keep the byte size in the file similarly, so if you lie to open about the element-type, you will run into a mismatch between the stored size and the actual size in terms of specified byte size, but fortunately, this does not apply to multiples-of-8-bit-byte files. If you want to read 6-bit bytes from a file that does not begin with the prerequisite prefix, you need to copy its contents to a new file that startes with the 32-bit prefix. Since you cannot change the element-type of a stream in mid-flight, you may need to write four 8-bit 0 bytes to your output file, copy the input file as 8-bit bytes, then reopen as a 32-bit file in overwrite mode, and write the file size of the input file in 6-bit bytes. Pretty damn ugly, but such is life when people make bad technical decisions. /// -- The past is not more important than the future, despite what your culture has taught you. Your future observations, conclusions, and beliefs are more important to you than those in your past ever will be. The world is changing so fast the balance between the past and the future has shifted.