BinaryRead

Reads a file into a binary buffer.

Syntax:

BinaryRead( handle, filename )

Parameters:

(i) handle: handle of buffer.

(s) filename: file to read into buffer.

Returns:

(i)  the number of bytes read.

 

This function reads the entire contents of a file into a buffer then returns the number of bytes read. The buffer must be large enough to hold the entire file. The file is placed into the buffer starting at offset 0.

This function supports extended-length path but requires the extended-length file paths to be converted to a Unicode string before being passed to the function. Use ChrStringToUnicode to do the conversion.

Note: Because Windows system limitations this function cannot read files larger than 2GBs regardless of the buffer size.

 

Example:


; This example edits the Config.sys file by adding a line
; to the bottom of the file.
fs=FileSize("C:\CONFIG.SYS")
binbuf = BinaryAlloc(fs+100)
If binbuf == 0
   Message("Error", "BinaryAlloc Failed")
Else
   BinaryRead(binbuf, "C:\CONFIG.SYS")
   BinaryPokeStr(binbuf, fs, "DEVICE=C:\FLOOGLE.SYS%@crlf%")
   BinaryWrite(binbuf, "C:\CONFIG.SYS")
   binbuf=BinaryFree(binbuf)
EndIf
Message("BinaryRead", "Done.")
See Also:

IntControl 39, Binary Operations, BinaryAlloc, BinaryReadEx , BinaryFree, BinaryWrite, BinaryWriteEx, ChrStringToUnicode