FileTools[Binary] - Maple Programming Help

Home : Support : Online Help : Programming : Input and Output : File Manipulation : FileTools : Binary Subpackage : FileTools/Binary/ReadFile

FileTools[Binary]

 reads all binary data from a file

Parameters

 file - file descriptor or filename opts - (optional) one or more of the options described below

Options

 • datatype=d

The type to assign to the data read, one of the following:

 • integer[1], integer[2], integer[4], integer[8], float[4], float[8]. These types represent hardware data types. The integer[n] is an n byte integer, and float[n] is an n byte float.  If datatype is not specified, it defaults to integer[1].
 • byteorder=b

Specify the byte order b in which bytes are read for multi-byte data types, where b is one of the names big, little, network, and native.

 - big and little specify big endian and little endian, respectively
 - network specifies the network ordering (big endian)
 - native uses the native byte ordering
 If byteorder is not specified, then it defaults to network.
 • If file is the name of a file that has not previously been opened, ReadFile attempts to open the file before reading the data. In this case, ReadFile will also close the file after reading.
 • An error is raised if file is not a valid descriptor or if it is the name of a file that does not exist.

Description

 • The ReadFile(file) command reads all the data in datatype format from a file and returns it in the form of an Array.
 • ReadFile will issue a warning message when the requested datatype is multi-byte and there is some extra data remaining at the end of the file.

Examples

 > $\mathrm{num}≔1{256}^{3}+2{256}^{2}+3\cdot 256+4$
 ${\mathrm{num}}{≔}{1690960}$ (1)
 > $\mathrm{num2}≔4{256}^{3}+3{256}^{2}+2\cdot 256+1$
 ${\mathrm{num2}}{≔}{67305985}$ (2)
 > $\mathrm{FileTools}:-\mathrm{Binary}:-\mathrm{WriteFile}\left("testfile",\mathrm{integer}\left[4\right],\left[\mathrm{num}\right]\right)$
 ${4}$ (3)
 > $\mathrm{FileTools}:-\mathrm{Binary}:-\mathrm{ReadFile}\left("testfile",'\mathrm{datatype}'='\mathrm{integer}\left[4\right]'\right)$
 $\left[{16909060}\right]$ (4)
 > $\mathrm{FileTools}:-\mathrm{Binary}:-\mathrm{ReadFile}\left("testfile",'\mathrm{datatype}'='\mathrm{integer}\left[4\right]','\mathrm{byteorder}'='\mathrm{little}'\right)$
 $\left[{67305985}\right]$ (5)
 > $\mathrm{FileTools}:-\mathrm{Remove}\left("testfile"\right)$

Compatibility

 • The FileTools[Binary][ReadFile] command was introduced in Maple 18.