Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
bujnlc8 committed Aug 23, 2024
1 parent aa07f26 commit ef6eda9
Show file tree
Hide file tree
Showing 9 changed files with 241 additions and 289 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Changelog

## [0.1.12] - 2024-08-23

### Changed

- 优化文件的下载,支持边下载边保存

- 移除`async-trait`依赖,不再基于 trait 来实现方法

### Added

- 新增 object `get_object_binary_range`方法,分块获取文件数据

## [0.1.11] - 2024-08-17

### Fixed
Expand Down
5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[package]
name = "qcos"
version = "0.1.11"
version = "0.1.12"
edition = "2021"
authors = ["bujnlc8 <[email protected]>"]
description = "provide basic interface encapsulation of Tencent Cloud Object Storage (cos)"
description = "Provide basic interface encapsulation of Tencent Cloud Object Storage (cos)"
repository = "https://github.com/bujnlc8/qcos"
license = "MIT"
keywords = ["cos", "tengxunyun", "tencentcloud", "qcos"]
Expand All @@ -18,7 +18,6 @@ sha1 = "0.10.6"
urlencoding = "2.1.3"
mime = "0.3.17"
quick-xml = {version = "0.36.1", features = ["serialize"]}
async-trait = "0.1.81"
tokio = { version = "1.39.2", features = ["full"]}
indicatif = { version = "0.17.8", optional = true }
futures-util = { version = "0.3.30", optional = true }
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
use std::path::PathBuf;
use qcos::acl::{AclHeader, ObjectAcl};
use qcos::client::Client;
use qcos::objects::{mime, ErrNo, Objects};
use qcos::objects::{mime, ErrNo};

#[tokio::main]
async fn main() {
Expand Down Expand Up @@ -71,12 +71,12 @@ async fn main() {

```
[dependencies]
qcos = "0.1.11"
qcos = "0.1.12"
```

如果需要开启显示进度条的方法:

```
[dependencies]
qcos = {version = "0.1.11", features=["progress-bar"]}
qcos = {version = "0.1.12", features=["progress-bar"]}
```
2 changes: 0 additions & 2 deletions examples/bucket.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
//! bucket管理
use qcos::acl::{AclHeader, BucketAcl};
use qcos::bucket::Bucket;
use qcos::client::Client;
use qcos::request::ErrNo;
use qcos::service::Service;

#[tokio::main]
async fn main() {
Expand Down
6 changes: 3 additions & 3 deletions examples/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ use std::path::PathBuf;

use qcos::acl::{AclHeader, ObjectAcl};
use qcos::client::Client;
use qcos::objects::{mime, Objects};
use qcos::objects::mime;
use qcos::request::ErrNo;

#[tokio::main]
async fn main() {
let client = Client::new(
"Your secrect id",
"Your secrect key",
"your secrect id",
"your secrect key",
"bucket name",
"region",
);
Expand Down
47 changes: 9 additions & 38 deletions src/bucket.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! bucket相关接口
//! bucket相关接口 方法见 [`crate::client::Client`#impl-Client]
use crate::client::Client;

Expand All @@ -8,40 +8,15 @@ use reqwest::Body;
use crate::acl::AclHeader;
use std::collections::HashMap;

#[async_trait::async_trait]
pub trait Bucket {
/// 在指定账号下创建一个存储桶
/// 创建存储桶时,如果没有指定访问权限,则默认使用私有读写(private)权限。
async fn put_bucket(&self, acl_header: Option<AclHeader>) -> Response;
// 为了兼容以前的版本
pub struct Bucket;

/// 用于删除指定的存储桶。该 API 的请求者需要对存储桶有写入权限。
async fn delete_bucket(&self) -> Response;

/// 可以列出该存储桶内的部分或者全部对象。该 API 的请求者需要对存储桶有读取权限。
async fn list_objects(
&self,
prefix: &str,
delimiter: &str,
encoding_type: &str,
marker: &str,
max_keys: i32,
) -> Response;

/// 检查bucket状态
async fn check_bucket(&self) -> Response;

/// 写入存储桶的访问控制列表(ACL)
async fn put_bucket_acl(&self, acl_header: AclHeader) -> Response;
}

#[async_trait::async_trait]
impl Bucket for Client {
impl Client {
/// 创建一个存储桶
/// <https://cloud.tencent.com/document/product/436/7738>
/// # Examples
/// ```
/// use qcos::client::Client;
/// use qcos::bucket::Bucket;
/// use qcos::acl::{AclHeader, BucketAcl};
/// async {
/// let mut acl_header = AclHeader::new();
Expand All @@ -51,7 +26,7 @@ impl Bucket for Client {
/// assert!(res.error_message.contains("403"));
/// };
/// ```
async fn put_bucket(&self, acl_header: Option<AclHeader>) -> Response {
pub async fn put_bucket(&self, acl_header: Option<AclHeader>) -> Response {
let headers = self.get_headers_with_auth("put", "/", acl_header, None, None);
let resp = Request::put(
self.get_full_url_from_path("/").as_str(),
Expand All @@ -69,14 +44,13 @@ impl Bucket for Client {
/// # Examples
/// ```
/// use qcos::client::Client;
/// use qcos::bucket::Bucket;
/// async {
/// let client = Client::new("foo", "bar", "qcloudtest-xxx", "ap-guangzhou");
/// let res = client.delete_bucket().await;
/// assert!(res.error_message.contains("403"));
/// };
/// ```
async fn delete_bucket(&self) -> Response {
pub async fn delete_bucket(&self) -> Response {
let headers = self.get_headers_with_auth("delete", "/", None, None, None);
let resp = Request::delete(
self.get_full_url_from_path("/").as_str(),
Expand All @@ -93,14 +67,13 @@ impl Bucket for Client {
/// # Examples
/// ```
/// use qcos::client::Client;
/// use qcos::bucket::Bucket;
/// async {
/// let client = Client::new("foo", "bar", "qcloudtest-xxx", "ap-guangzhou");
/// let res = client.list_objects("prefix", "", "", "/", 100).await;
/// assert!(res.error_message.contains("403"));
/// };
/// ```
async fn list_objects(
pub async fn list_objects(
&self,
prefix: &str,
delimiter: &str,
Expand Down Expand Up @@ -142,14 +115,13 @@ impl Bucket for Client {
/// # Examples
/// ```
/// use qcos::client::Client;
/// use qcos::bucket::Bucket;
/// async {
/// let client = Client::new("foo", "bar", "qcloudtest-xxx", "ap-guangzhou");
/// let res = client.check_bucket().await;
/// assert!(res.error_message.contains("403"));
/// };
/// ```
async fn check_bucket(&self) -> Response {
pub async fn check_bucket(&self) -> Response {
let headers = self.get_headers_with_auth("head", "/", None, None, None);
let resp = Request::head(
self.get_full_url_from_path("/").as_str(),
Expand All @@ -164,7 +136,6 @@ impl Bucket for Client {
/// # Examples
/// ```
/// use qcos::client::Client;
/// use qcos::bucket::Bucket;
/// use qcos::acl::{AclHeader, BucketAcl};
/// async {
/// let mut acl_header = AclHeader::new();
Expand All @@ -174,7 +145,7 @@ impl Bucket for Client {
/// assert!(res.error_message.contains("403"));
/// };
/// ```
async fn put_bucket_acl(&self, acl_header: AclHeader) -> Response {
pub async fn put_bucket_acl(&self, acl_header: AclHeader) -> Response {
let mut query = HashMap::new();
query.insert("acl".to_string(), String::new());
let headers =
Expand Down
23 changes: 11 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@
基本用法:
```
use std::path::PathBuf;
use qcos::client::Client;
use qcos::objects::Objects;
use mime;
use std::path::PathBuf;
use qcos::client::Client;
use mime;
#[tokio::main]
async fn main() {
let client = Client::new("foo", "bar", "qcloudtest-xxx", "ap-guangzhou");
/// 上传文件
let res = client.put_object(&PathBuf::from("Cargo.toml"), "Cargo.toml", Some(mime::TEXT_PLAIN_UTF_8), None).await;
/// 删除文件
let res = client.delete_object("Cargo.toml").await;
}
#[tokio::main]
async fn main() {
let client = Client::new("foo", "bar", "qcloudtest-xxx", "ap-guangzhou");
/// 上传文件
let res = client.put_object(&PathBuf::from("Cargo.toml"), "Cargo.toml", Some(mime::TEXT_PLAIN_UTF_8), None).await;
/// 删除文件
let res = client.delete_object("Cargo.toml").await;
}
```
*/

Expand Down
Loading

0 comments on commit ef6eda9

Please sign in to comment.