#s3 #amazon #ceph #aws

s3handler

An s3 handler for s3rs nu-shell-s3-plugin

37 releases

new 0.7.6 Jan 14, 2022
0.7.5 Nov 15, 2021
0.7.4 Jul 29, 2021
0.7.2 Mar 11, 2021
0.1.2 Mar 5, 2019

#159 in Web programming

Download history 308/week @ 2021-09-27 313/week @ 2021-10-04 203/week @ 2021-10-11 236/week @ 2021-10-18 255/week @ 2021-10-25 145/week @ 2021-11-01 161/week @ 2021-11-08 463/week @ 2021-11-15 309/week @ 2021-11-22 315/week @ 2021-11-29 432/week @ 2021-12-06 198/week @ 2021-12-13 128/week @ 2021-12-20 301/week @ 2021-12-27 241/week @ 2022-01-03 156/week @ 2022-01-10

842 downloads per month
Used in 3 crates (2 directly)

MIT license

155KB
3.5K SLoC

S3handler

Lint Code Base Build & Test

A s3 handler library for s3rs and nu-shell s3 plugin Here is the document.

Blocking API is ready

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();

Async API

Basic CRUD is implemented, other advance features are under developing. use s3handler = { features = ["tokio"] }

Download a file with 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 async handler to manipulate objects and buckets. This treat all data as pool and create a canal to bridge two pool. It is easy to management and sync data from folder to S3, S3 to S3, event folder to folder.

   +------+
   | 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();

Dependencies

~7–12MB
~269K SLoC