File¶
| Spice | |
|---|---|
File struct¶
A handle to an open file, wrapping the underlying C file pointer and tracking the end-of-file state
Methods¶
close¶
| Spice | |
|---|---|
Closes the file behind the provided file pointer.
Returns: bool — True if successful, false if not
getCursorPos¶
| Spice | |
|---|---|
Retrieves the current position of the file pointer.
Returns: unsigned long — Current position in the file in bytes
setCursorPos¶
| Spice | |
|---|---|
Sets the position of the file pointer to a specific position.
Parameters
| Name | Type | Description |
|---|---|---|
offset |
long |
Position in the file in bytes |
origin |
int |
Origin from which to set the position, can be SEEK_SET, SEEK_CUR, or SEEK_END (default: SEEK_SET) |
readChar¶
| Spice | |
|---|---|
Reads a singe char from the file.
Returns: char — Char in form of an int, because of EOF = -1.
readLine¶
| Spice | |
|---|---|
Reads a single line from the file.
Returns: String — Line in form of a string
write¶
| Spice | |
|---|---|
Writes a single character to the file.
Parameters
| Name | Type | Description |
|---|---|---|
value |
char |
Character to write |
Returns: bool — True if successful, false if not
write¶
| Spice | |
|---|---|
Writes a string to the file.
Parameters
| Name | Type | Description |
|---|---|---|
value |
string |
String to write |
Returns: bool — True if successful, false if not
write¶
| Spice | |
|---|---|
Writes a string to the file.
Parameters
| Name | Type | Description |
|---|---|---|
value |
const String& |
String to write |
Returns: bool — True if successful, false if not
getSize¶
| Spice | |
|---|---|
Returns the size of the file in bytes.
Returns: unsigned long — File size in bytes
isEOF¶
| Spice | |
|---|---|
Checks if the end of the file is reached.
Returns: bool — EOF reached / not reached
getRawHandle¶
| Spice | |
|---|---|
Get raw file handle
Returns: FilePtr — File handle
Functions¶
createFile¶
| Spice | |
|---|---|
Creates an empty file on disk similar to the 'touch' command on Linux.
Parameters
| Name | Type | Description |
|---|---|---|
path |
string |
Path to the file |
Returns: bool — True if successful, false if not
changeFilePermissions¶
| Spice | |
|---|---|
Changes the permissions of a file.
Parameters
| Name | Type | Description |
|---|---|---|
path |
string |
Path to the file |
mode |
short |
New permissions |
Returns: bool — True if successful, false if not
deleteFile¶
| Spice | |
|---|---|
Deletes a file from disk.
Parameters
| Name | Type | Description |
|---|---|---|
path |
string |
Path to the file |
Returns: bool — True if successful, false if not
openFile¶
| Spice | |
|---|---|
Opens a (new) file at the specified path with the specified mode.
There are predefined constants for the mode available:
MODE_READ, MODE_WRITE, MODE_APPEND,
MODE_READ_WRITE, MODE_READ_WRITE_OVERWRITE, MODE_READ_WRITE_APPEND
Parameters
| Name | Type | Description |
|---|---|---|
path |
string |
Path to the file |
mode |
string |
Mode to open the file in (default: MODE_READ) |
Returns: Result<File> — File pointer
openFile¶
| Spice | |
|---|---|
Opens the file at the given path in the given mode.
Parameters
| Name | Type | Description |
|---|---|---|
path |
String |
Path to the file |
mode |
string |
Mode to open the file in (e.g. "r", "w", "a") (default: MODE_READ) |
Returns: Result<File> — Result holding the opened file, or an error if the file could not be opened
readFile¶
| Spice | |
|---|---|
Reads a whole file from a given path.
Parameters
| Name | Type | Description |
|---|---|---|
path |
string |
Path to the file |
Returns: Result<String> — Content in form of a string
writeFile¶
| Spice | |
|---|---|
Writes a string to a file at a given path.
Parameters
| Name | Type | Description |
|---|---|---|
path |
string |
Path to the file |
content |
string |
Content to write |
Returns: Result<bool> — True if successful, false if not
getFileSize¶
| Spice | |
|---|---|
Returns the size of the file at the given paths in bytes.
Parameters
| Name | Type | Description |
|---|---|---|
path |
string |
Path to the file |
Returns: Result<unsigned long> — File size in bytes
fileExists¶
| Spice | |
|---|---|
Checks if a file exists. The function also returns true if the specified path points to a directory.
Parameters
| Name | Type | Description |
|---|---|---|
path |
string |
Path to the file |
Returns: bool — Existing / not existing
isFileReadable¶
| Spice | |
|---|---|
Checks if the read permissions to a file are given.
Parameters
| Name | Type | Description |
|---|---|---|
path |
string |
Path to the file |
Returns: bool — Readable / not readable
isFileWritable¶
| Spice | |
|---|---|
Checks if the write permissions to a file are given.
Parameters
| Name | Type | Description |
|---|---|---|
path |
string |
Path to the file |
Returns: bool — Writable / not writable
isFileExecutable¶
| Spice | |
|---|---|
Checks if the execute permissions to a file are given.
Parameters
| Name | Type | Description |
|---|---|---|
path |
string |
Path to the file |
Returns: bool — Executable / not executable
FilePtr alias¶
Alias for byte*.