Unified File System (FS)
Unified File System API for reading, writing, streaming, and managing files across internal flash and external SD card storage in KryonOS.
Global Object: FS
The FS global object provides a unified virtual file system interface in KryonOS. It dynamically routes operations between external SD Card storage and internal high-speed flash memory.
Firmware driver details are available in the KryonOS GitHub Repository.
Storage Mount Points
| Mount Prefix | Underlying Medium | Characteristics |
|---|---|---|
/local/ | Internal SPIFFS / LittleFS Flash | High-speed, non-removable, optimized for configurations and scripts. |
/sd/ | External SPI / SDMMC Card | High-capacity, removable, recommended for large assets, audio, and datasets. |
Paths without a mount prefix default automatically to /local/. However, using explicit prefixes such as /local/app.json or /sd/models/scene.3d is best practice.
File Operations
FS.exists(path)
Checks if a file or directory exists at the given path.
- Parameters:
path(String) - Returns:
Boolean
FS.readFile(path)
Reads the entire contents of a text file into memory.
- Parameters:
path(String) - Returns:
String(ornullif the file could not be read).
FS.writeFile(path, data)
Overwrites or creates a file with the provided text or byte data.
- Parameters:
path(String)data(StringorArrayBuffer)
- Returns:
Boolean(trueif successful).
FS.appendFile(path, data)
Appends text or byte data to the end of an existing file.
- Parameters:
path(String)data(StringorArrayBuffer)
- Returns:
Boolean
FS.deleteFile(path)
Removes a file from the file system.
- Parameters:
path(String) - Returns:
Boolean
FS.renameFile(oldPath, newPath)
Renames or moves a file to a new target path on the same volume.
- Parameters:
oldPath(String)newPath(String)
- Returns:
Boolean
FS.getFileSize(path)
Returns the size of the file in bytes.
- Parameters:
path(String) - Returns:
Integer(or-1if the file does not exist).
Directory Management
FS.mkdir(path)
Creates a new directory.
- Parameters:
path(String) - Returns:
Boolean
FS.listDir(path)
Lists all entries within a directory.
- Parameters:
path(String) - Returns:
Arrayof directory item objects.
Each entry object contains:
name(String): File or folder name.size(Integer): Size in bytes (0 for directories).isDir(Boolean):trueif the entry is a subdirectory.
Code Example: JSON Configuration Manager
// Reading and saving structured JSON configurations
var CONFIG_FILE = "/local/settings.json";
function loadSettings() {
if (!FS.exists(CONFIG_FILE)) {
var defaultSettings = {
brightness: 80,
soundVolume: 50,
theme: "dark"
};
FS.writeFile(CONFIG_FILE, JSON.stringify(defaultSettings));
return defaultSettings;
}
var raw = FS.readFile(CONFIG_FILE);
try {
return JSON.parse(raw);
} catch(e) {
System.print("Failed to parse settings JSON: " + e);
return null;
}
}
function saveSettings(settingsObj) {
var serialized = JSON.stringify(settingsObj);
return FS.writeFile(CONFIG_FILE, serialized);
}
// Usage
var appConfig = loadSettings();
System.print("Brightness setting: " + appConfig.brightness);