.READ

Syntax

.READ streamnumber bytearray size

(.READ streamnumber bytearray)

Explanation

.READ transfers data from a file into a BYTEARRAY. The first input is the stream number and the second input is the BYTEARRAY where the data is to be stored. The third input is the number of bytes to transfer. If the third input is missing, the BYTEARRAY is filled completely.

The output of .READ is the number of bytes transferred. If no bytes are transferred because the end of the file is reached, the output is the value "EOF.

If the file open in normal mode, a maximum of one line, terminated by the line feed character, is transferred. The last byte is appended with a byte of value 0. You can then use the TEXTARRAY command to convert the contents of the BYTEARRAY to a Logo word. If the file is open in binary mode, however, the data is transferred unchanged, including all carriage return and line feed characters.

See also OPEN, .SEEK and .WRITE.

Example

The following example opens a file for reading and reads the first 128 bytes in binary mode.

TO READ.128.BYTES :NAME


 * MAKE "STREAM (OPEN :NAME "RB)


 * MAKE "DATA BYTEARRAY 128


 * (.READ :STREAM :DATA)


 * CLOSE :STREAM

END