writebytes - Maple Help

writebytes

writes bytes from a string or list to a file or pipe

 Calling Sequence writebytes(file, bytes)

Parameters

 file - file descriptor or filename bytes - string, list of integers, or hardware Array

Description

 • The writebytes function writes the specified bytes to the indicated file.
 • writebytes returns a count of the number of characters written.
 • If the bytes are a string, the characters in the string are written. It is not possible to write a zero byte using a string argument.
 • If the bytes are a list of integers, each integer must be in the range 0..255. One byte is written for each integer.
 • If the bytes are a hardware Array, the data in the hardware Array's data space is written. The format of this data is architecture dependent. The file is guaranteed to be re-readable only on the same architecture on which it was written, although it may be compatible between some architectures.
 • If the file being written to is a STREAM or RAW file, and it is currently open in READ mode, it will be reopened in WRITE mode at the same offset. The file is opened with type TEXT if string data is used, or with type BINARY if list data is used.
 • If a file name is given, and that file is not yet open, it is opened in WRITE mode. The file is opened with type TEXT if string data is used, or with type BINARY if list data is used.

 • The writebytes command is thread safe as of Maple 15.
 • Parallel calls to file i/o commands on the same file descriptor will be serialized in an arbitrary order.  If you need the commands to execute in a particular order you must use Maple's synchronization tools to enforce this.  See Threads:-Mutex.

Examples

 > $\mathrm{writebytes}\left(\mathrm{testFile},"This is a test"\right)$
 ${14}$ (1)
 > $\mathrm{writebytes}\left(\mathrm{testFile},\left[65,66,67\right]\right)$
 ${3}$ (2)
 > $\mathrm{filepos}\left(\mathrm{testFile},0\right)$
 ${0}$ (3)
 > $\mathrm{readline}\left(\mathrm{testFile}\right)$

 This is a testABC