Page 1 of 1

RawRead()

Posted: 27 Feb 2024, 19:15
by iseahound
Please add a note that if a UTF-8 BOM file is encountered, the file pointer is set to 3. Therefore calls to RawRead() will read 3 less bytes.

The user should add

Code: Select all

f.pos := 0
before calls to rawread or they may get errors.

This may be a bug.

Re: RawRead()

Posted: 07 Mar 2024, 05:19
by Ragnar
There is already a note on the FileOpen page:
When a file containing a UTF-8 or UTF-16 byte order mark (BOM) is opened with read access, the BOM is excluded from the output by positioning the file pointer after it. Therefore, File.Pos may report 3 or 2 immediately after opening the file.

Re: RawRead()

Posted: 01 Apr 2024, 18:09
by iseahound
It should be added to RawRead however, as one would expect "raw" to mean unmodified.

Re: RawRead()

Posted: 02 Apr 2024, 06:36
by RussF
I would have to agree with @iseahound here. Perhaps a warning that you must first check the fileobj.pos property and reset it to 0 if you want to be sure you are getting the first two bytes.

In fact, I would also argue that the FileOpen object should have an additional flag that opens a file in raw mode, initially forcing the file pointer to 0 rather than (maybe) 2 (or maybe not). While AHK may not be the best choice for processing binary data, there may be a circumstance where you need to as part of a larger application.

Russ