Chicon
A file abstraction system for Rust. Chicon is a library meant to provide a simple, uniform and universal API interacting with any filesystem. Chicon behaves 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 switching from a physical filesystem to a virtual one like S3, SFTP, SSH or in-memory. Chicon is suitable for any situation where storing directories and files on different filesystems is needed. Memory file system can be appropriate to write tests in order to have a faster execution than with 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 = String new;
file.read_to_string.unwrap;
assert_eq!;
s3_fs.remove_file.unwrap; // To delete the file
Use SFTP as backend to create a file
You just need to change from
S3FileSystem::new
toSFTPFileSystem::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 = String new;
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 = String new;
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; // To remove dir and all entries inside
If you need more examples, checkout the tests in the source code on the GitHub repository.
Roadmap
- implement swift as a new backend
- refactor with more idiomatic Rust stuff
- add async support