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

// 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}")
    }
}
// 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")
            }
        }

        while (importPager.reactionsPager.hasMorePages()) {
            updateProgress(totalPages, ++processedPages)
            val reactions = importPager.reactionsPager.nextPage()
            reactions.forEach { reaction ->
                TODO("Map each reaction and insert into local Database")
            }
        }

        println("Import finished successfully!")
    }
}

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

Samples

// 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")
            }
        }

        while (importPager.reactionsPager.hasMorePages()) {
            updateProgress(totalPages, ++processedPages)
            val reactions = importPager.reactionsPager.nextPage()
            reactions.forEach { reaction ->
                TODO("Map each reaction and insert into local Database")
            }
        }

        println("Import finished successfully!")
    }
}
// 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}")
    }
}

Constructors

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

Functions

Link copied to clipboard
internal expect open override fun getUnencryptedArchiveSink(): Sink

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 actual open override fun getUnencryptedArchiveSink(): Sink

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 actual open override fun getUnencryptedArchiveSink(): Sink

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: Source, 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: Source, 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: Source, 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
@ObjCName(name = "importFile")
suspend fun importFromFile(multiplatformBackupFilePath: String, passphrase: String?): BackupImportResult

Imports a backup from the specified root path.

Link copied to clipboard
fun importFromFileData(data: Uint8Array, passphrase: String?): Promise<BackupImportResult>
Link copied to clipboard
internal fun peekBackup(source: Source): BackupPeekResult

Peeks into a backup artifact, returning information about it.

internal fun peekBackup(source: Source): BackupPeekResult

Peeks into a backup artifact, returning information about it.

internal fun peekBackup(source: Source): BackupPeekResult

Peeks into a backup artifact, returning information about it.

Link copied to clipboard
@ObjCName(name = "peek")
suspend fun peekBackupFile(pathToBackupFile: String): BackupPeekResult

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

Link copied to clipboard
fun peekFileData(data: Uint8Array): Promise<BackupPeekResult>
Link copied to clipboard
internal expect open suspend override fun unzipAllEntries(): BackupPageStorage

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

internal actual open suspend override fun unzipAllEntries(): BackupPageStorage

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

internal actual open suspend override fun unzipAllEntries(): BackupPageStorage

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