#amazon-s3 #minio #s3 #tokio

minio-rsc

适用于 Minio 的 Rust,API 与 Amazon S3 协议兼容

7 个版本

0.2.3 2024 年 7 月 22 日
0.2.1 2024 年 3 月 23 日
0.2.0 2023 年 9 月 22 日
0.1.5 2023 年 7 月 17 日
0.1.3 2023 年 3 月 15 日

#615网络编程

Download history 111/week @ 2024-05-02 88/week @ 2024-05-09 87/week @ 2024-05-16 200/week @ 2024-05-23 2047/week @ 2024-05-30 1672/week @ 2024-06-06 1145/week @ 2024-06-13 900/week @ 2024-06-20 891/week @ 2024-06-27 1140/week @ 2024-07-04 1104/week @ 2024-07-11 1318/week @ 2024-07-18 540/week @ 2024-07-25 1520/week @ 2024-08-01 846/week @ 2024-08-08 801/week @ 2024-08-15

每月下载量 3,812

MIT/Apache

235KB
5.5K SLoC

minio-rsc

Crates.io Documentation License

Minio 的 Rust 库。API 与 Amazon S3 协议兼容。

Minio 客户端

use minio_rsc::client::{BucketArgs, KeyArgs};
use minio_rsc::error::Result;
use minio_rsc::provider::StaticProvider;
use minio_rsc::Minio;

async fn example() -> Result<()> {
    let provider = StaticProvider::new("minio-access-key-test", "minio-secret-key-test", None);
    let minio = Minio::builder()
        .endpoint("localhost:9022")
        .provider(provider)
        .secure(false)
        .build()
        .unwrap();
    let (buckets, owner) = minio.list_buckets().await?;

    minio.make_bucket(BucketArgs::new("bucket1"), false).await?;
    minio.make_bucket("bucket2", true).await?;

    minio.put_object("bucket1", "hello.txt", "hello minio!".into()).await?;
    minio.stat_object("bucket1", "hello.txt").await?;
    minio.get_object("bucket1", "hello.txt").await?;
    let key = KeyArgs::new("hello.txt").version_id(Some("cdabf31a-9752-4265-b137-6b3961fbaf9b".to_string()));
    minio.get_object("bucket1", key).await?;
    minio.remove_object("bucket1", "hello.txt").await?;

    let bucket2 = minio.bucket("bucket2");
    bucket2.put_object("hello.txt", "hello minio!".into()).await?;
    bucket2.stat_object("hello.txt").await?;
    bucket2.get_object("hello.txt").await?;
    bucket2.remove_object("hello.txt").await?;

    // if fs-tokio feature enabled
    // download file to local
    minio.fget_object("bucket1", "hello.txt", "local.txt").await?;
    // upload file to minio
    minio.fput_object("bucket1", "hello.txt", "local.txt").await?;

    minio.remove_bucket("bucket1").await?;
    minio.remove_bucket("bucket2").await?;

    Ok(())
}

操作

存储桶操作 对象操作
make_bucket get_object
list_buckets fget_object
bucket_exists copy_object
remove_bucket stat_object
list_object_versions remove_object
list_objects put_object
get_bucket_tags fput_object
set_bucket_tags presigned_get_object
del_bucket_tags presigned_put_object
get_bucket_versioning is_object_legal_hold_enabled
set_bucket_versioning enable_object_legal_hold_enabled
get_object_lock_config disable_object_legal_hold_enabled
set_object_lock_config get_object_tags
del_object_lock_config set_object_tags
get_bucket_cors del_object_tags
set_bucket_cors get_object_retention
del_bucket_cors set_object_retention
get_bucket_encryption select_object_content
set_bucket_encryption
del_bucket_encryption

特性

自定义请求

BaseExecutor 实现

use minio_rsc::Minio;
use hyper::Method;
use minio_rsc::errors::Result;
use reqwest::Response;
use bytes::Bytes;

async fn get_object(minio:Minio)-> Result<Response> {
    let executor = minio.executor(Method::GET);
    let res: Response = executor
        .bucket_name("bucket")
        .object_name("test.txt")
        .query("versionId", "cdabf31a-9752-4265-b137-6b3961fbaf9b")
        .send_ok()
        .await?;
    Ok(res)
}

async fn put_object(minio:Minio, data:Bytes)-> Result<()> {
    let executor = minio.executor(Method::PUT);
    let res: Response = executor
        .bucket_name("bucket")
        .object_name("test.txt")
        .body(data)
        .send_ok()
        .await?;
    Ok(())
}

依赖项

~10–23MB
~338K SLoC