kunfei 3 лет назад
Родитель
Сommit
cc7cacfd6e

+ 3 - 3
app/src/main/java/io/legado/app/help/DirectLinkUpload.kt

@@ -49,9 +49,9 @@ object DirectLinkUpload {
                     zipFile
                 }
 
-                is ByteArray -> ZipUtils.zipByteArray(file)
-                is String -> ZipUtils.zipString(file)
-                else -> ZipUtils.zipString(GSON.toJson(file))
+                is ByteArray -> ZipUtils.zipByteArray(file, fileName)
+                is String -> ZipUtils.zipByteArray(file.toByteArray(), fileName)
+                else -> ZipUtils.zipByteArray(GSON.toJson(file).toByteArray(), fileName)
             }
         }
         val analyzeUrl = AnalyzeUrl(url)

+ 1 - 1
app/src/main/java/io/legado/app/lib/dialogs/AlertBuilder.kt

@@ -1,4 +1,4 @@
-@file:Suppress("NOTHING_TO_INLINE", "unused")
+@file:Suppress("unused")
 
 package io.legado.app.lib.dialogs
 

+ 16 - 7
app/src/main/java/io/legado/app/utils/compress/ZipUtils.kt

@@ -16,19 +16,28 @@ import java.util.zip.*
 @Suppress("unused", "MemberVisibilityCanBePrivate")
 object ZipUtils {
 
-    fun zipByteArray(byteArray: ByteArray): ByteArray {
+    fun gzipByteArray(byteArray: ByteArray): ByteArray {
         val byteOut = ByteArrayOutputStream()
         val zip = GZIPOutputStream(byteOut)
-        zip.use {
+        return zip.use {
             it.write(byteArray)
-        }
-        return byteOut.use {
-            it.toByteArray()
+            byteOut.use {
+                byteOut.toByteArray()
+            }
         }
     }
 
-    fun zipString(text: String): ByteArray {
-        return zipByteArray(text.toByteArray())
+    fun zipByteArray(byteArray: ByteArray, fileName: String): ByteArray {
+        val byteOut = ByteArrayOutputStream()
+        val zipOutputStream = ZipOutputStream(byteOut)
+        zipOutputStream.putNextEntry(ZipEntry(fileName))
+        zipOutputStream.write(byteArray)
+        zipOutputStream.closeEntry()
+        return zipOutputStream.use {
+            byteOut.use {
+                byteOut.toByteArray()
+            }
+        }
     }
 
     /**