downloadFile method
Downloads a file from the specified URL as a list of bytes.
The url
should be a direct download URL (e.g., a raw GitHub URL).
Returns a Uint8List containing the file's binary data.
Throws a GitHubApiException if the download fails.
Implementation
Future<Uint8List> downloadFile(String url) async {
final token = _token ?? Platform.environment['GITHUB_TOKEN'];
final response = await _httpClient.get(
Uri.parse(url),
headers: {if (token != null) 'Authorization': 'Bearer $token'},
);
if (response.statusCode != 200) {
throw GitHubApiException(
'Failed to download file from $url',
statusCode: response.statusCode,
);
}
return response.bodyBytes;
}