diff --git a/core/src/commonMain/kotlin/com/littlekt/file/compression/Compression.kt b/core/src/commonMain/kotlin/com/littlekt/file/compression/Compression.kt index eb9fee83..50008822 100644 --- a/core/src/commonMain/kotlin/com/littlekt/file/compression/Compression.kt +++ b/core/src/commonMain/kotlin/com/littlekt/file/compression/Compression.kt @@ -16,7 +16,7 @@ interface Compression { * @param input uncompressed data. * @return compressed data ByteBuffer. */ - suspend fun compress(input: ByteBuffer): ByteBuffer = ByteBuffer(compress(input.toArray())) + suspend fun compress(input: ByteBuffer): ByteBuffer /** * Compress a block of data @@ -32,7 +32,7 @@ interface Compression { * @param input compressed data * @return decompressed data ByteBuffer. */ - suspend fun decompress(input: ByteBuffer): ByteBuffer = ByteBuffer(decompress(input.toArray())) + suspend fun decompress(input: ByteBuffer): ByteBuffer /** * Decompress a block of data diff --git a/core/src/commonMain/kotlin/com/littlekt/file/compression/CompressionGZIP.kt b/core/src/commonMain/kotlin/com/littlekt/file/compression/CompressionGZIP.kt index 6b09849e..7ef219c0 100644 --- a/core/src/commonMain/kotlin/com/littlekt/file/compression/CompressionGZIP.kt +++ b/core/src/commonMain/kotlin/com/littlekt/file/compression/CompressionGZIP.kt @@ -1,5 +1,7 @@ package com.littlekt.file.compression +import com.littlekt.file.ByteBuffer + /** * An implementation of the gzip algorithm. * @@ -7,6 +9,14 @@ package com.littlekt.file.compression * @date 12/2/2024 */ expect class CompressionGZIP : Compression { + override suspend fun compress(input: ByteBuffer): ByteBuffer + + override suspend fun compress(input: ByteArray): ByteArray + + override suspend fun decompress(input: ByteBuffer): ByteBuffer + + override suspend fun decompress(input: ByteArray): ByteArray + companion object { operator fun invoke(): CompressionGZIP } diff --git a/core/src/jsMain/kotlin/com/littlekt/file/compression/CompressionGZIP.js.kt b/core/src/jsMain/kotlin/com/littlekt/file/compression/CompressionGZIP.js.kt index a8ea1e6c..1785a6ad 100644 --- a/core/src/jsMain/kotlin/com/littlekt/file/compression/CompressionGZIP.js.kt +++ b/core/src/jsMain/kotlin/com/littlekt/file/compression/CompressionGZIP.js.kt @@ -1,5 +1,6 @@ package com.littlekt.file.compression +import com.littlekt.file.ByteBuffer import kotlinx.coroutines.await import org.khronos.webgl.Uint8Array import org.khronos.webgl.get @@ -11,8 +12,10 @@ import org.khronos.webgl.get * @date 12/2/2024 */ actual class CompressionGZIP : Compression { + actual override suspend fun compress(input: ByteBuffer): ByteBuffer = + ByteBuffer(compress(input.toArray())) - override suspend fun compress(input: ByteArray): ByteArray { + actual override suspend fun compress(input: ByteArray): ByteArray { val uint8Array = Uint8Array(input.toTypedArray()) val readableStream = ReadableStream( @@ -38,7 +41,10 @@ actual class CompressionGZIP : Compression { return ByteArray(output.length) { output[it] } } - override suspend fun decompress(input: ByteArray): ByteArray { + actual override suspend fun decompress(input: ByteBuffer): ByteBuffer = + ByteBuffer(decompress(input.toArray())) + + actual override suspend fun decompress(input: ByteArray): ByteArray { val uint8Array = Uint8Array(input.toTypedArray()) val readableStream = ReadableStream( diff --git a/core/src/jvmAndroidMain/kotlin/com/littlekt/file/compression/CompressionGZIP.jvmAndroid.kt b/core/src/jvmAndroidMain/kotlin/com/littlekt/file/compression/CompressionGZIP.jvmAndroid.kt index 2089616f..cd82e15f 100644 --- a/core/src/jvmAndroidMain/kotlin/com/littlekt/file/compression/CompressionGZIP.jvmAndroid.kt +++ b/core/src/jvmAndroidMain/kotlin/com/littlekt/file/compression/CompressionGZIP.jvmAndroid.kt @@ -1,5 +1,6 @@ package com.littlekt.file.compression +import com.littlekt.file.ByteBuffer import java.io.ByteArrayInputStream import java.io.ByteArrayOutputStream import java.util.zip.GZIPInputStream @@ -14,8 +15,10 @@ import kotlinx.coroutines.withContext * @date 12/2/2024 */ actual class CompressionGZIP : Compression { + actual override suspend fun compress(input: ByteBuffer): ByteBuffer = + ByteBuffer(compress(input.toArray())) - override suspend fun compress(input: ByteArray): ByteArray { + actual override suspend fun compress(input: ByteArray): ByteArray { val compressedData = withContext(Dispatchers.IO) { ByteArrayOutputStream(input.size).use { outputStream -> @@ -26,7 +29,10 @@ actual class CompressionGZIP : Compression { return compressedData } - override suspend fun decompress(input: ByteArray): ByteArray { + actual override suspend fun decompress(input: ByteBuffer): ByteBuffer = + ByteBuffer(decompress(input.toArray())) + + actual override suspend fun decompress(input: ByteArray): ByteArray { val uncompressData = withContext(Dispatchers.IO) { ByteArrayInputStream(input).use { inputStream ->