Ok, so, the correct way to transform a Kotlin `Byt...
# javascript
e
Ok, so, the correct way to transform a Kotlin
ByteArray
(
Int8Array
) to a
Uint8Array
is
Copy code
public actual inline fun Uint8Array.toKotlinArray(): ByteArray =
  Int8Array(buffer, byteOffset, byteLength).unsafeCast<ByteArray>()

@Suppress("NOTHING_TO_INLINE")
public actual inline fun ByteArray.toPlatformArray(): Uint8Array {
  val i8a = unsafeCast<Int8Array>()
  return Uint8Array(i8a.buffer, i8a.byteOffset, i8a.byteLength)
}
You basically need to specify the byte offset and byte length, otherwise the result is way off.
t
First extension with fixed name expected as PR :)
e
@turansky which name would suite better?
@Artem Kobzar question if you know the answer, how is the backing array buffer handled for the KJS implementation of
ByteArray
? Is it a sort of shared buffer, and that's why the offset is not zero?
t
@turansky which name would suite better?
toByteArray
Also
Int8Array.asByteArray
missed in your example