Storage API
File I/O and browser operations
bool browser_open(const char* start_path, const char* file_extension, browser_callback_t callback)
Open file browser to select a file
| const char* | start_path | Starting directory path (e.g., "/" for root) |
| const char* | file_extension | File extension filter (e.g., ".gb", ".txt") Set to NULL to show all files |
| browser_callback_t | callback | Callback function called when file is selected |
Returns — true if browser launched successfully
bool on_file_selected(const char* path) {
// Load the file
storage_read_file(path, buffer, sizeof(buffer));
return true;
}
browser_open("/", ".txt", on_file_selected);uint32_t storage_read_file(const char* path, void* buffer, size_t buffer_size)
Read entire file into buffer
| const char* | path | File path (max 255 chars) |
| void* | buffer | Output buffer |
| size_t | buffer_size | Size of output buffer |
Returns — Number of bytes read, or 0 on error
uint8_t data[1024];
uint32_t bytes = storage_read_file("/config.bin", data, sizeof(data));
if (bytes > 0) {
// Process data
}uint32_t storage_write_file(const char* path, const void* buffer, size_t size)
Write entire file from buffer (overwrites existing)
| const char* | path | File path (max 255 chars) |
| const void* | buffer | Data to write |
| size_t | size | Number of bytes to write |
Returns — Number of bytes written, or 0 on error
uint32_t storage_append_file(const char* path, const void* buffer, size_t size)
Append data to existing file
| const char* | path | File path (max 255 chars) |
| const void* | buffer | Data to append |
| size_t | size | Number of bytes to append |
Returns — Number of bytes written, or 0 on error
bool storage_delete_file(const char* path)
Delete a file
| const char* | path | File path (max 255 chars) |
Returns — true on success, false if file doesn't exist or error
bool storage_mkdir(const char* path)
Create directory (and parent directories if needed)
| const char* | path | Directory path (max 255 chars) |
Returns — true on success (also returns true if directory already exists)
bool storage_file_exists(const char* path)
Check if file exists
| const char* | path | File path (max 255 chars) |
Returns — true if file exists
uint32_t storage_file_size(const char* path)
Get file size in bytes
| const char* | path | File path (max 255 chars) |
Returns — File size in bytes, or 0 if not found