Rishka
RISC-V virtual runtime in C/C++ made for ESP32-WROVER
fs.h
Go to the documentation of this file.
1/*
2 * This file is part of the Rishka distribution (https://github.com/nthnn/rishka).
3 * Copyright (c) 2024 Nathanne Isip.
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 3.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
27#ifndef LIBRISHKA_FS_H
28#define LIBRISHKA_FS_H
29
30#include <librishka/types.h>
31
40class File final {
41private:
42 i32 handle;
44protected:
45 File(i32 _handle);
47public:
59 static File open(string file, string mode);
60
68 bool is_file();
69
77 bool is_dir();
78
86 i32 available();
87
95 i32 peek();
96
104 u64 lastwrite();
105
115 bool bufsize(usize size);
116
125 bool seek(u32 pos);
126
135 bool seek_dir(u64 position);
136
144 usize size();
145
153 usize position();
154
162 i32 read();
163
171 void write(u8 data);
172
180 void write(string data);
181
189 string path();
190
198 string name();
199
208 File next();
209
218 bool is_ok();
219
228 string next_name();
229
235 void flush();
236
242 void close();
243
249 void rewind();
250};
251
259class FS final {
260public:
269 static bool mkdir(const char* path);
270
279 static bool rmdir(const char* path);
280
289 static bool remove(const char* path);
290
299 static bool exists(const char* path);
300};
301
302#endif /* LIBRISHKA_FS_H */
Class for file system operations in Rishka applications.
Definition: fs.h:259
static bool rmdir(const char *path)
Remove a directory with the specified path.
Definition: librishka_fs.cpp:117
static bool exists(const char *path)
Check if a file or directory exists at the specified path.
Definition: librishka_fs.cpp:125
static bool remove(const char *path)
Remove a file with the specified path.
Definition: librishka_fs.cpp:121
static bool mkdir(const char *path)
Create a directory with the specified path.
Definition: librishka_fs.cpp:113
Class for handling file operations in Rishka applications.
Definition: fs.h:40
static File open(string file, string mode)
Open a file with the specified name and mode.
Definition: librishka_fs.cpp:25
bool is_dir()
Check if the object represents a directory.
Definition: librishka_fs.cpp:33
usize size()
Get the size of the file.
Definition: librishka_fs.cpp:49
bool is_file()
Check if the object represents a file.
Definition: librishka_fs.cpp:29
File(i32 _handle)
Definition: librishka_fs.cpp:21
string path()
Get the path of the file.
Definition: librishka_fs.cpp:69
usize position()
Get the current position within the file.
Definition: librishka_fs.cpp:53
i32 read()
Read a byte from the file.
Definition: librishka_fs.cpp:57
bool seek_dir(u64 position)
Set the current position within the directory.
Definition: librishka_fs.cpp:101
bool is_ok()
Checks if the file is in a valid state.
Definition: librishka_fs.cpp:81
u64 lastwrite()
Get the timestamp of the last write operation on the file.
Definition: librishka_fs.cpp:97
i32 peek()
Peek at the next byte in the file without consuming it.
Definition: librishka_fs.cpp:41
void rewind()
Rewind the directory pointer to the beginning of the current working directory.
Definition: librishka_fs.cpp:109
bool bufsize(usize size)
Set the buffer size for the file.
Definition: librishka_fs.cpp:93
void close()
Close the file.
Definition: librishka_fs.cpp:89
i32 available()
Get the number of bytes available for reading from the file.
Definition: librishka_fs.cpp:37
string next_name()
Get the name of the next file in the directory.
Definition: librishka_fs.cpp:105
bool seek(u32 pos)
Set the current position within the file.
Definition: librishka_fs.cpp:45
void write(u8 data)
Write a byte to the file.
Definition: librishka_fs.cpp:61
File next()
Get the next file in the directory.
Definition: librishka_fs.cpp:77
string name()
Get the name of the file.
Definition: librishka_fs.cpp:73
void flush()
Flush the file buffer.
Definition: librishka_fs.cpp:85
Header file for common data types used in Rishka applications.
signed int i32
Alias for the signed 32-bit integer type.
Definition: types.h:58
unsigned int u32
Alias for the unsigned 32-bit integer type.
Definition: types.h:82
unsigned char u8
Alias for the unsigned 8-bit integer type.
Definition: types.h:70
unsigned long int u64
Alias for the unsigned 64-bit integer type.
Definition: types.h:88
u32 usize
Alias for the unsigned integer type representing size.
Definition: types.h:94