(require 'byte)
Some algorithms are expressed in terms of arrays of small integers.
Using Scheme strings to implement these arrays is not portable vis-a-vis
the correspondence between integers and characters and non-ascii
character sets. These functions abstract the notion of a byte.
k must be a valid index of bytes.
byte-refreturns byte k of bytes using zero-origin indexing.
k must be a valid index of bytes, and byte must be a small nonnegative integer.
byte-set!stores byte in element k of bytes and returns an unspecified value.
make-bytesreturns a newly allocated byte-array of length k. If byte is given, then all elements of the byte-array are initialized to byte, otherwise the contents of the byte-array are unspecified.
Returns a newly allocated byte-array composed of the small nonnegative arguments.
list->bytesreturns a newly allocated byte-array formed from the small nonnegative integers in the list bytes.
bytes->listreturns a newly allocated list of the bytes that make up the given byte-array.
Bytes->list and list->bytes are inverses so far as
equal? is concerned.
Returns a new string formed from applying
integer->charto each byte inbytes->string. Note that this may signal an error for bytes having values between 128 and 255.
Returns a new byte-array formed from applying
char->integerto each character instring->bytes. Note that this may signal an error if an integer is larger than 255.
bytes must be a bytes, and start and end must be exact integers satisfying
0 <= start <= end <= (bytes-length bytes).
subbytesreturns a newly allocated bytes formed from the bytes of bytes beginning with index start (inclusive) and ending with index end (exclusive).
Returns a newly allocated bytes-array consisting of the elements of bytes in reverse order.
Input and output of bytes should be with ports opened in binary
mode (see Input/Output). Calling open-file with 'rb or
'wb modes argument will return a binary port if the Scheme
implementation supports it.
Writes the byte byte (not an external representation of the byte) to the given port and returns an unspecified value. The port argument may be omitted, in which case it defaults to the value returned by
current-output-port.
Returns the next byte available from the input port, updating the port to point to the following byte. If no more bytes are available, an end-of-file object is returned. port may be omitted, in which case it defaults to the value returned by
current-input-port.
When reading and writing binary numbers with read-bytes and
write-bytes, the sign of the length argument determines the
endianness (order) of bytes. Positive treats them as big-endian,
the first byte input or output is highest order. Negative treats
them as little-endian, the first byte input or output is the lowest
order.
Once read in, SLIB treats byte sequences as big-endian. The multi-byte sequences produced and used by number conversion routines see Byte/Number Conversions are always big-endian.
read-bytesreturns a newly allocated bytes-array filled with(absn)bytes read from port. If n is positive, then the first byte read is stored at index 0; otherwise the last byte read is stored at index 0. Note that the length of the returned byte-array will be less than(absn)if port reaches end-of-file.port may be omitted, in which case it defaults to the value returned by
current-input-port.
write-byteswrites(absn)bytes to output-port port. If n is positive, then the first byte written is index 0 of bytes; otherwise the last byte written is index 0 of bytes.write-bytesreturns an unspecified value.port may be omitted, in which case it defaults to the value returned by
current-output-port.
subbytes-read! and subbytes-write provide
lower-level procedures for reading and writing blocks of bytes. The
relative size of start and end determines the order of
writing.
Fills bts with up to
(abs (-start end))bytes read from port. The first byte read is stored at index bts.subbytes-read!returns the number of bytes read.port may be omitted, in which case it defaults to the value returned by
current-input-port.
subbytes-writewrites(abs (-start end))bytes to output-port port. The first byte written is index start of bts.subbytes-writereturns the number of bytes written.port may be omitted, in which case it defaults to the value returned by
current-output-port.