MPBackupExporter

Entity able to serialize BackupData entities, like BackupMessage, BackupConversation, BackupUser into a cross-platform BackupData format.

Entity able to serialize BackupData entities, like BackupMessage, BackupConversation, BackupUser into a cross-platform BackupData format.

Samples

val backupPassword = "Aqa123456!"
// Create a MPBackupExporter
val mpBackupExporter = MPBackupExporter(
    selfUserId = getSelfUserId(),
)

// Each client (iOS, Web, Android) has their own logic for fetching stuff from database
// It's probably necessary to paginate the data from database, in case there are tens of thousands of messages, for example
getMessagesFromDatabase().forEach { message ->
    mpBackupExporter.add(message)
}

getUsersFromDatabase().forEach { user ->
    mpBackupExporter.add(user)
}

getConversationsFromDatabase().forEach { conversation ->
    mpBackupExporter.add(conversation)
}

getReactionsFromDatabase().forEach { reaction ->
    mpBackupExporter.add(reaction)
}

// When all data is exported, you can call finalize, getting the binary data of the file in a Promise
val fileData = mpBackupExporter.finalize(backupPassword).await() // Equivalent to await mpBackupExporter.finalize(...)
println("Backup created file. Raw binary data: $fileData")

Entity able to serialize BackupData entities, like BackupMessage, BackupConversation, BackupUser into a cross-platform BackupData format.

Samples

val backupPassword = "Aqa123456!"
// Create a MPBackupExporter
val mpBackupExporter = MPBackupExporter(
    selfUserId = getSelfUserId(),
    workDirectory = "/path/to/working/directory/",
    outputDirectory = "/path/to/output/directory/",
    fileZipper = { entries, path ->
        TODO("Zip all entries into a single zip file and return the path to this file")
    }
)

// Each client (iOS, Web, Android) has their own logic for fetching stuff from database
// It's probably necessary to paginate the data from database, in case there are tens of thousands of messages, for example
getMessagesFromDatabase().forEach { message ->
    mpBackupExporter.add(message)
}

getUsersFromDatabase().forEach { user ->
    mpBackupExporter.add(user)
}

getConversationsFromDatabase().forEach { conversation ->
    mpBackupExporter.add(conversation)
}

getReactionsFromDatabase().forEach { reaction ->
    mpBackupExporter.add(reaction)
}

// When all data is exported, you can call finalize, saving the result into a file.
val pathToBackupFile = mpBackupExporter.finalize(backupPassword)
println("Backup created at $pathToBackupFile")

Constructors

Link copied to clipboard
constructor(selfUserId: BackupQualifiedId)
constructor(selfUserId: BackupQualifiedId, workDirectory: String, outputDirectory: String, fileZipper: FileZipper, fileSystem: FileSystem, logger: BackupLogger? = null)
constructor(selfUserId: BackupQualifiedId, workDirectory: String, outputDirectory: String, fileZipper: FileZipper)

Properties

Link copied to clipboard
internal val logger: BackupLogger?
internal val logger: BackupLogger?
internal val logger: BackupLogger?
Link copied to clipboard
internal expect open override val storage: BackupPageStorage
internal actual open override val storage: BackupPageStorage
internal actual open override val storage: BackupPageStorage

Functions

Link copied to clipboard
fun add(conversation: BackupConversation)
fun add(message: BackupMessage)
fun add(reaction: BackupReaction)
fun add(user: BackupUser)
fun add(conversation: BackupConversation)
fun add(message: BackupMessage)
fun add(reaction: BackupReaction)
fun add(user: BackupUser)
fun add(conversation: BackupConversation)
fun add(message: BackupMessage)
fun add(reaction: BackupReaction)
fun add(user: BackupUser)
Link copied to clipboard
internal suspend fun finalize(password: String, output: Sink): ExportResult

Finalize the export and write the data to the given output. This method should be called after all the data was added.

internal suspend fun finalize(password: String, output: Sink): ExportResult

Finalize the export and write the data to the given output. This method should be called after all the data was added.

fun finalize(password: String): Promise<BackupExportResult>

Exports all the previously added data to a BackupExportResult. This method should be called after all the data was added.

internal suspend fun finalize(password: String, output: Sink): ExportResult

Finalize the export and write the data to the given output. This method should be called after all the data was added.

suspend fun finalize(password: String): BackupExportResult

Persists all the data into a single backup file, returning a BackupExportResult. This method should be called after all the data was added.

Link copied to clipboard
internal fun CommonMPBackupExporter.validate(conversation: BackupConversation): Boolean

Validates the given BackupConversation and its content.

internal fun CommonMPBackupExporter.validate(message: BackupMessage): Boolean

Validates the given BackupMessage and its content.

internal fun CommonMPBackupExporter.validate(user: BackupUser): Boolean

Validates the given BackupUser and its content.

Link copied to clipboard
internal expect open override fun zipEntries(data: List<BackupPage>): Deferred<Source>
internal actual open override fun zipEntries(data: List<BackupPage>): Deferred<Source>
internal actual open override fun zipEntries(data: List<BackupPage>): Deferred<Source>