Rishka
RISC-V virtual runtime in C/C++ made for ESP32-WROVER
File Class Referencefinal

Class for handling file operations in Rishka applications. More...

#include <fs.h>

Public Member Functions

bool is_file ()
 Check if the object represents a file. More...
 
bool is_dir ()
 Check if the object represents a directory. More...
 
i32 available ()
 Get the number of bytes available for reading from the file. More...
 
i32 peek ()
 Peek at the next byte in the file without consuming it. More...
 
u64 lastwrite ()
 Get the timestamp of the last write operation on the file. More...
 
bool bufsize (usize size)
 Set the buffer size for the file. More...
 
bool seek (u32 pos)
 Set the current position within the file. More...
 
bool seek_dir (u64 position)
 Set the current position within the directory. More...
 
usize size ()
 Get the size of the file. More...
 
usize position ()
 Get the current position within the file. More...
 
i32 read ()
 Read a byte from the file. More...
 
void write (u8 data)
 Write a byte to the file. More...
 
void write (string data)
 Write a string to the file. More...
 
string path ()
 Get the path of the file. More...
 
string name ()
 Get the name of the file. More...
 
File next ()
 Get the next file in the directory. More...
 
bool is_ok ()
 Checks if the file is in a valid state. More...
 
string next_name ()
 Get the name of the next file in the directory. More...
 
void flush ()
 Flush the file buffer. More...
 
void close ()
 Close the file. More...
 
void rewind ()
 Rewind the directory pointer to the beginning of the current working directory. More...
 

Static Public Member Functions

static File open (string file, string mode)
 Open a file with the specified name and mode. More...
 

Protected Member Functions

 File (i32 _handle)
 

Detailed Description

Class for handling file operations in Rishka applications.

The File class provides methods for performing various file operations, such as opening, reading, writing, and closing files. It also includes functionalities for file navigation and querying file attributes.

Constructor & Destructor Documentation

◆ File()

File::File ( i32  _handle)
protected

Protected constructor for creating a file object

Member Function Documentation

◆ available()

i32 File::available ( )

Get the number of bytes available for reading from the file.

This method returns the number of bytes available for reading from the file.

Returns
The number of bytes available for reading.

◆ bufsize()

bool File::bufsize ( usize  size)

Set the buffer size for the file.

This method sets the buffer size for the file. It determines the amount of data buffered in memory before being written to the file.

Parameters
sizeThe buffer size to set, in bytes.
Returns
True if the buffer size was successfully set, false otherwise.

◆ close()

void File::close ( )

Close the file.

This method closes the file, releasing any associated resources.

◆ flush()

void File::flush ( )

Flush the file buffer.

This method flushes the file buffer, writing any buffered data to the file.

◆ is_dir()

bool File::is_dir ( )

Check if the object represents a directory.

This method checks whether the File object represents a directory.

Returns
True if the object represents a directory, false otherwise.

◆ is_file()

bool File::is_file ( )

Check if the object represents a file.

This method checks whether the File object represents a file.

Returns
True if the object represents a file, false otherwise.

◆ is_ok()

bool File::is_ok ( )

Checks if the file is in a valid state.

This method checks if the file is in a valid state, i.e., if it has been successfully opened or created and is ready for reading or writing operations.

Returns
True if the file is in a valid state, false otherwise.

◆ lastwrite()

u64 File::lastwrite ( )

Get the timestamp of the last write operation on the file.

This method returns the timestamp of the last write operation performed on the file.

Returns
The timestamp of the last write operation.

◆ name()

string File::name ( )

Get the name of the file.

This method returns the name of the file.

Returns
The name of the file.

◆ next()

File File::next ( )

Get the next file in the directory.

This method returns the next file in the directory and advances the directory pointer.

Returns
A File object representing the next file in the directory.

◆ next_name()

string File::next_name ( )

Get the name of the next file in the directory.

This method returns the name of the next file in the directory without advancing the directory pointer.

Returns
The name of the next file in the directory.

◆ open()

File File::open ( string  file,
string  mode 
)
static

Open a file with the specified name and mode.

This method opens a file with the given name and mode. The mode parameter specifies the access mode for the file (e.g., "r" for reading, "w" for writing).

Parameters
fileThe name of the file to open.
modeThe mode in which to open the file (e.g., "r" for reading, "w" for writing).
Returns
A File object representing the opened file.

◆ path()

string File::path ( )

Get the path of the file.

This method returns the path of the file.

Returns
The path of the file.

◆ peek()

i32 File::peek ( )

Peek at the next byte in the file without consuming it.

This method peeks at the next byte in the file without consuming it.

Returns
The next byte in the file, or -1 if the end of the file is reached.

◆ position()

usize File::position ( )

Get the current position within the file.

This method returns the current position within the file.

Returns
The current position within the file.

◆ read()

i32 File::read ( )

Read a byte from the file.

This method reads a byte from the file and advances the file pointer.

Returns
The byte read from the file, or -1 if the end of the file is reached.

◆ rewind()

void File::rewind ( )

Rewind the directory pointer to the beginning of the current working directory.

This method rewinds the directory pointer to the beginning of the current working directory.

◆ seek()

bool File::seek ( u32  pos)

Set the current position within the file.

This method sets the current position within the file to the specified position.

Parameters
posThe position to set.
Returns
True if the position was successfully set, false otherwise.

◆ seek_dir()

bool File::seek_dir ( u64  position)

Set the current position within the directory.

This method sets the current position within the directory to the specified position.

Parameters
positionThe position to set.
Returns
True if the position was successfully set, false otherwise.

◆ size()

usize File::size ( )

Get the size of the file.

This method returns the size of the file.

Returns
The size of the file, in bytes.

◆ write() [1/2]

void File::write ( string  data)

Write a string to the file.

This method writes a string to the file at the current position.

Parameters
dataThe string to write to the file.

◆ write() [2/2]

void File::write ( u8  data)

Write a byte to the file.

This method writes a byte to the file at the current position.

Parameters
dataThe byte to write to the file.

The documentation for this class was generated from the following files: