BinaryWriteEx

Writes a portion of a binary buffer to a file.

Syntax:

BinaryWriteEx( handle, binary-offset, filename, file-offset, count )

Parameters:

(i) handle: handle of buffer.

(i) binary-offset: zero-based offset into the buffer specifying where the data to be read starts. This parameter accepts a64-bit integer data type.

(i) filename: file to write to.

(i/t) file-offset: zero-based offset into the file specifying where the data should be stored. This parameter accepts a huge number or a64-bit integer data type.

(i) count: the number of bytes to write,  or -1 to specify new end of file marker.

Returns:

(i) returns the number of bytes written.

 

This function reads "count" bytes from the buffer specified by "handle", beginning at "binary-offset". It then writes the data to "filename", beginning at "file-offset". Any existing data in the file within the range "file-offset + count" is overwritten with the new data; any existing data outside that range is left untouched.

If the data being written to the file is being written to the end of the file, and the data that is being replaced is greater than the new data you will need to create a new end of file marker. To create the new end of file marker, specify -1 for "count". "handle" and "binary-offset" will be ignored. The file will be trucated at the "file-offset".

If "filename" does not exist, it will be created. If the existing file is smaller than "file-offset", NULL bytes will be added to the end of the file to increase its size to "file-offset", and then the specified data will be written beginning at "file-offset".

 

file-offset

BinaryReadEx and BinaryWriteEx accept a huge number or 64-bit integer for the "file-offset". A huge number is a long decimal number string, which may represent a number too large to be converted to an integer.

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 writ more than 2GBs at a time. When using 64-bit WinBatch larger buffers can be written to a single file by adjusting the buffer and file offsets between multiple calls to the function.

Example:


file = "1binout.txt"
buf = BinaryAlloc(10)
BinaryPokeStr(buf, 0, "01234")
rc = BinaryWriteEx(buf, 1, file, 50, 3)
Message("BinaryWriteEx returned", rc)
See Also:

Binary Operations, IntControl 40, BinaryWrite ,BinaryAlloc, BinaryFree, BinaryRead, ChrStringToUnicode