[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

9.24.4 Uvector block I/O

A uniform vector can be seen as an abstraction of a chunk of memory. So you might want to use it for binary I/O. Yes, you can do it.

Function: read-block! vec &optional iport start end
Reads a chunk of data from the given input port iport, and stores it to the uniform vector vec. You can give any uniform vector. If optional start and end arguments are given, they specify the index range in vec that is to be filled, and the rest of the vector remains untouched. Otherwise, entire vector is used. If iport is omitted, the current input port is used.

If the input reached EOF before the required region of vec is filled, the rest of the vector is untouched.

If iport is already reached EOF when read-block! is called, an EOF object is returned. Otherwise, the procedure returns the number of elements read (not bytes).

If the iport is a buffered port with `modest' or `none' buffering mode (See section 6.18.3 File ports), read-block! may return before all the elements in vec is filled, even if iport hasn't reached EOF. The ports connected to a pipe or a network socket behave so by default. If you know there will be enough data arriving and want to make sure vec is filled, change the buffering mode of iport to `full'.

The data is read as a byte stream, so if you give uniform vectors other than s8vector or u8vector, your result may affected by the endianness of the platform. Suppose the input stream has a byte sequence #x01, #x02, #x03, #x04. If you read it into u32vector, the first element you'll get may be #x01020304 if you're using big-endian architecture, or #x04030201 if you're using little-endian architecture.

Function: write-block vec &optional oport start end
Writes out the content of the uniform vector vec 'as is' to the output port oport. If oport is omitted, the current output port is used. If optional start and end arguments are given, they specify the index range in vec to be written out. This procedure returns an unspecified value.

If you write out a uniform vector except s8vector and u8vector, the care should be taken about the endianness, as in read-block!. The number #x01020304 in your u32vector may be written out as the byte sequence #x01, #x02, #x03, #x04 or #x04, #x03, #x02, #x01, depending on your architecture.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated by Ken Dickey on November, 28 2002 using texi2html