rhai-fs: Filesystem Access

rhai-fs is an independent Rhai package that enables reading from and writing to files in an external filesystem.


See https://docs.rs/rhai-fs for the list of functions.

On crates.io: rhai-fs

On GitHub: rhaiscript/rhai-fs

Package name: FilesystemPackage



rhai = "1.18.0"
rhai-fs = "0.1"       # use rhai-fs crate

Load Package into Engine

use rhai::Engine;
use rhai::packages::Package;    // needed for 'Package' trait
use rhai_fs::FilesystemPackage;

let mut engine = Engine::new();

// Create new 'FilesystemPackage' instance
let fs = FilesystemPackage::new();

// Load the package into the `Engine`
fs.register_into_engine(&mut engine);


// Create a file, or open it if already exists
let file = open_file("example.txt");

// Read the contents of the file (if any) into a BLOB
let blob_buf = file.read_blob();

print(`file contents: ${blob_buf}`);

// Update BLOB data
blob_buf.write_utf8(0..=0x20, "foobar");

print(`new file contents: ${blob_buf}`);

// Seek back to the beginning

// Overwrite the original file with new data


FeatureDescriptionDefault?Should be used with Rhai feature
no_arrayremoves support for arrays and BLOB’snono_index
metadataenables functions metadata (turns on metadata in Rhai)no