yama/yama_wormfile_s3/examples/s3demo.rs

44 lines
1.2 KiB
Rust

use s3::creds::Credentials;
use s3::{Bucket, Region};
use std::time::Instant;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use yama_wormfile::paths::WormPath;
use yama_wormfile::{WormFileProvider, WormFileWriter};
use yama_wormfile_s3::S3WormFilesystem;
#[tokio::main]
async fn main() -> eyre::Result<()> {
let bucket = Bucket::new(
"yama-test-bucket",
Region::Custom {
region: "unknown".to_owned(),
endpoint: "https://gateway.storjshare.io".to_owned(),
},
Credentials::from_env_specific(Some("S3_ACCESS"), Some("S3_SECRET"), None, None)?,
)?
.with_path_style();
let s3fs = S3WormFilesystem::new(bucket, "yamademo/".to_owned()).unwrap();
let mut w = s3fs.write().await.unwrap();
w.write_all(b"hi lols").await?;
w.flush().await?;
w.finalise(WormPath::new("worms/xyz2").unwrap(), true)
.await?;
let start = Instant::now();
let mut r = s3fs.read(WormPath::new("worms/xyz").unwrap()).await?;
let mut buf = Vec::new();
r.read_u16().await?;
r.read_to_end(&mut buf).await?;
let end = Instant::now();
eprintln!(
"{:?} {}",
std::str::from_utf8(&buf),
(end - start).as_millis()
);
Ok(())
}