part of mac.utils;

Future<String> fetch(String url) async {
  var uri = Uri.parse(url);
  var client = new HttpClient();
  var request = await client.getUrl(uri);
  var response = await request.close();
  if (response.statusCode != 200) {
    throw new Exception("Failed to fetch ${url}");
  }
  return response.transform(UTF8.decoder).join().then((out) {
    client.close();
    return out;
  });
}

Future<dynamic> fetchJSON(String url) async {
  var text = await fetch(url);
  var json = JSON.decode(text);
  return json;
}

part of mac.utils;

Future<String> fetch(String url) async {
  var uri = Uri.parse(url);
  var client = new HttpClient();
  var request = await client.getUrl(uri);
  var response = await request.close();
  if (response.statusCode != 200) {
    throw new Exception("Failed to fetch ${url}");
  }
  return UTF8.decoder.bind(response).join().then((out) {
    client.close();
    return out;
  });
}

Future<dynamic> fetchJSON(String url) async {
  var text = await fetch(url);
  var json = JSON.decode(text);
  return json;
}

Prepare for Uint8List SDK breaking change
Prepare for Uint8List SDK breaking change

A recent change to the Dart SDK updated `HttpClientResponse`
to implement `Stream<Uint8List>` rather than implementing
`Stream<List<int>>`.

This forwards-compatible chnage updates calls to
`Stream.transform(StreamTransformer)` to instead call the
functionally equivalent `StreamTransformer.bind(Stream)`
API, which puts the stream in a covariant position and
thus causes the SDK change to be non-breaking.

https://github.com/dart-lang/sdk/issues/36900
