-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
310bc14
commit 5ce748e
Showing
135 changed files
with
2,267 additions
and
371 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
src/androidMain/kotlin/com/ashampoo/kim/common/ZLib.android.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright 2024 Ashampoo GmbH & Co. KG | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.ashampoo.kim.common | ||
|
||
import java.io.ByteArrayOutputStream | ||
import java.util.zip.Deflater | ||
import java.util.zip.Inflater | ||
|
||
private const val ZLIB_BUFFER_SIZE: Int = 1024 | ||
|
||
actual fun compress(input: String): ByteArray { | ||
|
||
val deflater = Deflater() | ||
val inputBytes = input.toByteArray() | ||
|
||
deflater.setInput(inputBytes) | ||
deflater.finish() | ||
|
||
val outputStream = ByteArrayOutputStream(inputBytes.size) | ||
|
||
val buffer = ByteArray(ZLIB_BUFFER_SIZE) | ||
|
||
while (!deflater.finished()) { | ||
|
||
val count = deflater.deflate(buffer) | ||
|
||
outputStream.write(buffer, 0, count) | ||
} | ||
|
||
deflater.end() | ||
|
||
return outputStream.toByteArray() | ||
} | ||
|
||
actual fun decompress(byteArray: ByteArray): String { | ||
|
||
val inflater = Inflater() | ||
val outputStream = ByteArrayOutputStream() | ||
|
||
return outputStream.use { | ||
|
||
val buffer = ByteArray(ZLIB_BUFFER_SIZE) | ||
|
||
inflater.setInput(byteArray) | ||
|
||
var count = -1 | ||
|
||
while (count != 0) { | ||
|
||
count = inflater.inflate(buffer) | ||
|
||
outputStream.write(buffer, 0, count) | ||
} | ||
|
||
inflater.end() | ||
|
||
String(outputStream.toByteArray()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.