package eu.friedcutlet.yokan.services.backup interface BackupCompression { fun compress(data: ByteArray, level: Int): ByteArray fun decompress(data: ByteArray): ByteArray fun looksGzipped(data: ByteArray): Boolean = data.size >= 2 && data[0] == 0x1F.toByte() && data[1] == 0x8B.toByte() /** * Mangayomi (Flutter) backups are a ZIP archive containing a single * `*.backup.db` JSON entry. Return that entry's bytes for any ZIP whose * local file header (PK\x03\x04) is at offset 0. */ fun looksZipped(data: ByteArray): Boolean = data.size >= 4 && data[0] == 0x50.toByte() && data[1] == 0x4B.toByte() && (data[2] == 0x03.toByte() || data[2] == 0x05.toByte() || data[2] == 0x07.toByte()) fun unzipFirstEntry(data: ByteArray): ByteArray? = null /** Async counterpart for browser-native ZIP decoders; synchronous platforms use the fast path. */ suspend fun unzipFirstEntryAsync(data: ByteArray): ByteArray? = unzipFirstEntry(data) /** All non-directory entries by name; null on platforms without a ZIP decoder. */ fun unzipEntries(data: ByteArray): Map? = null /** Async counterpart for browser-native ZIP decoders; synchronous platforms use the fast path. */ suspend fun unzipEntriesAsync(data: ByteArray): Map? = unzipEntries(data) /** Async counterpart for browser-native decompression; synchronous platforms use the fast path. */ suspend fun decompressAsync(data: ByteArray): ByteArray = decompress(data) /** * Produce a ZIP archive containing a single [entryName] entry holding * [data]. Used to write Mangayomi-compatible `.backup` files. Returns null * on platforms without a ZIP encoder. */ fun zipSingleEntry(entryName: String, data: ByteArray, level: Int): ByteArray? = null } expect fun createPlatformBackupCompression(): BackupCompression