Core Function FileReadBinary
From Sputnik Wiki
(Difference between revisions)
(Created page with "<pre> FileReadBinary( <file>, <expression> ) </pre> === Description === Read a number of bytes from a previously opened file starting from current File Steam pointer location....") |
(→Example) |
||
Line 32: | Line 32: | ||
<syntaxhighlight lang="sputnik"> | <syntaxhighlight lang="sputnik"> | ||
− | $File = FileOpen("MyFile.txt", "w") | + | $File = FileOpen("MyFile.txt", "w"); |
− | If | + | If ( isVarObj($File, "file") ) |
− | FileAppend( $File, "This is line 1\n" ) | + | { |
− | FileAppend( $File, "This is line 2\n" ) | + | FileAppend( $File, "This is line 1\n" ); |
− | FileAppend( $File, "This is line 3\n" ) | + | FileAppend( $File, "This is line 2\n" ); |
− | FileAppend( $File, $lines ) | + | FileAppend( $File, "This is line 3\n" ); |
− | FileClose( $File ) | + | FileAppend( $File, $lines ); |
− | + | FileClose( $File ); | |
− | + | } | |
− | + | ||
− | $File = FileOpen("MyFile.txt", "r") | + | $File = FileOpen("MyFile.txt", "r"); |
− | If | + | If ( isVarObj($File, "file") ) |
− | $binary = FileReadBinary($File) | + | { |
− | $k = 0 | + | $binary = FileReadBinary($File); |
− | + | $k = 0; | |
− | println( DecPad($k, 5) . " Byte: " . $i . " | Hex: " . Hex($i) . " | Char: " . Chr($i) ) | + | Foreach ($binary as $i) |
− | $k++ | + | { |
− | + | println( DecPad($k, 5) . " Byte: " . $i . " | Hex: " . Hex($i) . " | Char: " . Chr($i) ); | |
− | println( "Info: " . $binary ) | + | $k++; |
− | println( "Size: " . | + | } |
− | println( "TEXT BELOW\n" . Trim(Unpack("z0", $binary)) . "\nTEXT ABOVE" ) | + | println( "Info: " . $binary ); |
− | + | println( "Size: " . UBound($binary) ); | |
− | FileClose( $File ) | + | println( "TEXT BELOW\n" . Trim(Unpack("z0", $binary)) . "\nTEXT ABOVE" ); |
− | + | FileClose( $File ); | |
+ | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
[[Category:Core Function]] | [[Category:Core Function]] |
Revision as of 01:42, 19 November 2011
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 0 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("MyFile.txt", "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("z0", $binary)) . "\nTEXT ABOVE" ); FileClose( $File ); }