download method
Downloads the file at url to targetPath.
Follows up to 5 redirects. Writes to a .partial file first,
then renames atomically. Verifies maximum size if configured.
Implementation
Future<void> download(
Uri url,
File targetPath, {
Map<String, String> headers = const {},
}) async {
final tmpFile = File('${targetPath.path}.partial');
try {
await _downloadWithRetry(url, tmpFile, headers: headers);
tmpFile.renameSync(targetPath.path);
} finally {
if (tmpFile.existsSync()) tmpFile.deleteSync();
}
}