Core Function FileReadBinary

From Sputnik Wiki
Revision as of 14:05, 12 November 2011 by UberFoX (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
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 isObj($File, "file") Then ; You could just use isObj($File) however adding the "file" will make sure it is indeed a 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 )
 
EndIf
 
$File = FileOpen("MyFile.txt", "r")
If isObj($File, "file") Then
	$binary = FileReadBinary($File)	
	$k = 0
	For $i In $binary
		println( DecPad($k, 5) . " Byte: " . $i . " | Hex: " . Hex($i) . " | Char: " . Chr($i) )
		$k++
	Next
	println( "Info: " . $binary )
	println( "Size: " . BinaryLen($binary) )
	println( "TEXT BELOW\n" . Trim(Unpack("z0", $binary)) . "\nTEXT ABOVE" )
 
	FileClose( $File )
EndIf
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox