Skip to content

Latest commit

 

History

48 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

npio - Nepsod Input-Output

License

GIO-inspired Rust library for Linux filesystem and device I/O. Provides async, URI-based file operations, directory monitoring, thumbnails, and volume management.

Features

  • URI-based filesystem abstraction - Unified API for local and remote files
  • Async-first - Built on Tokio for high-performance I/O
  • Directory monitoring - Real-time file system change notifications
  • Thumbnail service - Automatic thumbnail generation and caching
  • Volume monitoring - Device and mount point tracking
  • Pluggable backends - Extensible architecture for different URI schemes

Usage

[dependencies]
npio = { path = "../npio" }
tokio = { version = "1", features = ["full"] }
use npio::{get_file_for_uri, register_backend};
use npio::backend::local::LocalBackend;
use std::sync::Arc;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    register_backend(Arc::new(LocalBackend::new()));

    let file = get_file_for_uri("file:///home/user/document.txt")?;
    let info = file.query_info("standard::*,time::modified", None).await?;
    println!("{}: {} bytes", info.get_name().unwrap_or("unknown"), info.get_size());
    
    Ok(())
}

Core API

File Operations

let file = get_file_for_uri("file:///path/to/file")?;
file.copy(&dest, CopyFlags::OVERWRITE, None, None).await?;
file.trash(None).await?;

Directory Monitoring

let model = DirectoryModel::new(file);
model.load(None).await?;
let mut rx = model.subscribe();
while let Ok(update) = rx.recv().await {
    match update {
        DirectoryUpdate::Added(info) => println!("Added: {}", info.get_name().unwrap_or("unknown")),
        _ => {}
    }
}

Thumbnails

let service = ThumbnailService::new();
if let Some(path) = service.get_thumbnail_path(&*file, ThumbnailSize::Normal, None).await? {
    println!("Thumbnail: {:?}", path);
}

Volume Monitoring

let monitor = VolumeMonitor::new();
monitor.start(None).await?;
let mut rx = monitor.subscribe();
while let Ok(event) = rx.recv().await {
    match event {
        VolumeMonitorEvent::MountAdded { mount } => println!("Mounted: {}", mount),
        _ => {}
    }
}

Backends

  • LocalBackend - Local filesystem operations
  • MountBackend - Mount point management
  • UDisks2Backend - Device management via UDisks2
  • ThumbnailBackend - Thumbnail generation

Examples

cargo run --example file_copy -- /path/to/source /path/to/dest
cargo run --example directory_listing -- /path/to/directory

Documentation

License

LGPL-3.0-or-later - see LICENSE.txt

About

Nepsod Input-Output library

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages