Crate raze[][src]

Expand description

Raze is a library for interfacing the BackBlaze B2 API

Raze provides raw API bindings via the API along with some useful functions via [util].
It is highly recommended to familiarize yourself with the official B2 documentation before using this crate.

This crate exposes an async API by the use of tokio and reqwest.

Disclaimer: This library is not associated with Backblaze - Be aware of the B2 pricing - Refer to for conditions


// Authenticate, upload and delete a file
async fn main() {
    let client = reqwest::ClientBuilder::new().build().unwrap();
    let auth = b2_authorize_account(&client, std::env::var("B2_TEST_KEY_STRING").unwrap()).await.unwrap();
    let upauth = b2_get_upload_url(&client, &auth, std::env::var("B2_TEST_BUCKET_ID").unwrap()).await.unwrap();
    let file = tokio::fs::File::open("tests/resources/simple_text_file.txt").await.unwrap();
    let metadata = file.metadata().await.unwrap();
    let size = metadata.len();
    let modf = metadata.modified().unwrap().duration_since(std::time::UNIX_EPOCH).unwrap().as_secs()*1000;

    let param = FileParameters {
        file_path: "simple_text_file.txt",
        file_size: size,
        content_type: None,
        content_sha1: Sha1Variant::HexAtEnd,
        last_modified_millis: modf,

    let stream = reader_to_stream(file);
    let stream = BytesStreamHashAtEnd::wrap(stream);
    let stream = BytesStreamThrottled::wrap(stream, 5000);
    let body = reqwest::Body::wrap_stream(stream);
    let resp1 = b2_upload_file(&client, &upauth, body, param).await.unwrap();

    let resp2 = b2_delete_file_version(&client, &auth, &resp1.file_name, &resp1.file_id.unwrap()).await.unwrap();


Raw API bindings, mostly 1:1 with official API

Various helper functions to assist with common tasks


An API error, returned by the B2 backend


The various kinds of errors this crate may return