[plt-scheme] Parsing Binary Files

From: Danny Yoo (dyoo at hkn.eecs.berkeley.edu)
Date: Tue Mar 7 13:18:16 EST 2006


On Tue, 7 Mar 2006, David J. Neu wrote:

> I'm parsing a binary file, and calls to read-byte and read-bytes return
> #<eof> when that byte is encountered.

Hi David,

Could it be that the file is opened in text mode?  I'm trying to duplicate
this problem now, and I can't:

;;;;;;
> (define b (bytes 0 1 0 1))
> (define p (open-input-bytes b))
> (read-byte p)
0
> (read-byte p)
1
> (read-byte p)
0
> (read-byte p)
1
> (read-byte p)
#<eof>
;;;;;;

which looks perfectly ok to me: the port is perfectly happy to emit 0 as a
byte value.


> The input-port being read from was opened using open-input-bytes.

Wait, but open-input-bytes already takes in a source of bytes: it doesn't
take in a port itself.  You mentioned earlier that you're parsing a binary
file.  So I'm confused about the domains here.  How are you getting from
the binary file to bytes?

I hate guessing.  *grin* Can you show us an example of what you mean?


Good luck to you!



Posted on the users mailing list.