# OS Module - Quick Reference

## Rust API

### File System (fs)

```rust
use herolib_system::os::*;

copy(src, dest) -> Result<String, FsError>           // Copy file/dir
copy_bin(src) -> Result<String, FsError>             // Copy to ~/hero/bin/
exist(path) -> bool                                   // Check if exists
find_file(dir, name) -> Result<String, FsError>      // Find first file
find_files(dir, name) -> Result<Vec<String>, FsError>// Find all files
find_dir(dir, name) -> Result<String, FsError>       // Find first dir
find_dirs(dir, name) -> Result<Vec<String>, FsError> // Find all dirs
delete(path) -> Result<String, FsError>              // Delete recursively
mkdir(path) -> Result<String, FsError>               // Create dir
file_size(path) -> Result<i64, FsError>              // Size in bytes
rsync(src, dest) -> Result<String, FsError>          // Sync dirs
chdir(path) -> Result<String, FsError>               // Change dir
file_read(path) -> Result<String, FsError>           // Read content
file_write(path, content) -> Result<String, FsError> // Write file
file_write_append(path, content) -> Result<String, FsError>
mv(src, dest) -> Result<String, FsError>             // Move/rename
which(cmd) -> String                                  // Find command
cmd_ensure_exists(cmds) -> Result<String, FsError>   // Verify commands
chmod_exec(path) -> Result<String, FsError>          // Make executable
```

### Download

```rust
download(url, dest, min_kb) -> Result<String, DownloadError>
download_file(url, dest, min_kb) -> Result<String, DownloadError>
download_install(url, min_kb) -> Result<String, DownloadError>  // To ~/hero/bin/
```

### Package Management

```rust
execute_package_command(args, debug) -> Result<CommandResult, PackageError>
set_thread_local_debug(bool)
thread_local_debug() -> bool
```

### Platform Detection

```rust
is_osx() -> bool
is_linux() -> bool
is_arm() -> bool
is_x86() -> bool
check_linux_x86() -> Result<(), PlatformError>
check_macos_arm() -> Result<(), PlatformError>
```

### Rust Example

```rust
use herolib_system::os::{mkdir, file_write, file_read, delete, download_install};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    mkdir("/tmp/mydir")?;
    file_write("/tmp/mydir/test.txt", "hello")?;
    let content = file_read("/tmp/mydir/test.txt")?;
    delete("/tmp/mydir")?;
    
    download_install("https://example.com/tool", 100)?;
    Ok(())
}
```
