checksum method
Get the checksum for a file.
Implementation
@override
Future<String?> checksum(String path, {String algorithm = 'md5'}) async {
try {
final file = fileSystem.file(_getFullPath(path));
if (!await file.exists()) {
return null;
}
final hash = _hashForAlgorithm(algorithm);
final sink = AccumulatorSink<Digest>();
final hasher = hash.startChunkedConversion(sink);
await for (final chunk in file.openRead()) {
hasher.add(chunk);
}
hasher.close();
return sink.events.single.toString();
} catch (e) {
if (_throwsExceptions()) {
throw UnableToProvideChecksumException(path, cause: e);
}
return null;
}
}