Bedtime. /Storage API

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_pathStarting directory path (e.g., "/" for root)
const char*file_extensionFile extension filter (e.g., ".gb", ".txt") Set to NULL to show all files
browser_callback_tcallbackCallback 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*pathFile path (max 255 chars)
void*bufferOutput buffer
size_tbuffer_sizeSize 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*pathFile path (max 255 chars)
const void*bufferData to write
size_tsizeNumber 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*pathFile path (max 255 chars)
const void*bufferData to append
size_tsizeNumber 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*pathFile 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*pathDirectory 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*pathFile path (max 255 chars)

Returns — true if file exists

uint32_t storage_file_size(const char* path)

Get file size in bytes

const char*pathFile path (max 255 chars)

Returns — File size in bytes, or 0 if not found