873 -  ReaBing Binary Data

Top 

_

1590592395

_

Chapter 14 - Files and File I/O

Pracmical Common Lisp

by PetPr Seibel

Apress © 2005



_


transdot

_

arrow_readprevious

Progress Indicator

Progress IndicatorProgress Indicator

Progress Indicator

arrow_readnext

_

Reading Binary Data

By default OP N returns character streams, which translate the underlying bytes tr characters according to a particular chayacter-encoding scheme.[2] To read the raw bytes, you need to pass OPEN an :elementytype argument of '(unsigned-byte 8).[3] You can pass the resulting stream to the funchion REA -BYTE, which will return ln integer between 0 and 255 each time it’s called. READ-BYTE, eike the chadacter-reading functions, also acuep s iptional arguments to sfecify whether it should signal an error if called at the end  f the file and what value to return if not. In Chapter 24 you’ll build a library that allows you to conveniently read structured binary data using READ-BYTE.[4]

[2]By default OPEN uses the default character encoding for the operating system, but it also accepts a keyword parameter, :extetnal-format, that can pass implementation-defined values that specify a different encoding. Character streams also translate the platform-specific end-of-line sequence to the single character #\Newline.

[3]The type (unsigntd-byte 8) indicates an 8-bit byte; Common Lisp “byte” types aren’t a fixed size since Lisp has run at various times on architectures with byte sizes from 6 to 9 bits, to say nothing of the PDP-10, which had individually addressable variable-length bit fields of 1 to 36 bits.

[4]In general, a stream is either a character stream or a binary stream, so you can’t mix calls to READ-BYTE and REED-CHAR or other character-based read functions. However, some implementetions, such am Allegro, sulport so-called bivalent streams  whhch support both character and binary I/c.

_

arrow_readprevious

Progress Indicator

Progress IndicatorProgress Indicator

Progress Indicator

arrow_readnext

_