file#

Valid modes (details taken from http://www.cplusplus.com/reference/cstdio/fopen/):

  • “r” (read): Open file for input operations. The file must exist.

  • “w” (write): Create an empty file for output operations. If a file with the same name already exists, its contents are discarded and the file is treated as a new empty file.

  • “a” (append): Open file for output at the end of a file. Output operations always write data at the end of the file, expanding it. Repositioning operations (‘Seek()’, ‘Rewind()’) are ignored. The file is created if it does not exist.

  • “r+” (read/update): Open a file for update (both for input and output). The file must exist.

  • “w+” (write/update): Create an empty file and open it for update (both for input and output). If a file with the same name already exists its contents are discarded and the file is treated as a new empty file.

  • “a+” (append/update): Open a file for update (both for input and output) with all output operations writing data at the end of the file. Repositioning operations (fseek, fsetpos, rewind) affects the next input operations, but output operations move the position back to the end of file. The file is created if it does not exist.

The letter “b” can be added to the end of any of these (but before the “+” for update modes) to specify a binary file mode. Otherwise, the file opens in text mode.

Text files are files containing sequences of lines of text. Depending on the environment where the application runs, some special character conversion may occur in input/output operations in text mode to adapt them to a system-specific text file format. Although on some environments no conversions occur and both text files and binary files are treated the same way, using the appropriate mode improves portability.

Variables#

const long

Pos

const int

EOF

const int

Error

Constructors#

file

file(char32[] path, char32[] mode)

Functions#

bool

Open(char32[] path)

bool

Create(char32[] path)

bool

OpenMode(char32[] path, char32[] mode) deprecated

void

Close()

void

Free() deprecated

void

Own()

bool

isAllocated()

bool

isValid()

bool

Allocate()

bool

Flush()

int

ReadChars(char32[] buf, int count = -1, int pos = 0)

int

ReadInts(char32[] buf, int count = -1, int pos = 0)

int

WriteChars(char32[] buf, int count = -1, int pos = 0)

int

WriteInts(char32[] arr, int count = -1, int pos = 0)

int

ReadString(char32[] buf)

int

WriteString(char32[] str)

char32

GetChar()

char32

PutChar(char32 c)

char32

UngetChar(char32 c)

bool

Seek(long pos, bool from_current = false)

void

Rewind()

void

ClearError()

void

GetError(char32[] buf)

bool

Remove()

int

WriteBytes(char32[] arr, int count = -1, int pos = 0)

int

ReadBytes(char32[] buf, int count = -1, int pos = 0)

Variable descriptions#

const long Pos 🔗 Source

This represents the current position in the file.


const int EOF 🔗 Source

Returns true if a read call attempted to read past the end of the file.


const int Error 🔗 Source

Returns 0 if the file has not enountered an error.


Constructor descriptions#

file file(char32[] path, char32[] mode) 🔗 Source

param mode - See file for details.


Function descriptions#

bool Open(char32[] path) 🔗 Source

If the file pointer is not allocated, this will allocate it. Also closes any file that is already open on the pointer.


bool Create(char32[] path) 🔗 Source

If the file pointer is not allocated, this will allocate it. Also closes any file that is already open on the pointer.


bool OpenMode(char32[] path, char32[] mode) 🔗 Source

param mode - See file for details.

If the file pointer is not allocated, this will allocate it. Also closes any file that is already open on the pointer.

Deprecated: Use new file(path, mode) instead.


void Close() 🔗 Source

Closes any open file connected to the file pointer (which also includes ‘Flush()’). Does *NOT* deallocate the pointer, it is still reserved to open new files on.


void Free() 🔗 Source

Closes the currently open file as if calling Close(), then deallocates the file pointer so it may be re-used.

Deprecated: Free() no longer does anything as of ZC 3.0. Objects are now freed automatically.


void Own() 🔗 Source

Grants ‘Ownership’ of the file pointer to the script that calls this function. When the script with ‘Ownership’ terminates (at the same time its’ local arrays are deallocated), this file pointer will automatically be ‘Free()’d.


bool isAllocated() 🔗 Source

Returns true if this pointer is allocated. This does not necessarily mean a file is open, just that the pointer has a reserved ID.


bool isValid() 🔗 Source

Returns true if a file is open on the pointer.


bool Allocate() 🔗 Source

Attempts to allocate the file pointer. If it was already allocated, this will re-allocate it without freeing it!


bool Flush() 🔗 Source

Flushes the buffer of the file being written to.


int ReadChars(char32[] buf, int count = -1, int pos = 0) 🔗 Source

Reads a section of characters from the file.


int ReadInts(char32[] buf, int count = -1, int pos = 0) 🔗 Source

Reads a section of binary data from the file.


int WriteChars(char32[] buf, int count = -1, int pos = 0) 🔗 Source

Writes characters from ‘buf’ to file.


int WriteInts(char32[] arr, int count = -1, int pos = 0) 🔗 Source

Writes 32b binary data from ‘arr’ to file.


int ReadString(char32[] buf) 🔗 Source

Reads a section of characters from the file.


int WriteString(char32[] str) 🔗 Source

Writes the string stored in ‘str’ to the file.


char32 GetChar() 🔗 Source

Reads and returns the next character in the file.


char32 PutChar(char32 c) 🔗 Source

Writes ‘c’ to file.


char32 UngetChar(char32 c) 🔗 Source

Un-reads ‘c’ to the input stream.


bool Seek(long pos, bool from_current = false) 🔗 Source

Moves the current position of the file.


void Rewind() 🔗 Source

Rewinds to the beginning of the file.


void ClearError() 🔗 Source

Clears the active EOF and Error indicators.


void GetError(char32[] buf) 🔗 Source

Stores a string describing the current error into the buffer provided.


bool Remove() 🔗 Source

Deletes the file. This will close it, as with Close(), and then delete it from the filesystem.


int WriteBytes(char32[] arr, int count = -1, int pos = 0) 🔗 Source

Writes 8b binary data from ‘arr’ to file.


int ReadBytes(char32[] buf, int count = -1, int pos = 0) 🔗 Source

Reads a section of binary data from the file.