run function

Future<Response> run()

Implementation

Future<Response> run() async {
  var shell = Shell();
  var zipFile = await downloadFile(getSpeedTestDownloadUrl());
  var folderPath = await decompileZip(zipFile.path);
  var response = await shell.run('$folderPath/speedtest');
  var lines = (response.stdout.toString()).split('\n').map((e) => e.trim()).toList();
  String lineValue(String keyword) =>
      lines.firstWhere((element) => element.startsWith(keyword), orElse: () => '').split(keyword).last;
  var server = lineValue('Server:');
  var isp = lineValue('ISP:');
  var latency = lineValue('Latency:').split('(').first;
  var download = lineValue('Download:').split('(').first;
  var upload = lineValue('Upload:').split('(').first;
  return Response(server, isp, latency, download, upload);
}