-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
120 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 7 additions & 25 deletions
32
xmtp_mls/src/groups/device_sync/backup/backup_importer/file_import.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,15 @@ | ||
use super::BackupImporter; | ||
use crate::groups::device_sync::{backup::BackupError, DeviceSyncError}; | ||
use async_compression::futures::bufread::ZstdDecoder; | ||
use crate::groups::device_sync::DeviceSyncError; | ||
use futures::io::BufReader; | ||
use std::pin::Pin; | ||
use tokio::io::AsyncRead; | ||
use tokio_util::compat::{FuturesAsyncReadCompatExt, TokioAsyncReadCompatExt}; | ||
use xmtp_proto::xmtp::device_sync::{backup_element::Element, BackupElement, BackupMetadata}; | ||
use std::{path::Path, pin::Pin}; | ||
use tokio_util::compat::TokioAsyncReadCompatExt; | ||
|
||
impl BackupImporter { | ||
pub async fn open(reader: impl AsyncRead + Send + 'static) -> Result<Self, DeviceSyncError> { | ||
let reader = reader.compat(); | ||
let reader = BufReader::new(reader); | ||
pub async fn from_file(path: impl AsRef<Path>, key: &[u8]) -> Result<Self, DeviceSyncError> { | ||
let reader = tokio::fs::File::open(path.as_ref()).await?; | ||
let reader = BufReader::new(reader.compat()); | ||
let reader = Box::pin(reader) as Pin<Box<_>>; | ||
let decoder = ZstdDecoder::new(reader); | ||
|
||
let mut importer = Self { | ||
decoder, | ||
decoded: vec![], | ||
metadata: BackupMetadata::default(), | ||
}; | ||
|
||
let Some(BackupElement { | ||
element: Some(Element::Metadata(metadata)), | ||
}) = importer.next_element().await? | ||
else { | ||
return Err(BackupError::MissingMetadata)?; | ||
}; | ||
|
||
importer.metadata = metadata; | ||
Ok(importer) | ||
Self::load(reader, key).await | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters