...
This commit is contained in:
100
packages/system/os/README.md
Normal file
100
packages/system/os/README.md
Normal file
@@ -0,0 +1,100 @@
|
||||
# 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 installation
|
||||
- `package`: System package management
|
||||
- `platform`: Platform and architecture detection
|
||||
|
||||
## Usage
|
||||
|
||||
Add this to your `Cargo.toml`:
|
||||
|
||||
```toml
|
||||
[dependencies]
|
||||
sal-os = "0.1.0"
|
||||
```
|
||||
|
||||
### File System Operations
|
||||
|
||||
```rust
|
||||
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
|
||||
|
||||
```rust
|
||||
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
|
||||
|
||||
```rust
|
||||
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:
|
||||
|
||||
```rhai
|
||||
// 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");
|
||||
}
|
||||
```
|
Reference in New Issue
Block a user