JamesZhang 1 rok pred
rodič
commit
5c81a111ef
2 zmenil súbory, kde vykonal 12 pridanie a 0 odobranie
  1. 11 0
      lib/util/fileUtils.dart
  2. 1 0
      pubspec.yaml

+ 11 - 0
lib/util/fileUtils.dart

@@ -1,6 +1,8 @@
 
 import 'dart:io';
 import 'dart:math';
+import 'package:convert/convert.dart';
+import 'package:crypto/crypto.dart';
 import 'package:path/path.dart' as path;
 import 'logger.dart';
 
@@ -44,6 +46,15 @@ String formatFileSize(int bytes) {
   return ((bytes / pow(1024, i)).toStringAsFixed(2)) + ' ' + suffixes[i];
 }
 
+// MD5
+Future<String> getFileMd5(String filePath) async {
+  final fileExists = File(filePath).existsSync();
+  if (!fileExists) throw FileSystemException("File does not exist", filePath);
+  final file = File(filePath);
+  final digest = await file.openRead().transform(md5).first;
+  return hex.encode(digest.bytes);
+}
+
 
 createFolder(String folderPath) async {
   // 创建文件夹

+ 1 - 0
pubspec.yaml

@@ -11,6 +11,7 @@ dependencies:
   flutter:
     sdk: flutter
   convert: ^3.1.1
+  crypto: ^3.0.6
   flutter_riverpod: ^2.4.9
   riverpod_annotation: ^2.3.3
   objectbox: ^2.4.0