21.3. Binary Input and Output
Prev | Chapter 21. Streams | Next

## 21.3. Binary Input and Output

### 21.3.1. Binary input, `READ-BYTE`, `EXT:READ-INTEGER` & `EXT:READ-FLOAT`

The function `(`EXT:READ-INTEGER` `stream` `element-type` `&OPTIONAL` `ENDIANNESS` `eof-error-p` `eof-value`)` reads a multi-byte `INTEGER` from `stream`, which should be a `STREAM` with `STREAM-ELEMENT-TYPE` `(`UNSIGNED-BYTE` 8)`. `element-type` should be type equivalent to `(`UNSIGNED-BYTE` `n`)`, where `n` is a multiple of 8.

`(`EXT:READ-INTEGER` `stream` `element-type`)` is like `(`READ-BYTE` `stream`)` if `stream`'s `STREAM-ELEMENT-TYPE` were set to `element-type`, except that `stream`'s `FILE-POSITION` will increase by `n`/8 instead of 1.

Together with `(`SETF` `STREAM-ELEMENT-TYPE`)`, this function permits mixed character/binary input from a stream.

The function `(`EXT:READ-FLOAT` `stream` `element-type` `&OPTIONAL` `ENDIANNESS` `eof-error-p` `eof-value`)` reads a floating-point number in IEEE 754 binary representation from `stream`, which should be a `STREAM` with `STREAM-ELEMENT-TYPE` `(`UNSIGNED-BYTE` 8)`. `element-type` should be type equivalent to `SINGLE-FLOAT` or `DOUBLE-FLOAT`.

Endianness. `ENDIANNESS` can be `:LITTLE` or `:BIG`. The default is `:LITTLE`, which corresponds to the `READ-BYTE` behavior in CLISP.

### 21.3.2. Binary output, `WRITE-BYTE`, `EXT:WRITE-INTEGER` & `EXT:WRITE-FLOAT`

The function `(`EXT:WRITE-INTEGER` `integer` `stream` `element-type` `&OPTIONAL` `ENDIANNESS`)` writes a multi-byte `INTEGER` to `stream`, which should be a `STREAM` with `STREAM-ELEMENT-TYPE` `(`UNSIGNED-BYTE` 8)`. `element-type` should be type equivalent to `(`UNSIGNED-BYTE` `n`)`, where `n` is a multiple of 8.

`(`EXT:WRITE-INTEGER` `integer` `stream` `element-type`)` is like `(`WRITE-BYTE` `integer` `stream`)` if `stream`'s `STREAM-ELEMENT-TYPE` were set to `element-type`, except that `stream`'s `FILE-POSITION` will increase by `n`/8 instead of 1.

Together with `(`SETF` `STREAM-ELEMENT-TYPE`)`, this function permits mixed character/binary output to a `STREAM`.

The function `(`EXT:WRITE-FLOAT` `float` `stream` `element-type` `&OPTIONAL` `ENDIANNESS`)` writes a floating-point number in IEEE 754 binary representation to `stream`, which should be a `STREAM` with `STREAM-ELEMENT-TYPE` `(`UNSIGNED-BYTE` 8)`. `element-type` should be type equivalent to `SINGLE-FLOAT` or `DOUBLE-FLOAT`.

| These notes document CLISP version 2.45 | Last modified: 2008-05-14

Enter your search termsSubmit search form
Webclisp.cons.orgclisp.podval.orgwww.lisp.org

Prev | Up | Next
21.2. Terminal interaction | Home | 21.4. Bulk Input and Output