Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
Mirai
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Mirai
Commits
56728378
Commit
56728378
authored
Mar 28, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add `gzip` and `ungzip`
parent
8f2843cb
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
43 additions
and
1 deletion
+43
-1
mirai-core/src/androidMain/kotlin/net/mamoe/mirai/utils/platformAndroid.kt
...droidMain/kotlin/net/mamoe/mirai/utils/platformAndroid.kt
+17
-0
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/platform.kt
...e/src/commonMain/kotlin/net.mamoe.mirai/utils/platform.kt
+4
-0
mirai-core/src/commonTest/kotlin/net/mamoe/mirai/utils/PlatformUtilsTest.kt
...monTest/kotlin/net/mamoe/mirai/utils/PlatformUtilsTest.kt
+6
-1
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/PlatformUtilsJvm.kt
.../jvmMain/kotlin/net/mamoe/mirai/utils/PlatformUtilsJvm.kt
+16
-0
No files found.
mirai-core/src/androidMain/kotlin/net/mamoe/mirai/utils/platformAndroid.kt
View file @
56728378
...
@@ -21,6 +21,8 @@ import java.io.InputStream
...
@@ -21,6 +21,8 @@ import java.io.InputStream
import
java.net.Inet4Address
import
java.net.Inet4Address
import
java.security.MessageDigest
import
java.security.MessageDigest
import
java.util.zip.Deflater
import
java.util.zip.Deflater
import
java.util.zip.GZIPInputStream
import
java.util.zip.GZIPOutputStream
import
java.util.zip.Inflater
import
java.util.zip.Inflater
...
@@ -63,6 +65,7 @@ actual object MiraiPlatformUtils {
...
@@ -63,6 +65,7 @@ actual object MiraiPlatformUtils {
}
}
}
}
actual
fun
md5
(
data
:
ByteArray
,
offset
:
Int
,
length
:
Int
):
ByteArray
{
actual
fun
md5
(
data
:
ByteArray
,
offset
:
Int
,
length
:
Int
):
ByteArray
{
data
.
checkOffsetAndLength
(
offset
,
length
)
data
.
checkOffsetAndLength
(
offset
,
length
)
return
MessageDigest
.
getInstance
(
"MD5"
).
apply
{
update
(
data
,
offset
,
length
)
}.
digest
()
return
MessageDigest
.
getInstance
(
"MD5"
).
apply
{
update
(
data
,
offset
,
length
)
}.
digest
()
...
@@ -99,4 +102,18 @@ actual object MiraiPlatformUtils {
...
@@ -99,4 +102,18 @@ actual object MiraiPlatformUtils {
block
(
read
)
block
(
read
)
}
}
}
}
actual
fun
gzip
(
data
:
ByteArray
,
offset
:
Int
,
length
:
Int
):
ByteArray
{
ByteArrayOutputStream
().
use
{
buf
->
GZIPOutputStream
(
buf
).
use
{
gzip
->
data
.
inputStream
(
offset
,
length
).
use
{
t
->
t
.
copyTo
(
gzip
)
}
}
buf
.
flush
()
return
buf
.
toByteArray
()
}
}
actual
fun
ungzip
(
data
:
ByteArray
,
offset
:
Int
,
length
:
Int
):
ByteArray
{
return
GZIPInputStream
(
data
.
inputStream
(
offset
,
length
)).
use
{
it
.
readBytes
()
}
}
}
}
\ No newline at end of file
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/platform.kt
View file @
56728378
...
@@ -30,6 +30,10 @@ expect object MiraiPlatformUtils {
...
@@ -30,6 +30,10 @@ expect object MiraiPlatformUtils {
fun
zip
(
data
:
ByteArray
,
offset
:
Int
=
0
,
length
:
Int
=
data
.
size
-
offset
):
ByteArray
fun
zip
(
data
:
ByteArray
,
offset
:
Int
=
0
,
length
:
Int
=
data
.
size
-
offset
):
ByteArray
fun
gzip
(
data
:
ByteArray
,
offset
:
Int
=
0
,
length
:
Int
=
data
.
size
-
offset
):
ByteArray
fun
ungzip
(
data
:
ByteArray
,
offset
:
Int
=
0
,
length
:
Int
=
data
.
size
-
offset
):
ByteArray
fun
md5
(
data
:
ByteArray
,
offset
:
Int
=
0
,
length
:
Int
=
data
.
size
-
offset
):
ByteArray
fun
md5
(
data
:
ByteArray
,
offset
:
Int
=
0
,
length
:
Int
=
data
.
size
-
offset
):
ByteArray
...
...
mirai-core/src/commonTest/kotlin/net/mamoe/mirai/utils/PlatformUtilsTest.kt
View file @
56728378
...
@@ -14,11 +14,16 @@ import net.mamoe.mirai.utils.io.encodeToString
...
@@ -14,11 +14,16 @@ import net.mamoe.mirai.utils.io.encodeToString
import
kotlin.test.Test
import
kotlin.test.Test
import
kotlin.test.assertEquals
import
kotlin.test.assertEquals
@OptIn
(
MiraiInternalAPI
::
class
)
internal
class
PlatformUtilsTest
{
internal
class
PlatformUtilsTest
{
@OptIn
(
MiraiInternalAPI
::
class
)
@Test
@Test
fun
testZip
()
{
fun
testZip
()
{
assertEquals
(
"test"
,
MiraiPlatformUtils
.
unzip
(
MiraiPlatformUtils
.
zip
(
"test"
.
toByteArray
())).
encodeToString
())
assertEquals
(
"test"
,
MiraiPlatformUtils
.
unzip
(
MiraiPlatformUtils
.
zip
(
"test"
.
toByteArray
())).
encodeToString
())
}
}
@Test
fun
testGZip
()
{
assertEquals
(
"test"
,
MiraiPlatformUtils
.
ungzip
(
MiraiPlatformUtils
.
gzip
(
"test"
.
toByteArray
())).
encodeToString
())
}
}
}
\ No newline at end of file
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/PlatformUtilsJvm.kt
View file @
56728378
...
@@ -22,6 +22,8 @@ import java.io.OutputStream
...
@@ -22,6 +22,8 @@ import java.io.OutputStream
import
java.net.Inet4Address
import
java.net.Inet4Address
import
java.security.MessageDigest
import
java.security.MessageDigest
import
java.util.zip.Deflater
import
java.util.zip.Deflater
import
java.util.zip.GZIPInputStream
import
java.util.zip.GZIPOutputStream
import
java.util.zip.Inflater
import
java.util.zip.Inflater
/**
/**
...
@@ -64,6 +66,20 @@ actual object MiraiPlatformUtils {
...
@@ -64,6 +66,20 @@ actual object MiraiPlatformUtils {
}
}
}
}
actual
fun
gzip
(
data
:
ByteArray
,
offset
:
Int
,
length
:
Int
):
ByteArray
{
ByteArrayOutputStream
().
use
{
buf
->
GZIPOutputStream
(
buf
).
use
{
gzip
->
data
.
inputStream
(
offset
,
length
).
use
{
t
->
t
.
copyTo
(
gzip
)
}
}
buf
.
flush
()
return
buf
.
toByteArray
()
}
}
actual
fun
ungzip
(
data
:
ByteArray
,
offset
:
Int
,
length
:
Int
):
ByteArray
{
return
GZIPInputStream
(
data
.
inputStream
(
offset
,
length
)).
use
{
it
.
readBytes
()
}
}
actual
fun
md5
(
data
:
ByteArray
,
offset
:
Int
,
length
:
Int
):
ByteArray
{
actual
fun
md5
(
data
:
ByteArray
,
offset
:
Int
,
length
:
Int
):
ByteArray
{
data
.
checkOffsetAndLength
(
offset
,
length
)
data
.
checkOffsetAndLength
(
offset
,
length
)
return
MessageDigest
.
getInstance
(
"MD5"
).
apply
{
update
(
data
,
offset
,
length
)
}.
digest
()
return
MessageDigest
.
getInstance
(
"MD5"
).
apply
{
update
(
data
,
offset
,
length
)
}.
digest
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment