MPBackupImporter

Entity able to parse backed-up data and returns digestible data in BackupData format.

Samples

samples.backup.BackupSample.commonImport

Entity 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
}

Constructors

Link copied to clipboard
constructor()
constructor(pathToWorkDirectory: String, backupFileUnzipper: BackupFileUnzipper)

Functions

Link copied to clipboard
internal abstract fun getUnencryptedArchiveSink(): <Error class: unknown class>

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.

internal open override fun getUnencryptedArchiveSink(): <Error class: unknown class>

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.

internal open override fun getUnencryptedArchiveSink(): <Error class: unknown class>

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.

Link copied to clipboard
internal suspend fun importBackup(source: <Error class: unknown class>, passphrase: String?): BackupImportResult

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.

internal suspend fun importBackup(source: <Error class: unknown class>, passphrase: String?): BackupImportResult

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.

internal suspend fun importBackup(source: <Error class: unknown class>, passphrase: String?): BackupImportResult

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.

Link copied to clipboard
suspend fun importFromFile(multiplatformBackupFilePath: String, passphrase: String?): BackupImportResult

Imports a backup from the specified root path.

Link copied to clipboard
fun importFromFileData(data: <Error class: unknown class>, passphrase: String?): <Error class: unknown class><BackupImportResult>
Link copied to clipboard
internal fun peekBackup(source: <Error class: unknown class>): BackupPeekResult

Peeks into a backup artifact, returning information about it.

internal fun peekBackup(source: <Error class: unknown class>): BackupPeekResult

Peeks into a backup artifact, returning information about it.

internal fun peekBackup(source: <Error class: unknown class>): BackupPeekResult

Peeks into a backup artifact, returning information about it.

Link copied to clipboard
suspend fun peekBackupFile(pathToBackupFile: String): BackupPeekResult

Peeks into the specified backup file and retrieves metadata about it.

Link copied to clipboard
fun peekFileData(data: <Error class: unknown class>): <Error class: unknown class><BackupPeekResult>
Link copied to clipboard
internal abstract suspend fun unzipAllEntries(): BackupPageStorage

Unzips all entries in the zip archive stored in the sink returned by getUnencryptedArchiveSink.

internal open suspend override fun unzipAllEntries(): BackupPageStorage

Unzips all entries in the zip archive stored in the sink returned by getUnencryptedArchiveSink.

internal open suspend override fun unzipAllEntries(): BackupPageStorage

Unzips all entries in the zip archive stored in the sink returned by getUnencryptedArchiveSink.