Chicon
A file abstraction system for Rust. Chicon is a library intends to provide a simple, uniform and universal API interacting with any filesystem, as an abstraction layer providing traits, types and methods. The main FileSystem trait is based on the usage of std::fs::* in order to be transparent when you want to switch from a physical filesystem to a virtual one like S3, SFTP, SSH and in-memory. It is suitable for any situation when you need to store directories and files on different filesystems. Memory file system can be appropriate when you write your tests in order to have faster behavior than an IO filesystem.
Examples
Use S3 as backend to create a file
use ;
use ;
let s3_fs = new;
let mut file = s3_fs.create_file.unwrap
file.write_all.unwrap;
file.sync_all.unwrap;
let mut content: String = Stringnew;
file.read_to_string.unwrap;
assert_eq!;
s3_fs.remove_file.unwrap; // If you want to delete the file
Use SFTP as backend to create a file
You just need to change from
S3FileSystem::newtoSFTPFileSystem::new.
use ;
use ;
let sftp_fs = new;
let mut file = sftp_fs.create_file.unwrap
file.write_all.unwrap;
file.sync_all.unwrap;
let mut content: String = Stringnew;
file.read_to_string.unwrap;
assert_eq!;
Use SSH as backend to read a file
use ;
use ;
let ssh_fs = new;
let mut file = ssh_fs.open_file.unwrap;
let mut buffer = Stringnew;
file.read_to_string.unwrap;
println!;
Use OS (local filesystem) as backend to create and read a directory
use ;
use ;
let os_fs = new;
os_fs.create_dir_all.unwrap;
os_fs.create_file.unwrap;
let dir_entries = os_fs.read_dir.unwrap;
assert!
assert_eq!
assert_eq!;
assert_eq!;
remove_dir_all.unwrap; // If you want to remove dir and all entries inside
If you need more examples, check-out all tests in the source code on Github
Roadmap:
- implement FS with swift
- implement seek trait for files
- refactor with more idiomatic Rust stuff