finish method

void finish(
  1. String id,
  2. List<int> bytes
)

Writes bytes where the last start of id put its part file, then reports the download complete.

Implementation

void finish(String id, List<int> bytes) {
  final start = lastStart(id) ?? (throw StateError('$id was never started'));
  File(start.path)
    ..createSync(recursive: true)
    ..writeAsBytesSync(bytes);
  kept.remove(id);
  emit(ModelDownloadUpdate(id: id, state: ModelDownloadState.complete));
}