10 releases

0.1.9 Apr 29, 2021
0.1.8 Apr 29, 2021
0.1.6 Mar 29, 2021

#62 in #cloud-storage

Download history 75/week @ 2024-07-23 52/week @ 2024-07-30 44/week @ 2024-08-06 159/week @ 2024-08-13 118/week @ 2024-08-20 93/week @ 2024-08-27 159/week @ 2024-09-03 142/week @ 2024-09-10 201/week @ 2024-09-17 126/week @ 2024-09-24 158/week @ 2024-10-01 148/week @ 2024-10-08 216/week @ 2024-10-15 102/week @ 2024-10-22 104/week @ 2024-10-29 141/week @ 2024-11-05

615 downloads per month

MIT license

43KB
923 lines

cloud-storage-lite

A simple, flexible Google Cloud Storage client (GCS).

This library isn't as featureful as, say the cloud-storage crate, but it's also more usable if you:

  • are using a secret keeper like Vault
  • generally work with a single bucket (using a bucket-scoped client)
  • would like to use multiple clients or tokio runtimes in one program
  • want canonicalized errors (404 gets one and only one error variant)

Example

use std::{error::Error, convert::Infallible};
use cloud_storage_lite::{
 self as gcs,
 client::BucketClient,
 token_provider::{
   self,
   oauth::{self, OAuthTokenProvider, ServiceAccount}},
};
use futures::{future, stream, TryStreamExt};

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error + 'static>> {
  let token_provider =
    token_provider::RenewingTokenProvider::new(
      OAuthTokenProvider::new(
        ServiceAccount::read_from_canonical_env()?,
        oauth::SCOPE_STORAGE_FULL_CONTROL,
      )?
    );
  let client = gcs::Client::new(token_provider)
    .into_bucket_client("my-bucket".into());

  client
    .create_object(
      "key",
      stream::once(
        future::ok::<_, Infallible>(b"value".to_vec())
      )
    )
    .await?;

  let object = client.get_object("key").await?;

  let value_bytes = client
    .download_object(&object.name)
    .await?
    .map_ok(|chunk| chunk.to_vec())
    .try_concat()
    .await?;

  println!(
    "the value is: {}",
    String::from_utf8(value_bytes)?
  );

  Ok(())
}

Dependencies

~8–22MB
~329K SLoC