ensureRuntimeFile function

Future<File> ensureRuntimeFile(
  1. RuntimeFile file,
  2. Directory directory, {
  3. HttpClient? client,
  4. void onProgress(
    1. int received,
    2. int? total
    )?,
})

Makes <directory>/<file.name> a file with SHA-256 RuntimeFile.sha256 and returns it.

A file that is already there with that SHA-256 is not downloaded again. A download goes to a temporary file next to the final path. It is gunzipped or extracted if needed, checked, and then renamed into place.

Implementation

Future<File> ensureRuntimeFile(
  RuntimeFile file,
  Directory directory, {
  HttpClient? client,
  void Function(int received, int? total)? onProgress,
}) {
  file.validate();
  return fetchVerified(
    FetchSpec(
      url: file.url,
      sha256: file.sha256,
      downloadSha256: file.downloadSha256,
      archiveEntry: file.archiveEntry,
    ),
    File(p.join(directory.path, file.name)),
    client: client,
    onProgress: onProgress,
  );
}