MPBackupImporter
Entity able to parse backed-up data and returns digestible data in BackupData format.
Samples
samples.backup.BackupSample.commonImportEntity able to parse backed-up data and returns digestible data in BackupData format.
Samples
import com.wire.backup.dump.MPBackupExporter
import com.wire.backup.ingest.BackupPeekResult
import com.wire.backup.ingest.MPBackupImporter
import com.wire.backup.ingest.isCreatedBySameUser
import kotlinx.coroutines.await
import org.khronos.webgl.Uint8Array
fun main() {
//sampleStart
// Peek into backup file
val importer = MPBackupImporter()
// data is an uint8 array
val peekResult = importer.peekFileData(data).await() // await promise
when (peekResult) {
BackupPeekResult.Failure.UnknownFormat -> TODO("This is not a valid backup file")
is BackupPeekResult.Failure.UnsupportedVersion -> TODO("Unsupported version, too old or too new")
is BackupPeekResult.Success -> {
// You can check if the backup was created by a specific user ID:
val isCreatedBySameUser = peekResult.isCreatedBySameUser(getSelfUserId())
println("Backup info: isEncrypted=${peekResult.isEncrypted}, version=${peekResult.version}")
}
}
//sampleEnd
}
import com.wire.backup.data.BackupConversation
import com.wire.backup.data.BackupMessage
import com.wire.backup.data.BackupQualifiedId
import com.wire.backup.data.BackupUser
import com.wire.backup.ingest.BackupImportResult
fun main() {
//sampleStart
// Handling import result
when (importResult) {
BackupImportResult.Failure.MissingOrWrongPassphrase -> TODO("User has provided a wrong password")
BackupImportResult.Failure.ParsingFailure -> TODO("This file is not a valid backup file, or its an unsupported version")
is BackupImportResult.Failure.UnknownError -> TODO("Exception. You can get more info by doing ${importResult.message}")
is BackupImportResult.Failure.UnzippingError -> TODO("Client implementation of Unzipper has thrown an exception")
is BackupImportResult.Success -> {
val importPager = importResult.pager
// You can calculate progress based on total page count:
val totalPages = importPager.totalPagesCount
var processedPages = 0
while (importPager.conversationsPager.hasMorePages()) {
updateProgress(totalPages, ++processedPages)
val conversations = importPager.conversationsPager.nextPage()
conversations.forEach { conversation ->
TODO("Map each conversation and insert into local Database")
}
}
while (importPager.usersPager.hasMorePages()) {
updateProgress(totalPages, ++processedPages)
val users = importPager.usersPager.nextPage()
users.forEach { user ->
TODO("Map each user and insert into local Database")
}
}
while (importPager.messagesPager.hasMorePages()) {
updateProgress(totalPages, ++processedPages)
val messages = importPager.messagesPager.nextPage()
messages.forEach { message ->
TODO("Map each message and insert into local Database")
}
}
println("Import finished successfully!")
}
}
//sampleEnd
}
Entity able to parse backed-up data and returns digestible data in BackupData format.
Samples
import com.wire.backup.data.BackupConversation
import com.wire.backup.data.BackupMessage
import com.wire.backup.data.BackupQualifiedId
import com.wire.backup.data.BackupUser
import com.wire.backup.ingest.BackupImportResult
fun main() {
//sampleStart
// Handling import result
when (importResult) {
BackupImportResult.Failure.MissingOrWrongPassphrase -> TODO("User has provided a wrong password")
BackupImportResult.Failure.ParsingFailure -> TODO("This file is not a valid backup file, or its an unsupported version")
is BackupImportResult.Failure.UnknownError -> TODO("Exception. You can get more info by doing ${importResult.message}")
is BackupImportResult.Failure.UnzippingError -> TODO("Client implementation of Unzipper has thrown an exception")
is BackupImportResult.Success -> {
val importPager = importResult.pager
// You can calculate progress based on total page count:
val totalPages = importPager.totalPagesCount
var processedPages = 0
while (importPager.conversationsPager.hasMorePages()) {
updateProgress(totalPages, ++processedPages)
val conversations = importPager.conversationsPager.nextPage()
conversations.forEach { conversation ->
TODO("Map each conversation and insert into local Database")
}
}
while (importPager.usersPager.hasMorePages()) {
updateProgress(totalPages, ++processedPages)
val users = importPager.usersPager.nextPage()
users.forEach { user ->
TODO("Map each user and insert into local Database")
}
}
while (importPager.messagesPager.hasMorePages()) {
updateProgress(totalPages, ++processedPages)
val messages = importPager.messagesPager.nextPage()
messages.forEach { message ->
TODO("Map each message and insert into local Database")
}
}
println("Import finished successfully!")
}
}
//sampleEnd
}
import com.wire.backup.dump.MPBackupExporter
import com.wire.backup.ingest.BackupPeekResult
import com.wire.backup.ingest.MPBackupImporter
import com.wire.backup.ingest.isCreatedBySameUser
fun main() {
//sampleStart
// Peek into backup file
val importer = MPBackupImporter(
pathToWorkDirectory = "/path/to/working/directory",
backupFileUnzipper = { zippedFile ->
TODO("Unzip all content into a directory, and return the path to the unzipped content")
}
)
// Check if the backup is encrypted or not
val peekResult = importer.peekBackupFile("path/to/backupFile.wbu")
when (peekResult) {
BackupPeekResult.Failure.UnknownFormat -> TODO("This is not a valid backup file")
is BackupPeekResult.Failure.UnsupportedVersion -> TODO("Unsupported version, too old or too new")
is BackupPeekResult.Success -> {
// You can check if the backup was created by a specific user ID:
val isCreatedBySameUser = peekResult.isCreatedBySameUser(getSelfUserId())
println("Backup info: isEncrypted=${peekResult.isEncrypted}, version=${peekResult.version}")
}
}
//sampleEnd
}
Functions
Provides a sink to store the unencrypted data. Be the archive encrypted or not, the data will be moved to this sink until unzipAllEntries is used.
Provides a sink to store the unencrypted data. Be the archive encrypted or not, the data will be moved to this sink until unzipAllEntries is used.
Provides a sink to store the unencrypted data. Be the archive encrypted or not, the data will be moved to this sink until unzipAllEntries is used.
Decrypt (if needed) and unzip the backup artifact. The resulting BackupImportResult.Success contains a BackupImportPager, that can be used to consume pages of backed up application data, like messages, users and conversations.
Decrypt (if needed) and unzip the backup artifact. The resulting BackupImportResult.Success contains a BackupImportPager, that can be used to consume pages of backed up application data, like messages, users and conversations.
Decrypt (if needed) and unzip the backup artifact. The resulting BackupImportResult.Success contains a BackupImportPager, that can be used to consume pages of backed up application data, like messages, users and conversations.
Imports a backup from the specified root path.
Peeks into a backup artifact, returning information about it.
Peeks into a backup artifact, returning information about it.
Peeks into a backup artifact, returning information about it.
Peeks into the specified backup file and retrieves metadata about it.
Unzips all entries in the zip archive stored in the sink returned by getUnencryptedArchiveSink.
Unzips all entries in the zip archive stored in the sink returned by getUnencryptedArchiveSink.
Unzips all entries in the zip archive stored in the sink returned by getUnencryptedArchiveSink.