checkDownloaded method
Checks that the File with provided parameters is downloaded.
Implementation
Future<File?> checkDownloaded({
required String filename,
String? checksum,
int? size,
String? url,
}) async {
final Downloading? downloading = downloads[checksum];
if (downloading != null) {
return downloading.file;
}
File? file;
if (checksum != null) {
final String? path = await _downloadLocal?.read(checksum);
if (path != null) {
file = File(path);
if (!await file.exists() || await file.length() != size) {
file = null;
_downloadLocal?.delete(checksum);
}
}
} else {
file = await PlatformUtils.fileExists(filename, size: size, url: url);
}
if (checksum != null && file != null) {
downloads[checksum] = Downloading.completed(
checksum,
filename,
size,
file.path,
onDownloaded: (file) => _downloadLocal?.upsert(checksum, file.path),
);
_downloadLocal?.upsert(checksum, file.path);
}
return file;
}