Jump to content

Confusing binary string doc


Recommended Posts

I don't understand this sentence in the help file regarding BinaryString?

BinaryString(10) does not return "10" but a BinaryString which 4 digits long which is equivalent to

0x0A000000.

So it returns a value of 0A hex = 10 decimal? Somehow I got the impression it was allocating 10 bytes. This code copies the file accurately, but it seems to have an error given the documentation.

$InputFile = FileOpen(".\binary-read.txt", 0)
If $InputFile = -1 Then
    MsgBox(0, "Error", "Unable to open file for reading.")
    Exit
EndIf

$blocksize = 4096
$block = BinaryString($blocksize)
$block = FileRead($InputFile, $blocksize)

$OutputFile = FileOpen(".\binary-write.txt", 2)
If $OutputFile = -1 Then
    MsgBox(0, "Error", "Unable to open file for writing.")
    Exit
EndIf

FileWrite($OutputFile, $block)
FileClose($OutputFile)

The above was coded in light of Larry's statement that his _BinaryFileRead and _BinaryFileWrite UDF's are obsolete now that the latest beta [now final] supports binarystring type

So what is the proper, non-obsolete way to read binary files?

Link to comment
Share on other sites

Well, I hoped to delete my post, but I guess that is not allowed, but now I think I understand what BinaryString is. It seems to be basically "what String should have been" so BinaryString(10) is exactly analogous to String(10). It IS a conversion function, period, full stop. (number to string)

Please ignore my code snippet above, it is stupid. I got the wrong impression from the examples.

EDIT: I see editing is allowed, but only for a time.

This is slightly better:

$InputFile = FileOpen(".\binary-read.txt", 0)
If $InputFile = -1 Then
    MsgBox(0, "Error", "Unable to open file for reading.")
    Exit
EndIf

$blocksize = 512;

$block = FileRead($InputFile, $blocksize)

$OutputFile = FileOpen(".\binary-write.txt", 2)
If $OutputFile = -1 Then
    MsgBox(0, "Error", "Unable to open file for writing.")
    Exit
EndIf

FileWrite($OutputFile, $block)
FileClose($OutputFile)

It doesn't even use BinaryString, nor does it use raw mode, yet it doesn't seem to have any problem with nulls in the input or output file

Edited by daddydave
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...