download method
Sends a download as a response.
Implementation
Future<void> download(File file, {String? filename}) async {
if (!isOpen) throw closed();
headers['Content-Disposition'] =
'attachment; filename="${filename ?? file.path}"';
contentType = MediaType.parse(lookupMimeType(file.path)!);
headers['content-length'] = file.lengthSync().toString();
if (!isBuffered) {
await file.openRead().cast<List<int>>().pipe(this);
} else {
buffer!.add(file.readAsBytesSync());
await close();
}
}