convertJSDataViewToByteData static method

ByteData convertJSDataViewToByteData(
  1. Object jsObject
)

Convert the js DataView object to a dart ByteData. They're basically the same object (down to the api), but it helps to have the data in a native friendly data.

Implementation

static ByteData convertJSDataViewToByteData(final Object jsObject) {
  final byteLength = _JSUtil.getProperty(jsObject, "byteLength") as int;
  final byteData = ByteData(byteLength);
  for (var i = 0; i < byteLength; i++) {
    final value = _JSUtil.callMethod(jsObject, "getUint8", [i]) as int;
    byteData.setUint8(i, value);
  }
  return byteData;
}