use std::{future::Future, sync::Arc};
use bytes::Bytes;
use tokio::sync::Mutex;
use remozipsy::{FileInfo, FileSystem};
#[derive(Debug, Clone, Default)]
pub struct ShowStorage {
files: Arc<Mutex<Vec<FileInfo>>>,
}
impl ShowStorage {
pub fn take_content(&self) -> Vec<FileInfo> {
let lock = self.files.blocking_lock();
lock.clone()
}
}
impl FileSystem for ShowStorage {
type Error = ();
type StorePrepare = FileInfo;
async fn all_files(&mut self) -> Result<Vec<FileInfo>, Self::Error> { Ok(vec![]) }
async fn prepare_store_file(&self, info: FileInfo) -> Result<Self::StorePrepare, Self::Error> { Ok(info) }
fn store_file(
&self,
prepared: Self::StorePrepare,
_data: Bytes,
) -> impl Future<Output = Result<(), Self::Error>> + Send {
let files = self.files.clone();
async move {
let mut guard = files.lock().await;
guard.push(prepared);
Ok(())
}
}
async fn delete_file(&self, _info: FileInfo) -> Result<(), Self::Error> {
Ok(())
}
}