downloadPackage method

Future<DownloadPackageResult> downloadPackage(
  1. PackageId id
)

Downloads a cached package identified by id to the cache.

id must refer to a cached package.

If allowOutdatedHashChecks is true we use a cached version listing response if present instead of probing the server. Not probing allows for pub get with a filled cache to be a fast case that doesn't require any new version-listings.

Returns id with an updated ResolvedDescription, this can be different if the content-hash changed while downloading.

Implementation

Future<DownloadPackageResult> downloadPackage(PackageId id) async {
  final source = id.source;
  assert(source is CachedSource);
  final result = await (source as CachedSource).downloadToSystemCache(
    id,
    this,
  );

  // We only update the README.md in the cache when a change to the cache has
  // happened. This is:
  // * to avoid failing if used with a read-only cache, and
  // * because the cost of writing a single file is negligible compared to
  //   downloading a package, but might be significant in the fast-case where
  //   a the cache is already valid.
  if (result.didUpdate) {
    maintainCache();
  }
  return result;
}