xmtp_archive/exporter/
file_export.rs1use super::ArchiveExporter;
2use crate::ArchiveError;
3use futures_util::AsyncReadExt;
4use std::path::Path;
5use tokio::{fs::File, io::AsyncWriteExt};
6
7impl ArchiveExporter {
8 pub async fn write_to_file(&mut self, path: impl AsRef<Path>) -> Result<(), ArchiveError> {
9 let mut file = File::create(path.as_ref()).await?;
10 let mut buffer = [0u8; 1024];
11
12 let mut amount = self.read(&mut buffer).await?;
13 while amount != 0 {
14 let _ = file.write(&buffer[..amount]).await?;
15 amount = self.read(&mut buffer).await?;
16 }
17
18 file.flush().await?;
19
20 Ok(())
21 }
22}