Update MD5 Calc

- Calculate md5 asynchronously
This commit is contained in:
Linloir 2022-10-18 14:40:48 +08:00
parent 84fe935fcd
commit 3c6b5d64e3
No known key found for this signature in database
GPG Key ID: 58EEB209A0F2C366
3 changed files with 14 additions and 6 deletions

View File

@ -1,7 +1,7 @@
/* /*
* @Author : Linloir * @Author : Linloir
* @Date : 2022-10-11 10:30:05 * @Date : 2022-10-11 10:30:05
* @LastEditTime : 2022-10-14 23:53:18 * @LastEditTime : 2022-10-18 14:20:02
* @Description : * @Description :
*/ */
@ -89,6 +89,6 @@ class Message extends JSONEncodable {
'content': _content, 'content': _content,
'timestamp': _timestamp, 'timestamp': _timestamp,
'md5encoded': _contentmd5, 'md5encoded': _contentmd5,
'filemd5': payload?.filemd5 'filemd5': payload?.filemd5 ?? _filemd5
}; };
} }

View File

@ -1,13 +1,15 @@
/* /*
* @Author : Linloir * @Author : Linloir
* @Date : 2022-10-11 10:56:02 * @Date : 2022-10-11 10:56:02
* @LastEditTime : 2022-10-18 11:27:15 * @LastEditTime : 2022-10-18 14:35:25
* @Description : Local Service Repository * @Description : Local Service Repository
*/ */
import 'dart:async'; import 'dart:async';
import 'dart:convert';
import 'dart:io'; import 'dart:io';
import 'package:convert/convert.dart';
import 'package:crypto/crypto.dart'; import 'package:crypto/crypto.dart';
import 'package:file_picker/file_picker.dart'; import 'package:file_picker/file_picker.dart';
import 'package:path_provider/path_provider.dart'; import 'package:path_provider/path_provider.dart';
@ -114,9 +116,15 @@ class LocalServiceRepository {
); );
if (filePickResult == null) return null; if (filePickResult == null) return null;
var file = File(filePickResult.files.single.path!); var file = File(filePickResult.files.single.path!);
var md5Output = AccumulatorSink<Digest>();
ByteConversionSink md5Input = md5.startChunkedConversion(md5Output);
await for(var bytes in file.openRead()) {
md5Input.add(bytes);
}
md5Input.close();
return LocalFile( return LocalFile(
file: file, file: file,
filemd5: md5.convert(await file.readAsBytes()).toString() filemd5: md5Output.events.single.toString()
); );
} }

View File

@ -1,7 +1,7 @@
/* /*
* @Author : Linloir * @Author : Linloir
* @Date : 2022-10-11 11:02:19 * @Date : 2022-10-11 11:02:19
* @LastEditTime : 2022-10-14 15:12:02 * @LastEditTime : 2022-10-18 14:11:36
* @Description : * @Description :
*/ */
@ -185,7 +185,7 @@ class FetchMessageResponse extends TCPResponse {
FetchMessageResponse({ FetchMessageResponse({
required Map<String, Object?> jsonObject required Map<String, Object?> jsonObject
}): super(jsonObject: jsonObject) { }): super(jsonObject: jsonObject) {
_messages = ((jsonObject['body'] as Map<String, Object?>)['messages'] as List) _messages = (((jsonObject['body'] as Map<String, Object?>?) ?? {'messages': []})['messages'] as List)
.map((e) => Message.fromJSONObject(jsonObject: e)).toList(); .map((e) => Message.fromJSONObject(jsonObject: e)).toList();
} }