downloadPackageContent method

Future<Uint8List> downloadPackageContent(
  1. String packageId, {
  2. required String version,
})

Returns the contents of the package content (.nupkg) file for the package with the packageId and version.

Throws a PackageNotFoundException if the server returns a 404 status code.

Throws a NuGetServerException if the server returns a non-200 status code.

Implementation

Future<Uint8List> downloadPackageContent(
  String packageId, {
  required String version,
}) async {
  final id = packageId.toLowerCase();
  final uri = resourceUri.replace(pathSegments: [
    ...resourceUri.pathSegments,
    id,
    version,
    '$id.$version.nupkg'
  ]);
  final response = await httpClient.get(uri);
  return switch (response.statusCode) {
    404 => throw PackageNotFoundException(packageId),
    200 => response.bodyBytes,
    _ => throw NuGetServerException('Failed to download package content: '
        '${response.statusCode} ${response.reasonPhrase}'),
  };
}