Jump to content

Binary( )conversion fail on file opened in 'text' mode

Recommended Posts

I found that using  Binary(FileRead($x)) with FileOpen($x) can cause failed reads (blank) on systems that use 2byte per letter text encoding.

It's not clearly stated in the help file that the default mode for FileOpen() is text and should not be used to read binary data. Or, this may be a bug in Autoit.

I in this example, $data should return "FF000000" through "C00000", but as you can see from my screen shot, it returns empty reads between FD and DF. This seems to happen on computers set to 2byte per letter text encodings.


Local $data

For $i = 1 to 0xff
$data= Binary($i) & Binary($data)

$file = FileOpen(@WorkingDir & "\.example_DELETE.txt",2)
FileWrite($file, $data)

$data = ""
For $i = 1 To 0xff
$data = Binary($data) & Binary(FileRead($file,1))




Edited by EddieBoy
Link to post
Share on other sites

I'll just add, if you live in the US and have had programs fail when sent overseas to unicode etc users, this issue may be the culprit.

 When I changed my code to use "forced binary" FileOpen($x,16), the problem went away.  

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...