Edoardo Luppi
07/01/2023, 6:05 PMU*
types support for JsExport
(https://youtrack.jetbrains.com/issue/KT-51389) and thought to ask one thing before posting it.
Currently to support both the JVM and Node's buffers (Uint8Array
) I've defined an expect class with typealiases:
public expect class ZByteArray
public actual typealias ZByteArray = ByteArray
public actual typealias ZByteArray = Uint8Array
The problem with this approach is in common code ZByteArray
doesn't have any methods or fields, it's useless.
Is there a way to overcome this limitation?Adam S
07/01/2023, 6:30 PMexpect fun ZByteArray.foo(): String
you might be better off using Okio though? That’s got good multiplatform support for byte arraysEdoardo Luppi
07/01/2023, 6:32 PMjw
07/01/2023, 6:33 PMEdoardo Luppi
07/01/2023, 6:36 PMZByteArray
tho, like
/**
* Reads [n] bytes, and advances the read pointer.
*/
@Suppress("NON_EXPORTABLE_TYPE")
public fun readBytes(n: Int): ZByteArray
You see that I had to suppress a compiler warning.
@jw interesting, could you make an example, I'm not sure how it would be used in this case