BackupCompression.kt
composeApp/src/commonMain/kotlin/eu/friedcutlet/yokan/services/backup/BackupCompression.kt
1package eu.friedcutlet.yokan.services.backup23interface BackupCompression {4 fun compress(data: ByteArray, level: Int): ByteArray5 fun decompress(data: ByteArray): ByteArray6 fun looksGzipped(data: ByteArray): Boolean = data.size >= 2 && data[0] == 0x1F.toByte() && data[1] == 0x8B.toByte()78 /**9 * Mangayomi (Flutter) backups are a ZIP archive containing a single10 * `*.backup.db` JSON entry. Return that entry's bytes for any ZIP whose11 * local file header (PK\x03\x04) is at offset 0.12 */13 fun looksZipped(data: ByteArray): Boolean =14 data.size >= 4 &&15 data[0] == 0x50.toByte() && data[1] == 0x4B.toByte() &&16 (data[2] == 0x03.toByte() || data[2] == 0x05.toByte() || data[2] == 0x07.toByte())1718 fun unzipFirstEntry(data: ByteArray): ByteArray? = null1920 /** Async counterpart for browser-native ZIP decoders; synchronous platforms use the fast path. */21 suspend fun unzipFirstEntryAsync(data: ByteArray): ByteArray? = unzipFirstEntry(data)2223 /** All non-directory entries by name; null on platforms without a ZIP decoder. */24 fun unzipEntries(data: ByteArray): Map<String, ByteArray>? = null2526 /** Async counterpart for browser-native ZIP decoders; synchronous platforms use the fast path. */27 suspend fun unzipEntriesAsync(data: ByteArray): Map<String, ByteArray>? = unzipEntries(data)2829 /** Async counterpart for browser-native decompression; synchronous platforms use the fast path. */30 suspend fun decompressAsync(data: ByteArray): ByteArray = decompress(data)3132 /**33 * Produce a ZIP archive containing a single [entryName] entry holding34 * [data]. Used to write Mangayomi-compatible `.backup` files. Returns null35 * on platforms without a ZIP encoder.36 */37 fun zipSingleEntry(entryName: String, data: ByteArray, level: Int): ByteArray? = null38}3940expect fun createPlatformBackupCompression(): BackupCompression41