diff --git a/compottie-dot/src/wasmJsMain/kotlin/io/github/alexzhirkevich/compottie/Conversion.wasmJs.kt b/compottie-dot/src/wasmJsMain/kotlin/io/github/alexzhirkevich/compottie/Conversion.wasmJs.kt index 1e9791b2..b1b31bdf 100644 --- a/compottie-dot/src/wasmJsMain/kotlin/io/github/alexzhirkevich/compottie/Conversion.wasmJs.kt +++ b/compottie-dot/src/wasmJsMain/kotlin/io/github/alexzhirkevich/compottie/Conversion.wasmJs.kt @@ -2,6 +2,7 @@ package io.github.alexzhirkevich.compottie import org.khronos.webgl.ArrayBuffer import org.khronos.webgl.Int8Array +import org.khronos.webgl.Uint8Array import org.khronos.webgl.get import org.khronos.webgl.set import kotlin.wasm.unsafe.UnsafeWasmMemoryApi @@ -32,11 +33,11 @@ internal fun createSourceUnstable(data : JsReference) : JsAny = js("" """) internal fun ArrayBuffer.toByteArray(): ByteArray { - return Int8Array(this).toByteArray() + return Uint8Array(this).toByteArray() } @OptIn(ExperimentalCompottieApi::class) -internal fun Int8Array.toByteArray(): ByteArray { +internal fun Uint8Array.toByteArray(): ByteArray { if (Compottie.useStableWasmMemoryManagement) { return ByteArray(byteLength) { @@ -81,14 +82,14 @@ private fun byteArrayToInt8ArrayImpl(a: JsReference): Int8Array = js( @JsFun( """ (src, size, dstAddr) => { - const mem8 = new Int8Array(wasmExports.memory.buffer, dstAddr, size); + const mem8 = new Uint8Array(wasmExports.memory.buffer, dstAddr, size); mem8.set(src); } """ ) -private external fun jsExportInt8ArrayToWasm(src: Int8Array, size: Int, dstAddr: Int) +private external fun jsExportInt8ArrayToWasm(src: Uint8Array, size: Int, dstAddr: Int) -private fun jsInt8ArrayToKotlinByteArray(x: Int8Array): ByteArray { +private fun jsInt8ArrayToKotlinByteArray(x: Uint8Array): ByteArray { val size = x.length @OptIn(UnsafeWasmMemoryApi::class) diff --git a/compottie-dot/src/wasmJsMain/kotlin/io/github/alexzhirkevich/compottie/ZipFileSystem.wasmJs.kt b/compottie-dot/src/wasmJsMain/kotlin/io/github/alexzhirkevich/compottie/ZipFileSystem.wasmJs.kt index 7ccf3d9e..51c11084 100644 --- a/compottie-dot/src/wasmJsMain/kotlin/io/github/alexzhirkevich/compottie/ZipFileSystem.wasmJs.kt +++ b/compottie-dot/src/wasmJsMain/kotlin/io/github/alexzhirkevich/compottie/ZipFileSystem.wasmJs.kt @@ -2,6 +2,7 @@ package io.github.alexzhirkevich.compottie import org.khronos.webgl.Int8Array +import org.khronos.webgl.Uint8Array @OptIn(ExperimentalCompottieApi::class) internal actual suspend fun decompress(array: ByteArray, decompressedSize : Int) : ByteArray { @@ -28,10 +29,10 @@ internal actual suspend fun decompress(array: ByteArray, decompressedSize : Int) break } - val chunk = Int8Array(result.value.buffer).toByteArray() + val chunk = Uint8Array(result.value.buffer).toByteArray() chunk.copyInto(decompressed, ind) - ind += array.size + ind += chunk.size } return decompressed