mirror of
https://github.com/gedoor/legado.git
synced 2025-01-09 04:17:45 +08:00
优化
This commit is contained in:
parent
26156331a4
commit
30a181bf27
@ -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,4 +1,4 @@
|
||||
@file:Suppress("NOTHING_TO_INLINE", "unused")
|
||||
@file:Suppress("unused")
|
||||
|
||||
package io.legado.app.lib.dialogs
|
||||
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user