1

DOM API returns ArrayBuffer but what I need is Array[Byte]. How can I do a conversion?

import scala.scalajs.js.typedarray.ArrayBuffer

def toScalaArray(input: ArrayBuffer): Array[Byte] = {
  // code in question
}

1 Answer 1

1

Wrap it in an Int8Array, then call the extension method .toArray defined in the typedarray package:

import scala.scalajs.js.typedarray._

def toScalaArray(input: ArrayBuffer): Array[Byte] =
  new Int8Array(input).toArray
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.