I cannot figure out how to get to raw bytes from Blob (org.w3c.files.Blob). Kotlin JS representation of Blob does have any suitable method ![]()
UPD. This code seems to be doing the job:
if (data is Blob) {
println("Data is Blob! ${data.type}")
val reader = FileReader()
reader.addEventListener("loadend", {event: Event ->
val r = reader.result
if (r is ArrayBuffer) {
println("Data is read as ArrayBuffer")
val arr = Int8Array(r as ArrayBuffer, 0, r.byteLength)
println("Data byte length: ${arr.length}")
handler(arr as ByteArray)
} else {
println("Data is read not as ArrayBuffer")
}
})
reader.readAsArrayBuffer(data);
}