Core Function FileReadBinary
From Sputnik Wiki
(Difference between revisions)
(→Example) |
m (1 revision) |
||
(3 intermediate revisions by one user not shown) | |||
Line 23: | Line 23: | ||
Success: Returns a binary variable filled with data read from file. | Success: Returns a binary variable filled with data read from file. | ||
− | Failure: Returns | + | Failure: Returns null if error occurs. |
=== Remarks === | === Remarks === | ||
Line 42: | Line 42: | ||
} | } | ||
− | $File = FileOpen(" | + | $File = FileOpen("Main.spk", "r"); |
If ( isVarObj($File, "file") ) | If ( isVarObj($File, "file") ) | ||
{ | { | ||
Line 54: | Line 54: | ||
println( "Info: " . $binary ); | println( "Info: " . $binary ); | ||
println( "Size: " . UBound($binary) ); | println( "Size: " . UBound($binary) ); | ||
− | println( "TEXT BELOW\n" . Trim(Unpack(" | + | println( "TEXT BELOW\n" . Trim(Unpack("A*", $binary, 3)) . "\nTEXT ABOVE" ); |
FileClose( $File ); | FileClose( $File ); | ||
} | } |
Latest revision as of 12:38, 14 June 2015
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 ); }