Core Function FileReadBinary
From Sputnik Wiki
FileReadBinary( <file>, <expression> )
Contents |
Description
Read a number of bytes from a previously opened file starting from current File Steam pointer location.
Parameters
file
A variable containing the File handle.
expression
Optional; Number of bytes to read.
If this param is not provided it will read to the end of the file.
Return Value
Success: Returns a binary variable filled with data read from file.
Failure: Returns null if error occurs.
Remarks
N/A
Example
$File = FileOpen("MyFile.txt", "w"); If ( isVarObj($File, "file") ) { FileAppend( $File, "This is line 1\n" ); FileAppend( $File, "This is line 2\n" ); FileAppend( $File, "This is line 3\n" ); FileAppend( $File, $lines ); FileClose( $File ); } $File = FileOpen("Main.spk", "r"); If ( isVarObj($File, "file") ) { $binary = FileReadBinary($File); $k = 0; Foreach ($binary as $i) { println( DecPad($k, 5) . " Byte: " . $i . " | Hex: " . Hex($i) . " | Char: " . Chr($i) ); $k++; } println( "Info: " . $binary ); println( "Size: " . UBound($binary) ); println( "TEXT BELOW\n" . Trim(Unpack("A*", $binary, 3)) . "\nTEXT ABOVE" ); FileClose( $File ); }