mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-20 17:04:45 +08:00
Fix zip and unzip
This commit is contained in:
parent
243b2ea731
commit
21abfe4a64
@ -54,18 +54,12 @@ actual object MiraiPlatformUtils {
|
||||
data.checkOffsetAndLength(offset, length)
|
||||
if (length == 0) return ByteArray(0)
|
||||
|
||||
val inflater = Deflater()
|
||||
inflater.reset()
|
||||
ByteArrayOutputStream().use { output ->
|
||||
inflater.setInput(data, offset, length)
|
||||
ByteArrayPool.useInstance {
|
||||
while (!inflater.finished()) {
|
||||
output.write(it, 0, inflater.deflate(it))
|
||||
}
|
||||
}
|
||||
val deflater = Deflater()
|
||||
deflater.setInput(data, offset, length)
|
||||
deflater.finish()
|
||||
|
||||
inflater.end()
|
||||
return output.toByteArray()
|
||||
ByteArrayPool.useInstance {
|
||||
return it.take(deflater.deflate(it)).toByteArray().also { deflater.end() }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright 2020 Mamoe Technologies and contributors.
|
||||
*
|
||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||
*
|
||||
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
package net.mamoe.mirai.utils
|
||||
|
||||
import kotlinx.io.core.toByteArray
|
||||
import net.mamoe.mirai.utils.io.encodeToString
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
internal class PlatformUtilsTest {
|
||||
|
||||
@OptIn(MiraiInternalAPI::class)
|
||||
@Test
|
||||
fun testZip() {
|
||||
assertEquals("test", MiraiPlatformUtils.unzip(MiraiPlatformUtils.zip("test".toByteArray())).encodeToString())
|
||||
}
|
||||
}
|
@ -55,18 +55,12 @@ actual object MiraiPlatformUtils {
|
||||
data.checkOffsetAndLength(offset, length)
|
||||
if (length == 0) return ByteArray(0)
|
||||
|
||||
val inflater = Deflater()
|
||||
inflater.reset()
|
||||
ByteArrayOutputStream().use { output ->
|
||||
inflater.setInput(data, offset, length)
|
||||
ByteArrayPool.useInstance {
|
||||
while (!inflater.finished()) {
|
||||
output.write(it, 0, inflater.deflate(it))
|
||||
}
|
||||
}
|
||||
val deflater = Deflater()
|
||||
deflater.setInput(data, offset, length)
|
||||
deflater.finish()
|
||||
|
||||
inflater.end()
|
||||
return output.toByteArray()
|
||||
ByteArrayPool.useInstance {
|
||||
return it.take(deflater.deflate(it)).toByteArray().also { deflater.end() }
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user