10个版本

0.2.4 2023年12月26日
0.2.3 2023年5月23日
0.2.2 2022年12月23日
0.2.1 2022年11月1日
0.1.2 2022年6月9日

#300认证

Download history 3/week @ 2024-03-11 37/week @ 2024-04-01 20/week @ 2024-04-08 3/week @ 2024-04-22 3/week @ 2024-04-29 8/week @ 2024-05-06 10/week @ 2024-05-13 24/week @ 2024-05-20 17/week @ 2024-05-27 13/week @ 2024-06-03 16/week @ 2024-06-10 15/week @ 2024-06-17 35/week @ 2024-06-24

每月82次 下载
qiniu-sdk 中使用

MIT 许可证

1MB
25K SLoC

Qiniu-Objects-Manager

qiniu-objects-manager docs.rs Run Test Cases GitHub release MIT licensed

概述

基于 qiniu-apis 提供针对七牛对象的管理功能(同时提供阻塞客户端和异步客户端,异步客户端则需要启用 async 功能),主要负责七牛对象的列举和操作。

安装

不启用异步接口,推荐使用 ureq

[dependencies]
qiniu-objects-manager = { version = "0.2.1", features = ["ureq"] }

启用 Isahc 异步接口

[dependencies]
qiniu-objects-manager = { version = "0.2.1", features = ["async", "isahc"] }

启用 Reqwest 异步接口

[dependencies]
qiniu-objects-manager = { version = "0.2.1", features = ["async", "reqwest"] }

其他功能

c_ares

启用 c-ares 库作为 DNS 解析器

trust_dns

启用 trust-dns 库作为 DNS 解析器

dns-over-https

启用 trust-dns 库作为 DNS 解析器,并使用 DOH 协议

dns-over-tls

启用 trust-dns 库作为 DNS 解析器,并使用 DOT 协议

代码示例

阻塞代码示例

对象元信息获取

use qiniu_objects_manager::{apis::credential::Credential, ObjectsManager};

let credential = Credential::new("abcdefghklmnopq", "1234567890");
let object_manager = ObjectsManager::new(credential);
let bucket = object_manager.bucket("test-bucket");

let response = bucket.stat_object("test-key").call()?;
let object = response.into_body();
println!("fsize: {}", object.get_size_as_u64());
println!("hash: {}", object.get_hash_as_str());
println!("mime_type: {}", object.get_mime_type_as_str());

对象批量元信息获取

use qiniu_objects_manager::{apis::credential::Credential, ObjectsManager, OperationProvider};
use futures::stream::TryStreamExt;

let credential = Credential::new("abcdefghklmnopq", "1234567890");
let object_manager = ObjectsManager::new(credential);
let bucket = object_manager.bucket("test-bucket");
let mut ops = bucket.batch_ops();
ops.add_operation(bucket.stat_object("test-file-1"));
ops.add_operation(bucket.stat_object("test-file-2"));
ops.add_operation(bucket.stat_object("test-file-3"));
ops.add_operation(bucket.stat_object("test-file-4"));
ops.add_operation(bucket.stat_object("test-file-5"));
let mut iter = ops.call();
while let Some(object) = iter.next() {
    let object = object?;
    println!("fsize: {:?}", object.get_size_as_u64());
    println!("hash: {:?}", object.get_hash_as_str());
    println!("mime_type: {:?}", object.get_mime_type_as_str());
}

对象列举

use qiniu_objects_manager::{apis::credential::Credential, ObjectsManager};
use futures::stream::TryStreamExt;

let credential = Credential::new("abcdefghklmnopq", "1234567890");
let object_manager = ObjectsManager::new(credential);
let bucket = object_manager.bucket("test-bucket");
let mut iter = bucket.list().iter();
while let Some(object) = iter.next() {
    let object = object?;
    println!("fsize: {:?}", object.get_size_as_u64());
    println!("hash: {:?}", object.get_hash_as_str());
    println!("mime_type: {:?}", object.get_mime_type_as_str());
}

异步代码示例

对象元信息获取

use qiniu_objects_manager::{apis::credential::Credential, ObjectsManager};

let credential = Credential::new("abcdefghklmnopq", "1234567890");
let object_manager = ObjectsManager::new(credential);
let bucket = object_manager.bucket("test-bucket");

let response = bucket.stat_object("test-key").async_call().await?;
let object = response.into_body();
println!("fsize: {}", object.get_size_as_u64());
println!("hash: {}", object.get_hash_as_str());
println!("mime_type: {}", object.get_mime_type_as_str());

对象批量元信息获取

use qiniu_objects_manager::{apis::credential::Credential, ObjectsManager, OperationProvider};
use futures::stream::TryStreamExt;

let credential = Credential::new("abcdefghklmnopq", "1234567890");
let object_manager = ObjectsManager::new(credential);
let bucket = object_manager.bucket("test-bucket");
let mut ops = bucket.batch_ops();
ops.add_operation(bucket.stat_object("test-file-1"));
ops.add_operation(bucket.stat_object("test-file-2"));
ops.add_operation(bucket.stat_object("test-file-3"));
ops.add_operation(bucket.stat_object("test-file-4"));
ops.add_operation(bucket.stat_object("test-file-5"));
let mut stream = ops.async_call();
while let Some(object) = stream.try_next().await? {
    println!("fsize: {:?}", object.get_size_as_u64());
    println!("hash: {:?}", object.get_hash_as_str());
    println!("mime_type: {:?}", object.get_mime_type_as_str());
}

对象列举

use qiniu_objects_manager::{apis::credential::Credential, ObjectsManager};
use futures::stream::TryStreamExt;

let credential = Credential::new("abcdefghklmnopq", "1234567890");
let object_manager = ObjectsManager::new(credential);
let bucket = object_manager.bucket("test-bucket");
let mut stream = bucket.list().stream();
while let Some(object) = stream.try_next().await? {
    println!("fsize: {:?}", object.get_size_as_u64());
    println!("hash: {:?}", object.get_hash_as_str());
    println!("mime_type: {:?}", object.get_mime_type_as_str());
}

最低支持的 Rust 版本(MSRV)

1.70.0

联系我们

  • 如需帮助,请提交工单(在门户右侧点击咨询和建议提交工单,或者直接向 [email protected] 发送邮件)
  • 如有问题,可到问答社区提问,问答社区
  • 更详细的文档,见官方文档站
  • 如发现bug,欢迎提交 Issue
  • 如有功能需求,欢迎提交 Issue
  • 如要提交代码,欢迎提交 Pull Request
  • 欢迎关注我们的微信 微博,及时获取动态信息。

代码许可

本项目采用 MIT 许可证

依赖

~12–34MB
~553K SLoC