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#
Constructors#
Functions#
bool |
Open(char32[] path) |
bool |
Create(char32[] path) |
bool |
OpenMode(char32[] path, char32[] mode) deprecated |
void |
Close() |
void |
Free() deprecated |
void |
Own() |
bool |
|
bool |
isValid() |
bool |
Allocate() |
bool |
Flush() |
int |
ReadChars(char32[] buf, int count = |
int |
ReadInts(char32[] buf, int count = |
int |
WriteChars(char32[] buf, int count = |
int |
WriteInts(char32[] arr, int count = |
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 = |
void |
Rewind() |
void |
|
void |
GetError(char32[] buf) |
bool |
Remove() |
int |
WriteBytes(char32[] arr, int count = |
int |
ReadBytes(char32[] buf, int count = |
Variable descriptions#
This represents the current position in the file.
Returns true if a read call attempted to read past the end of the file.
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.
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.
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.
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.
Returns true if this pointer is allocated. This does not necessarily mean a file is open, just that the pointer has a reserved ID.
Returns true if a file is open on the pointer.
Attempts to allocate the file pointer. If it was already allocated, this will re-allocate it without freeing it!
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.
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.
Rewinds to the beginning of the file.
Clears the active EOF and Error indicators.
void GetError(char32[] buf) 🔗 Source
Stores a string describing the current error into the buffer provided.
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.