updateProgress static method
Update progress for a URL.
Implementation
static Future<void> updateProgress(
String url, {
required int downloadedBytes,
int? totalBytes,
bool isHls = false,
}) async {
await _ensureLoaded();
final isComplete = totalBytes != null && downloadedBytes >= totalBytes;
_cache[url] = CacheMetadata(
downloadedBytes: downloadedBytes,
totalBytes: totalBytes,
isComplete: isComplete,
lastUpdated: DateTime.now(),
isHls: isHls,
);
// Persist on completion or periodically to reduce I/O
final now = DateTime.now();
final lastPersisted = _lastPersisted[url];
if (isComplete ||
lastPersisted == null ||
now.difference(lastPersisted) >= _persistInterval) {
_lastPersisted[url] = now;
await _persist();
}
}