backblaze_b2_client/
lib.rs

1//! This is a Rust client library for the Backblaze B2 cloud storage service. It provides a convenient interface for interacting with the B2 API. Relies on Tokio async runtime.
2//!
3//! The crate provides a simple client `B2SimpleClient` that is just a mapping with b2 requests, and a normal client `B2Client` that provides helpful utilities
4//! and auto re-auth to make life easier, you can access its inner basic client, currently only file uploads with `create_upload`.
5//!
6//! The crate is still a work in progress, so expect breaking changes between 0.0.X versions.
7//!
8//! # Features
9//!   
10//! - Auto re-auth with Backblaze B2.
11//! - Easy file upload handler.
12//! - Mapped all b2 storage request in simple client.
13//!
14//! ## Installation
15//!
16//! Add the following dependency to your project using the `cargo add` command:
17//!
18//! ```sh
19//! cargo add backblaze-b2-client
20//! ```
21//!
22//! ## Usage
23//!
24//! ### File Upload
25//!
26//! ```rust
27//! use backblaze_b2_client::B2Client;
28//! use tokio::fs::File;
29//!
30//! #[tokio::main]
31//! fn main() {
32//!     let client = B2Client::new("your_account_id", "your_application_key");
33//!   
34//!     let file = File::open("path_to_file").await.unwrap();
35//!
36//!     let metadata = open_file.metadata().await.unwrap();
37//!
38//!     let upload = client.create_upload(
39//!         file,
40//!         "file_name".into(),
41//!         "bucket_id".into(),
42//!         None,
43//!         metadata.len(),
44//!         None,
45//!     ).await;
46//!
47//!     let file_handle_copy = file_handle.clone();
48//!     tokio::spawn(async move {
49//!         let file_handle = file_handle_copy.clone();
50//!         // Logs progress to console every half a second
51//!         while !file_handle.has_stopped() {
52//!             println!(
53//!                 "status: {:?}, stats: {:.2}",
54//!                 file_handle.status(),
55//!                 file_handle.stats().current_stats()
56//!             );
57//!             sleep(Duration::from_millis(500)).await;
58//!         }
59//!     });
60//!
61//!     // Starts the file upload and waits for it to finish
62//!     let file = upload.start().await.unwrap();
63//!
64//!     println!("{:#?}", file);
65//! }
66//! ```
67pub mod client;
68pub mod definitions;
69pub mod error;
70pub mod simple_client;
71pub mod tasks;
72pub mod throttle;
73pub mod util;
74
75pub use reqwest;