Skip to main content

firebase_admin_sdk/storage/
bucket.rs

1use crate::core::middleware::AuthMiddleware;
2use crate::storage::file::File;
3use reqwest_middleware::ClientWithMiddleware;
4
5/// A reference to a Google Cloud Storage bucket.
6pub struct Bucket {
7    client: ClientWithMiddleware,
8    base_url: String,
9    name: String,
10    middleware: AuthMiddleware,
11}
12
13impl Bucket {
14    pub(crate) fn new(
15        client: ClientWithMiddleware,
16        base_url: String,
17        name: String,
18        middleware: AuthMiddleware,
19    ) -> Self {
20        Self {
21            client,
22            base_url,
23            name,
24            middleware,
25        }
26    }
27
28    /// Returns the name of the bucket.
29    pub fn name(&self) -> &str {
30        &self.name
31    }
32
33    /// Gets a `File` instance that refers to the file at the specified path.
34    ///
35    /// # Arguments
36    ///
37    /// * `name` - The path to the file within the bucket (e.g., "images/profile.png").
38    pub fn file(&self, name: &str) -> File {
39        File::new(
40            self.client.clone(),
41            self.base_url.clone(),
42            self.name.clone(),
43            name.to_string(),
44            self.middleware.clone(),
45        )
46    }
47}