md5OfFile function

Future<String> md5OfFile(
  1. File file, {
  2. int streamThreshold = 10 * 1024 * 1024,
})

获取md5

当文件大小超过streamThreshold时, 启用流式处理, 避免大文件干爆内存

Implementation

Future<String> md5OfFile(
  File file, {
  int streamThreshold = 10 * 1024 * 1024,
}) async {
  if (await file.length() > streamThreshold) {
    final stream = file.openRead();
    return md5.bind(stream).first.then(toString);
  } else {
    return md5Of(await file.readAsBytes());
  }
}