Crate object_store_opendal

source ·
Expand description

object_store_opendal is an object store implementation using opendal.

This crate can help you to access 30 more storage services with the same object_store API.

use std::sync::Arc;

use bytes::Bytes;
use object_store::path::Path;
use object_store::ObjectStore;
use object_store_opendal::OpendalStore;
use opendal::services::S3;
use opendal::{Builder, Operator};

#[tokio::main]
async fn main() {
   let builder = S3::default()
    .access_key_id("my_access_key")
    .secret_access_key("my_secret_key")
    .endpoint("my_endpoint")
    .region("my_region");

    // Create a new operator
    let operator = Operator::new(builder).unwrap().finish();

    // Create a new object store
    let object_store = Arc::new(OpendalStore::new(operator));

    let path = Path::from("data/nested/test.txt");
    let bytes = Bytes::from_static(b"hello, world! I am nested.");

    object_store.put(&path, bytes.clone().into()).await.unwrap();

    let content = object_store
        .get(&path)
        .await
        .unwrap()
        .bytes()
        .await
        .unwrap();

    assert_eq!(content, bytes);
}

Structs§

  • OpendalStore implements ObjectStore trait by using opendal.