hashFile function
Compute SHA-256 hash of a file at path.
Implementation
Future<String> hashFile(String path) async {
final proc = await Process.run('shasum', [
'-a',
'256',
path,
], stdoutEncoding: utf8);
if (proc.exitCode == 0) {
return (proc.stdout as String).split(' ').first.trim();
}
// Fallback
final proc2 = await Process.run('openssl', [
'dgst',
'-sha256',
'-hex',
path,
], stdoutEncoding: utf8);
final output = (proc2.stdout as String).trim();
final idx = output.indexOf('= ');
return idx >= 0 ? output.substring(idx + 2).trim() : output;
}