Enfusion Script API
Loading...
Searching...
No Matches
Public Member Functions | List of all members
FileHandle Interface Reference
Inheritance diagram for FileHandle:
[legend]

Public Member Functions

proto int Read (out void data, int length)
 Read raw data.
 
proto int ReadLine (out string data)
 Get line from file, every next call of this function returns next line.
 
proto int ReadArray (out notnull Managed dataArray, int elementLength, int numElements)
 Read raw data.
 
proto int Write (void data, int length=-1)
 Write raw data.
 
proto void WriteLine (string data)
 Write to file and add newline (CARRIAGE RETURN + LINE FEED).
 
proto int WriteArray (out notnull Managed dataArray, int elementLength=4, int numElements=-1)
 Write raw data.
 
proto void Seek (int pos)
 Set current position in file.
 
proto int GetPos ()
 Get current position in file.
 
proto int GetLength ()
 Get file size.
 
proto void Close ()
 Close the File.
 
proto bool IsOpen ()
 
proto bool IsEOF ()
 Indicate that the End-of-File has been reached.
 
- Public Member Functions inherited from Managed
proto external ref Managed Clone ()
 Return shallow copy of object, or null if it is not allowed (not public constructor)
 

Detailed Description

// binary file write
FileHandle fileW = FileIO.OpenFile("$profile:file.bin", FileMode.WRITE);
if (fileW)
{
int valInt = 4679;
float valFloat = 87.79;
string valStr = "Hello";
fileW.Write(valInt);
fileW.Write(valFloat);
fileW.Write(valStr);
fileW.Close();
}
// binary file read
FileHandle fileR = FileIO.OpenFile("$profile:file.bin", FileMode.READ);
if (fileR)
{
int valInt;
float valFloat;
string valStr;
fileR.Read(valInt, 4);
fileR.Read(valFloat, 4);
fileR.Read(valStr, 5);
fileR.Close();
Print(valInt);
Print(valFloat);
Print(valStr);
}
// text file write
FileHandle textFileW = FileIO.OpenFile("$profile:file.txt", FileMode.WRITE);
if (textFileW)
{
for (int i = 0; i < 10; i++)
{
textFileW.WriteLine("Line " + i);
}
textFileW.Close();
}
// text file read
FileHandle textFileR = FileIO.OpenFile("$profile:file.txt", FileMode.READ);
if (textFileR)
{
string line;
while(textFileR.ReadLine(line) >= 0)
{
Print(line);
}
textFileR.Close();
}
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
FileMode
Mode for opening file. See FileSystem::Open.
Definition: FileMode.c:14
Definition: FileHandle.c:69
proto void Close()
Close the File.
proto int ReadLine(out string data)
Get line from file, every next call of this function returns next line.
proto int Read(out void data, int length)
Read raw data.
proto void WriteLine(string data)
Write to file and add newline (CARRIAGE RETURN + LINE FEED).
proto int Write(void data, int length=-1)
Write raw data.
Definition: FileIO.c:13
static proto ref FileHandle OpenFile(string name, FileMode mode)
Opens a File.

Member Function Documentation

◆ Close()

proto void FileHandle.Close ( )

Close the File.

◆ GetLength()

proto int FileHandle.GetLength ( )

Get file size.

Returns
file size in bytes

◆ GetPos()

proto int FileHandle.GetPos ( )

Get current position in file.

Returns
offset from the file beginning

◆ IsEOF()

proto bool FileHandle.IsEOF ( )

Indicate that the End-of-File has been reached.

◆ IsOpen()

proto bool FileHandle.IsOpen ( )

◆ Read()

proto int FileHandle.Read ( out void  data,
int  length 
)

Read raw data.

Parameters
datasupported types: int, float, string
lengthnumber of bytes to read. For int type is clamped [0,4]. For float its not used (always 4). For string it's not limited.
Returns
the total number of bytes successfully read.

◆ ReadArray()

proto int FileHandle.ReadArray ( out notnull Managed  dataArray,
int  elementLength,
int  numElements 
)

Read raw data.

Parameters
dataArraysupported types: array<int>, array<float> (array content will be overwritten)
elementLengthnumber of bytes from each array element to read (e.g. for reading array of bytes use 1, for shorts use 2, for int-s use 4). For int type its clamped [0,4] For float its not used (always 4).
numElementsnumber of array elements to read.
Returns
the total number of bytes successfully read.

◆ ReadLine()

proto int FileHandle.ReadLine ( out string  data)

Get line from file, every next call of this function returns next line.

Returns
Count of characters or -1 if there is nothing to read

◆ Seek()

proto void FileHandle.Seek ( int  pos)

Set current position in file.

Parameters
posoffset from the file beginning

◆ Write()

proto int FileHandle.Write ( void  data,
int  length = -1 
)

Write raw data.

Parameters
datasupported types: int, float, string
lengthnumber of bytes to write. For int type its clamped [0,4] For float its not used. For string its clamped [0, size of string]. If -1 value is used, the whole content of data is written.
Returns
the total number of bytes successfully written.

◆ WriteArray()

proto int FileHandle.WriteArray ( out notnull Managed  dataArray,
int  elementLength = 4,
int  numElements = -1 
)

Write raw data.

Parameters
dataArraysupported types: array<int>, array<float>
elementLengthnumber of bytes from each array element to write. For int type its clamped [0,4] For float its not used (always 4).
numElementsnumber of array elements to write. If -1 value is used, all elements from array are written.
Returns
the total number of bytes successfully written.

◆ WriteLine()

proto void FileHandle.WriteLine ( string  data)

Write to file and add newline (CARRIAGE RETURN + LINE FEED).

Parameters
dataValue to write

The documentation for this interface was generated from the following file: