.WRITE stremanumber bytearray size
(.WRITE streamnumber bytearray)
.WRITE transfer data from a BYTEARRAY into a file. The first input denotes the stream number, while the second input is the BYTEARRAY where the data to be written is stored. The third input is the number of bytes to transfer. If the third input is missing, the BYTEARRAY is written completely.
The output of .WRITE is the number of bytes transferred. If an error occurs during the write, the output is the value "EOF.
If the file is open in normal mode, all line feed characters in the BYTEARRAY are converted to carriage return/line feed pairs. If the file is open in binary mode, however, all data is transferred unchanged.
The following example opens a file for reading and fills the first 128 bytes with the ASCII equivalents of the values 0 to 127.
TO WRITE.128.BYTES :NAME
- MAKE "STREAM (OPEN :NAME "WB)
- MAKE "DATA BYTEARRAY 128
- FOR "I 0 127 [ASET :DATA :I :I]
- (.WRITE :STREAM :DATA)
- CLOSE :STREAM