digest method Null safety

Future<Digest> digest(
  1. AssetId id
)

Returns a Digest representing a hash of the contents of id.

The digests should include the asset ID as well as the content of the file, as some build systems may rely on the digests for two files being different, even if their content is the same.

This should be treated as a transparent Digest and the implementation may differ based on the current build system being used.

Similar to readAsBytes, digest throws an exception if the asset can't be found or if it's an invalid input.

Implementation

Future<Digest> digest(AssetId id) async {
  var digestSink = AccumulatorSink<Digest>();
  md5.startChunkedConversion(digestSink)
    ..add(await readAsBytes(id))
    ..add(id.toString().codeUnits)
    ..close();
  return digestSink.events.first;
}