load static method

Future<WasmParseBackend> load({
  1. List<Uri>? candidates,
})

Fetch, compile, and instantiate. With no candidates, tries the locations a Flutter web build and a plain dart2js page serve the package asset from; see defaultAssetCandidates.

Implementation

static Future<WasmParseBackend> load({List<Uri>? candidates}) async {
  final uris = candidates ?? defaultAssetCandidates();
  Object? lastError;
  for (final uri in uris) {
    try {
      final response = _Response(await _fetch(uri.toString().toJS).toDart);
      if (!response.ok.toDart) {
        lastError = 'HTTP ${response.status.toDartInt} for $uri';
        continue;
      }
      final buffer = await response.arrayBuffer().toDart;
      return await fromBytes(buffer.toDart.asUint8List());
    } catch (e) {
      lastError = e;
    }
  }
  throw FlarkParseException(
    FlarkParseException.loadFailedCode,
    'could not load flark_parse.wasm from ${uris.join(', ')}: $lastError',
  );
}