Cerberus X Documentation

Class FileStream

A filestream allows you to read/write data from/to a file. More...

Declarations

Extends
Stream Streams are used to read or write data in a sequential manner.
Functions
Open : FileStream ( path:String, mode:String ) Opens a new filestream.
Inherited Properties
Eof : Int () Returns 1 if end-of-file has been reached, -1 if an IO error has occurred or 0 if the stream can be read.
Length : Int () Returns the stream length if the stream is seekable, else 0.
Position : Int () Returns the read/write position within the stream if the stream is seekable, else 0.
Inherited Methods
Close : Void () Closes the stream and released any OS resources in use.
Read : Int ( buffer:DataBuffer, offset:Int, count:Int ) Reads count bytes from the stream into databuffer, starting at address offset within the databuffer.
ReadAll : DataBuffer () Reads all remaining bytes from the stream into a databuffer.
ReadAll : Void ( buffer:DataBuffer, offset:Int, count:Int ) Reads count bytes from the stream into databuffer, starting at address offset within the databuffer.
ReadByte : Int () Reads an 8 bit byte from the stream.
ReadFloat : Float () Reads a 32 bit float value from the stream.
ReadInt : Int () Reads a 32 bit int value from the stream.
ReadShort : Int () Reads a 16 bit int value from the stream.
ReadString : String ( count:Int, encoding:String="utf8" ) Reads count bytes from the stream and converts them to a string using the given encoding.
ReadString : String ( encoding:String="utf8" ) Reads all bytes from the stream until end-of-file and converts them to a string using the given encoding.
Seek : Int ( position:Int ) If the stream is seekable, adjusts the read/write position within the stream and returns the new read/write position.
Write : Int ( buffer:DataBuffer, offset:Int, count:Int ) Writes count bytes from databuffer to the stream, starting at address offset within the databuffer.
WriteAll : Void ( buffer:DataBuffer, offset:Int, count:Int ) Writes count bytes from databuffer to the stream, starting at address offset within the databuffer.
WriteByte : Void ( value:Int ) Writes an 8 bit byte to the stream.
WriteFloat : Void ( value:Float ) Writes a 32 bit float value to the stream.
WriteInt : Void ( value:Int ) Writes a 32 bit int value to the stream.
WriteShort : Void ( value:Int ) Write a 16 bit int value to the stream.
WriteString : Void ( value:String, encoding:String="utf8" ) Writes a string to the stream using the given encoding.

Detailed Discussion

A filestream allows you to read/write data from/to a file.


Functions Documentation

Function Open : FileStream ( path:String, mode:String )

Opens a new filestream. The mode parameter should be one of the following:

ModeDescription
"r"Open a filestream for reading.
"w"Open a filestream for writing. If the file does not already exist, it will be created. If the file already exists, it will be emptied.
"u"Open a filestream for read/write updating. If the file does not already exist, it will be created.
"a"Open a filestream for read/write appending. This is the same as opening a filestream for updating and seeking to the end.
See also

Resource paths