Some checks are pending
Rhai Tests / Run Rhai Tests (push) Waiting to run
- Add a new `sal-os` package containing OS interaction utilities. - Update workspace members to include the new package. - Add README and basic usage examples for the new package. |
||
---|---|---|
.. | ||
src | ||
tests | ||
Cargo.toml | ||
README.md |
SAL OS Package (sal-os
)
The sal-os
package provides a comprehensive suite of operating system interaction utilities. It offers a cross-platform abstraction layer for common OS-level tasks, simplifying system programming in Rust.
Features
- File System Operations: Comprehensive file and directory manipulation
- Download Utilities: File downloading with automatic extraction support
- Package Management: System package manager integration
- Platform Detection: Cross-platform OS and architecture detection
- Rhai Integration: Full scripting support for all OS operations
Modules
fs
: File system operations (create, copy, delete, find, etc.)download
: File downloading and basic installationpackage
: System package managementplatform
: Platform and architecture detection
Usage
Add this to your Cargo.toml
:
[dependencies]
sal-os = "0.1.0"
File System Operations
use sal_os::fs;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create directory
fs::mkdir("my_dir")?;
// Write and read files
fs::file_write("my_dir/example.txt", "Hello from SAL!")?;
let content = fs::file_read("my_dir/example.txt")?;
// Find files
let files = fs::find_files(".", "*.txt")?;
Ok(())
}
Download Operations
use sal_os::download;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Download and extract archive
let path = download::download("https://example.com/archive.tar.gz", "/tmp", 1024)?;
// Download specific file
download::download_file("https://example.com/script.sh", "/tmp/script.sh", 0)?;
download::chmod_exec("/tmp/script.sh")?;
Ok(())
}
Platform Detection
use sal_os::platform;
fn main() {
if platform::is_linux() {
println!("Running on Linux");
}
if platform::is_arm() {
println!("ARM architecture detected");
}
}
Rhai Integration
The package provides full Rhai scripting support:
// File operations
mkdir("test_dir");
file_write("test_dir/hello.txt", "Hello World!");
let content = file_read("test_dir/hello.txt");
// Download operations
download("https://example.com/file.zip", "/tmp", 0);
chmod_exec("/tmp/script.sh");
// Platform detection
if is_linux() {
print("Running on Linux");
}
License
Licensed under the Apache License, Version 2.0.