From 24943b1d6b497a6f0e20da4413b7068ae7cdc8d3 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 14 Sep 2022 17:04:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/utils/ZipUtils.kt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/src/main/java/io/legado/app/utils/ZipUtils.kt b/app/src/main/java/io/legado/app/utils/ZipUtils.kt index e77c52db7..43656bcb4 100644 --- a/app/src/main/java/io/legado/app/utils/ZipUtils.kt +++ b/app/src/main/java/io/legado/app/utils/ZipUtils.kt @@ -4,6 +4,7 @@ import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.withContext import java.io.* +import java.util.zip.GZIPOutputStream import java.util.zip.ZipEntry import java.util.zip.ZipFile import java.util.zip.ZipOutputStream @@ -11,6 +12,17 @@ import java.util.zip.ZipOutputStream @Suppress("unused", "BlockingMethodInNonBlockingContext", "MemberVisibilityCanBePrivate") object ZipUtils { + fun zipString(text: String): ByteArray { + val byteOut = ByteArrayOutputStream() + val zip = GZIPOutputStream(byteOut) + zip.use { + it.write(text.toByteArray()) + } + return byteOut.use { + it.toByteArray() + } + } + /** * Zip the files. *