Original Author Paul Laughton, 2011
Page 114
De Re BASIC!
Byte.read.buffer <file_table_nexp>, <count_nexp>, <buffer_svar>
Reads the specified number of bytes (<count_nexp>) into the buffer string variable (<buffer_svar>) from
the file. The string length (len(<buffer_svar>)) will be the number of bytes actually read. If the end of file
is reached, the string length may be less than the requested count.
A buffer string is a special use of the BASIC! string. Each character of a string is 16 bits. When used as a
buffer, one byte of data is written into the lower 8 bits of each 16-bit character. The upper 8 bits are 0.
Extract the binary data from the string, one byte at a time, with the ASCII() or UCODE() functions.
The format of the buffer string read by this command is compatible with the DECODE$() function. If you
know that part of your data contains an encoded string, you can extract the substring (using a function
like MID$()), then pass the substring to DECODE$() to convert it to a BASIC! string.
Byte.write.buffer <file_table_nexp>, <buffer_sexp>
Writes the entire contents of the string expression to the file. The string is assumed to be a buffer string
holding binary data, as described in Byte.read.buffer. The writer discards the upper 8 bits of each 16-bit
character, writing one byte to the file for each character in the string.
The Byte.read.buffer command and the ENCODE$() function always create these "buffer strings". You
can construct one by using, for example, the CHR$() function with values less than 256.
If you use only ASCII characters in a string, you can use this function to write the string to a file. The
output is the same as if you had written it with Text.writeln, except that it will have no added newline.
Byte.eof <file_table_nexp>, <lvar>
Reports an opened file's end-of-file status. If the file is at EOF, the <lvar> is set true (non-zero). If the file
or directory is not at EOF, the <lvar> is set false (zero).
A file opened for write or append is always at EOF. A file opened for read is not at EOF until all of the
data has been read and then one more read is attempted. That read will have returned the value -1.
Byte.position.set may also position the file at EOF.
Byte.position.get <file_table_nexp>, <position_nvar>
Gets the position of the next byte to be read or written. The position of the first byte is 1. The position
value will be incremented by 1 for each byte read or written.
The position information can be used for setting up random file data access.
If the file is opened for append, the position returned will be the length of the file plus one.
Byte.position.set <file_table_nexp>, <position_nexp>
Sets the position of the next byte to be read from the file. If the position value is greater than the
position of the last byte of the file, the position will point to the end of file.