#actor #wasmcloud #events #capability-provider #api-bindings

wasmcloud-actor-blobstore

为 wasmCloud Actors 提供对 blobstore 合同的接口

5 个版本

0.2.2 2021 年 5 月 17 日
0.2.1 2021 年 4 月 16 日
0.2.0 2021 年 3 月 18 日
0.1.1 2021 年 2 月 16 日
0.1.0 2021 年 2 月 10 日

#1527 in WebAssembly


用于 2 crates

Apache-2.0

21KB
330

crates.io Rust license documentation

wasmCloud Blob Store Actor 接口

此包为 wasmCloud Actors 提供了对 blobstore 功能提供者的接口。使用此接口的 Actor 必须拥有 wasmcloud:blobstore 声明,以便有权与存储进行通信。

此通用协议可用于支持本地 blob 存储、Amazon S3、Azure blob 存储、Google blob 存储等功能提供者。

示例

use wapc_guest as guest;
use guest::prelude::*;
use wasmcloud_actor_blobstore as blobstore;
use wasmcloud_actor_http_server as http;
use wasmcloud_actor_core as actor;
use actor::{serialize, init};
use blobstore::*;
use serde_json::json;
use log::{error, info};

#[actor::init]
fn init() {
    http::Handlers::register_handle_request(download_poem);
    blobstore::Handlers::register_receive_chunk(handle_chunk);   
}

fn download_poem(req: http::Request) -> HandlerResult<http::Response> {    
    match blobstore::default().start_download(req.path, "poems".to_string(), 4096, None) {
        Ok(_) => Ok(http::Response::ok()),
        Err(_) => Err("Failed to initiate download of chunk".into())
    }
}

 /// Handle the incoming chunk as a poem "verse" and log the result
 /// Note that these chunks can be received out of order, so the poem
 /// in this case might be displayed in a different order and could look
 /// funny if the verse continues across a chunk boundary
 fn handle_chunk(chunk: FileChunk) -> HandlerResult<()> {
     let verse = String::from_utf8(chunk.chunk_bytes)?;
     info!("Poem {} part {}:\n{}", chunk.id, chunk.sequence_no, verse);
     Ok(())
 }


依赖项

~1–1.9MB
~41K SLoC