pub struct FileStorage<B: BlobStore> {
blob_client: BlobClient,
remote_blob_service: Arc<B>,
compression_config: CompressionConfig,
}Expand description
High-level file storage client that encrypts files and stores them as blobs
Fields§
§blob_client: BlobClient§remote_blob_service: Arc<B>§compression_config: CompressionConfigImplementations§
Source§impl<B: BlobStore> FileStorage<B>
impl<B: BlobStore> FileStorage<B>
Sourcepub async fn new(
blob_storage_path: &Path,
remote_blob_service: Arc<B>,
compression_config: CompressionConfig,
) -> Result<Self>
pub async fn new( blob_storage_path: &Path, remote_blob_service: Arc<B>, compression_config: CompressionConfig, ) -> Result<Self>
Create a new file storage client with remote blob service and custom compression
Sourcepub async fn store_file(&self, file_path: &Path) -> Result<FileRef>
pub async fn store_file(&self, file_path: &Path) -> Result<FileRef>
Store a file by reading from disk, encrypting, and storing in blob storage
This method:
- Reads the file from the provided path
- Encrypts the content using convergent encryption
- Stores the encrypted data in the blob store
- Returns metadata needed to retrieve the file later
§Arguments
file_path- Path to the file to store
§Returns
FileRef containing the blob hash, encryption info, and metadata
§Example
let temp_dir = tempdir()?;
let storage = FileStorage::new(temp_dir.path()).await?;
let file_path = Path::new("/path/to/document.pdf");
let stored_info = storage.store_file(file_path).await?;
println!("File stored with blob hash: {}", stored_info.blob_hash);Sourcepub async fn store_data(
&self,
data: &[u8],
reference_name: &str,
content_type: Option<String>,
) -> Result<FileRef>
pub async fn store_data( &self, data: &[u8], reference_name: &str, content_type: Option<String>, ) -> Result<FileRef>
Store raw data (not from a file) with encryption and blob storage
This method allows storing arbitrary data without reading from disk.
§Arguments
data- The raw data to storereference_name- A reference name for the data (used in metadata)content_type- Optional content type for metadata
§Returns
FileRef containing the blob hash, encryption info, and metadata
Sourcepub async fn retrieve_file(&self, stored_info: &FileRef) -> Result<Vec<u8>>
pub async fn retrieve_file(&self, stored_info: &FileRef) -> Result<Vec<u8>>
Retrieve a file from storage and decrypt it
This method:
- Retrieves the encrypted data from blob storage using the hash
- Decrypts the data using the provided encryption info
- Returns the original file content
§Arguments
stored_info- Metadata from when the file was stored
§Returns
The original file content as bytes
§Example
let temp_dir = tempdir()?;
let storage = FileStorage::new(temp_dir.path()).await?;
// Assume we have stored_info from a previous store_file call
let file_content = storage.retrieve_file(&stored_info).await?;
println!("Retrieved {} bytes", file_content.len());Sourcepub async fn retrieve_file_to_disk(
&self,
stored_info: &FileRef,
output_path: &Path,
) -> Result<()>
pub async fn retrieve_file_to_disk( &self, stored_info: &FileRef, output_path: &Path, ) -> Result<()>
Save retrieved file content to disk
This is a convenience method that combines retrieve_file with writing to disk.
§Arguments
stored_info- Metadata from when the file was storedoutput_path- Path where to write the retrieved file
§Example
let temp_dir = tempdir()?;
let storage = FileStorage::new(temp_dir.path()).await?;
let output_path = Path::new("/tmp/retrieved_file.txt");
storage.retrieve_file_to_disk(&stored_info, output_path).await?;Sourcepub fn blob_client(&self) -> &BlobClient
pub fn blob_client(&self) -> &BlobClient
Get the underlying blob client for advanced operations
Trait Implementations§
Source§impl<B: Clone + BlobStore> Clone for FileStorage<B>
impl<B: Clone + BlobStore> Clone for FileStorage<B>
Source§fn clone(&self) -> FileStorage<B>
fn clone(&self) -> FileStorage<B>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more