download method
Downloads a file from the specified url to a temporary location.
The url can be either a String or a Uri object.
Returns the path to the downloaded file.
Implementation
Future<String> download(
Object url,
String fileName, {
Map<String, String>? headers,
void Function(int bytesReceived, int totalBytes)? onProgress,
}) async {
// Create a temporary file path
final tempDir = Directory.systemTemp;
final filePath = '${tempDir.path}/$fileName';
final uri = _toUri(url);
await _downloadToFile(uri, filePath, headers: headers, onProgress: onProgress);
// Track the downloaded file
HTTPSClient._downloadedFiles[fileName] = filePath;
return filePath;
}