use chrono::prelude::*;
use std::io::Read;
use vfs::VfsPath;
use vfs_https::HttpsFS;
fn main() -> vfs::VfsResult<()> {
let builder = HttpsFS::builder("localhost")
.set_port(8443)
.add_root_certificate("examples/cert/cert.crt")
.set_credential_provider(|server_msg| {
println!(
"Server request authentification with message \"{}\".",
server_msg
);
(String::from("user"), String::from("pass"))
});
let root: VfsPath = builder.build()?.into();
let root = root.join("example.txt")?;
if !root.exists()? {
root.create_file()?;
}
let mut file = root.append_file()?;
let time = Local::now();
let line = format!("{}: Hello HttpsFS!\n", time);
file.write(line.as_bytes())?;
let file = root.open_file()?;
let mut buffed_file = std::io::BufReader::new(file);
let mut content = String::new();
buffed_file.read_to_string(&mut content)?;
println!("Content of example.txt: \n{}", content);
Ok(())
}