downloadRelease function

Future<File> downloadRelease(
  1. File file,
  2. String url,
  3. String appName
)

Implementation

Future<File> downloadRelease(File file, String url, String appName) async {
  var res = await http.get(
    Uri.parse(url),
    headers: {
      ...UpdatGlobalOptions.downloadReleaseHeaders,
    },
  );
  if (res.statusCode == 200) {
    await file.writeAsBytes(res.bodyBytes);
    if (file.path.endsWith("zip")) {
      final outDir = Directory(p.join(p.dirname(file.path), appName));
      outDir.createSync(recursive: true);
      extractFileToDisk(file.absolute.path, outDir.absolute.path);
    }
    // Return with new installed status
    return file;
  } else {
    throw Exception(
      'There was an issue downloading the file, please try again later.\n'
      'Code ${res.statusCode}',
    );
  }
}