10 releases

0.2.4 Dec 26, 2023
0.2.3 May 23, 2023
0.2.2 Dec 23, 2022
0.2.1 Nov 1, 2022
0.1.2 Jun 9, 2022

#412 in Authentication

Download history 309/week @ 2024-02-26 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

71 downloads per month
Used in qiniu-sdk

MIT license

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

联系我们

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

代码许可

This project is licensed under the MIT license.

Dependencies

~12–31MB
~541K SLoC