loadResource static method

void loadResource(
  1. Pointer<Char> uri,
  2. Pointer<ResourceBuffer> out
)

Implementation

static void loadResource(Pointer<Char> uri, Pointer<ResourceBuffer> out) {
  try {
    var data = File(uri.cast<Utf8>().toDartString().replaceAll("file://", ""))
        .readAsBytesSync();
    var ptr = calloc<Uint8>(data.lengthInBytes);
    ptr.asTypedList(data.lengthInBytes).setRange(0, data.lengthInBytes, data);

    out.ref.data = ptr.cast<Void>();
    out.ref.size = data.lengthInBytes;
    out.ref.id = _assets.length;
    _assets[out.ref.id] = ptr;
  } catch (err) {
    print(err);
    out.ref.size = -1;
  }
}