downloadFile static method
Downloads a file from url and writes it to destPath.
Throws an HttpException if the server returns a non-200 status code.
Implementation
static Future<void> downloadFile(String url, String destPath) async {
final client = HttpClient();
try {
final request = await client.getUrl(Uri.parse(url));
request.headers.set('User-Agent', 'inno_bundle');
final response = await request.close();
if (response.statusCode != 200) {
throw HttpException('HTTP ${response.statusCode}');
}
final file = File(destPath);
final sink = file.openWrite();
await response.pipe(sink);
await sink.close();
} finally {
client.close();
}
}