https://github.com/rhaiscript/rhai-fs
Provides filesystem access for the Rhai scripting language.
https://github.com/rhaiscript/rhai-fs
filesystem lib rhai rhai-fs scripting-language
Last synced: 4 months ago
JSON representation
Provides filesystem access for the Rhai scripting language.
- Host: GitHub
- URL: https://github.com/rhaiscript/rhai-fs
- Owner: rhaiscript
- License: apache-2.0
- Created: 2022-10-04T03:08:14.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2023-10-25T09:20:17.000Z (almost 2 years ago)
- Last Synced: 2025-06-21T14:42:40.007Z (4 months ago)
- Topics: filesystem, lib, rhai, rhai-fs, scripting-language
- Language: Rust
- Homepage:
- Size: 60.5 KB
- Stars: 10
- Watchers: 3
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE.txt
Awesome Lists containing this project
README
# About `rhai-fs`
[](https://github.com/license/rhaiscript/rhai-fs)
[](https://crates.io/crates/rhai-fs/)
[](https://crates.io/crates/rhai-fs/)
[](https://docs.rs/rhai-fs/)This crate provides filesystem access for the [Rhai] scripting language.
## Usage
### `Cargo.toml`
```toml
[dependencies]
rhai-fs = "0.1.2"
```### [Rhai] script
```js
// Create a file or open and truncate if file is already created
let file = open_file("example.txt");
let blob_buf = file.read_blob();
print("file contents: " + blob_buf);
blob_buf.write_utf8(0..=0x20, "foobar");
print("new file contents: " + blob_buf);
file.write(blob_buf);
```### Rust source
```rust
use rhai::{Engine, EvalAltResult};
use rhai::packages::Package;
use rhai_fs::FilesystemPackage;fn main() -> Result<(), Box> {
// Create Rhai scripting engine
let mut engine = Engine::new();// Create filesystem package and add the package into the engine
let package = FilesystemPackage::new();
package.register_into_engine(&mut engine);// Print the contents of the file `Cargo.toml`.
let contents = engine.eval::(r#"open_file("Cargo.toml", "r").read_string()"#)?;
println!("{}", contents);Ok(())
}
```## Features
| Feature | Default | Description |
| :--------: | :------: | ---------------------------------------------------- |
| `no_index` | disabled | Enables support for `no_index` builds of [Rhai] |
| `sync` | disabled | Enables support for `sync` builds of [Rhai] |
| `metadata` | disabled | Enables support for generating package documentation |[Rhai]: https://rhai.rs