Filesystem Library
Stof filesystem library ("fs").
The filesystem library is a part of Stof, however, is separately organized because it is system-dependent and cannot (and should not) be broadly implemented for all embedded environments.
All Stof filesystem calls go through this library though, so if this library is replicated or added in other environments, those features of Stof will work (primarily import statements). For example, in TypeScript, server environments (like Deno or Node.js) have filesystem calls that can be used to give Stof access to filesystem resources, but must do so explicitly (Stof is meant to be in the dark by default).
fs.write(path: str, contents: str): void
Will create a text file at the given path with the provided contents if it does not exist and will entirely replace its contents if it does.
fs.write_blob(path: str, contents: blob): void
Will create a binary file at the given path with the provided blob content if it does not exist and will entirely replace its contents if it does.
fs.read(path: str): str
Reads a text file into a string. Will throw an error if the file does not exist.
Used in format implementations to read text files (up to the format to decide). Implementing this library function will enable Stof to import files of any format that uses it.
For anyone implementing a custom format, the helper function "fs_read_string" exists on the Rust Stof document to make this easy, ensuring other embedded environments have access.
fs.read_blob(path: str): blob
Reads a binary file into a blob. Will throw an error if the file does not exist.
Used in format implementations to read binary files (up to the format to decide). Implementing this library function will enable Stof to import files of any format that uses it.
For anyone implementing a custom format, the helper function "fs_read_blob" exists on the Rust Stof document to make this easy, ensuring other embedded environments have access.
Last updated
Was this helpful?