package eu.friedcutlet.yokan.services.extensions import java.io.ByteArrayInputStream import java.io.ByteArrayOutputStream import java.util.zip.GZIPInputStream internal actual suspend fun gzipDecompress(bytes: ByteArray): ByteArray { val output = ByteArrayOutputStream() val buffer = ByteArray(32 * 1024) var outputSize = 0 GZIPInputStream(ByteArrayInputStream(bytes)).use { input -> while (true) { val count = input.read(buffer) if (count < 0) break check(count <= MaxProtobufDecompressedBytes - outputSize) { "Decompressed protobuf exceeds the 64 MiB limit" } output.write(buffer, 0, count) outputSize += count } } return output.toByteArray() }