Storage API
File I/O and browser operations
The storage API provides sandboxed file I/O for reading and writing files on the SD card. All paths are relative to the SD card root.
Path Format
- Paths start with "/" (root of SD card)
- Example: "/myapp/data.bin"
- Maximum path length: 255 characters
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);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
}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 (must be > 0) |
Returns — Number of bytes written, or 0 on error
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
Delete a file
| const char* | path | File path (max 255 chars) |
Returns — true on success, false if file doesn't exist or error
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)
Check if file exists
| const char* | path | File path (max 255 chars) |
Returns — true if file exists
Get file size in bytes
| const char* | path | File path (max 255 chars) |
Returns — File size in bytes, or 0 if not found