calculateHash function

Future<Digest> calculateHash(
  1. String path
)

Calculates the sha256 hash of a file's content.

This is likely to be an expensive operation if the file is large.

You can use this method to check if a file has changes since the last time you took the file's hash.

Throws FileNotFoundException if path doesn't exist. Throws NotAFileException if path is not a file.

Implementation

Future<Digest> calculateHash(String path) async {
  if (!exists(path)) {
    throw FileNotFoundException(path);
  }

  if (!isFile(path)) {
    throw NotAFileException(path);
  }
  final input = File(path);

  const hasher = sha256;
  final digest = await hasher.bind(input.openRead()).first;

  verbose(() => 'calculateHash($path) = $digest');
  return digest;
}