Arbortext Command Language > Functions by Alphabetical Listing > write (Function)
  
write (Function)
write(fid, buf[, len])
This function writes len bytes from the scalar variable buf to the file or channel identified by fid, which is an open identifier returned by open_connect or open_accept. If len is omitted, all data in buf is written. write returns the number of characters written or –1 on failure.
Unlike put, write can handle binary data (that is, null characters). See the description of read for an example of a function which copies a binary file using read and write.
For output to a file identifier, write is implemented using the standard I/O function fwrite so it is acceptable to mix put and write calls.
When writing to a network channel, Arbortext Editor automatically queues any data that is not immediately transferred, for example, if the write operation would block. Unlike read, you do not have to be concerned about asynchronous writes.
Example
write(sock, "GET" . path. "HTTP/1.0/r/r/r/n")
If writing to a binary stream, that is, a file opened with "wb" or a network channel, write writes Unicode characters. Thus,
write(fid, "abc\n")
would write 8 bytes. A Unicode text file normally starts with the Unicode byte-order mark U+FEFF which can be written to a binary stream as:
write(fid, chr(0xfeff))
The byte-order mark written to a binary file this way is in the native machine order so that on a little-endian machine like an Intel-based PC, the byte-order mark would actually appear as U+FFFE in the file. Since Unicode characters are also written in native order, this will identify the Unicode file as written on a little-endian machine.
Related Topics
open_accept built-in function
open_connect built-in function
pack built-in function
put built-in function
read built-in function