41 个版本
0.9.0 | 2023 年 2 月 7 日 |
---|---|
0.8.1 | 2022 年 10 月 13 日 |
0.8.0 | 2022 年 6 月 15 日 |
0.7.6 | 2022 年 1 月 14 日 |
0.1.2 | 2019 年 3 月 5 日 |
#933 in 网页编程
54 每月下载次数
在 2 crates 中使用
160KB
4K SLoC
S3handler
S3handler 是为 s3rs 和 nu-shell s3 插件 提供的 s3 处理器库。这里是 文档。
阻塞 API 已准备就绪
use s3handler = { features = ["blocking"] }
let config = s3handler::CredentialConfig{
host: "s3.us-east-1.amazonaws.com".to_string(),
access_key: "akey".to_string(),
secret_key: "skey".to_string(),
user: None,
region: None, // default will be treated as us-east-1
s3_type: None, // default will try to config as AWS S3 handler
secure: None, // dafault is false, because the integrity protect by HMAC
};
let mut handler = s3handler::Handler::from(&config);
let _ = handler.la();
异步 API
实现了基本的 CRUD,其他高级功能正在开发中。将此依赖项添加到您的 cargo.toml 中 s3handler = { features = ["tokio-async"] }
使用异步 API 下载文件 use s3handler = { features = ["tokio-async"] }
// Public resource
let s3_pool = s3handler::none_blocking::primitives::S3Pool::new("somewhere.in.the.world".to_string());
let obj = s3_pool.bucket("bucket_name").object("objcet_name");
async {
obj.download_file("/path/to/save/a/file").await;
};
S3 异步处理器,用于操作对象和存储桶。它将所有数据视为池,创建一个通道来连接两个池。它易于管理,并可以从文件夹同步数据到 S3、S3 到 S3、甚至从文件夹到文件夹。
+------+
| Pool | (UpPool) modify by `from_*` api
+------+
| ^
Pull | | Push
v |
+------+
| Pool | (DownPool) modify by `toward_*` api
+------+
use s3handler::none_blocking::traits::DataPool;
// Resource with AWS version 2 auth
let s3_pool = s3handler::none_blocking::primitives::S3Pool::new("somewhere.in.the.world".to_string())
.aws_v2("access-key".to_string(), "secrete-key".to_string());
let bucket = s3_pool.bucket("bucket_name");
// Actually the bucket is a unconnnected canal
assert!(!bucket.is_connect());
let canal = bucket.toward("/path/to/another/folder").unwrap();
// The canal bridges the two folder and ready to transfer data between bucket and folder
assert!(canal.is_connect());
canal.sync().await;
let s3_pool = S3Pool::new(env::var("S3_HOST").unwrap()).aws_v4(
akey.to_string(),
env::var("SECRET_KEY").unwrap(),
env::var("REGION").unwrap(),
);
let mut object_list = s3_pool
.bucket(&env::var("BUCKET_NAME").unwrap())
.list()
.await
.unwrap();
let obj = object_list.next_object().await.unwrap();
依赖项
~9–22MB
~346K SLoC