瀏覽代碼

Remove all lengthSync ops

vishnukvmd 3 年之前
父節點
當前提交
528b7da54e
共有 4 個文件被更改,包括 12 次插入12 次删除
  1. 3 2
      lib/ui/file_info_dialog.dart
  2. 2 2
      lib/utils/crypto_util.dart
  3. 1 1
      lib/utils/file_download_util.dart
  4. 6 7
      lib/utils/file_uploader.dart

+ 3 - 2
lib/ui/file_info_dialog.dart

@@ -27,7 +27,8 @@ class _FileInfoWidgetState extends State<FileInfoWidget> {
 
   @override
   void initState() {
-    _isImage = widget.file.fileType == FileType.image || widget.file.fileType == FileType.livePhoto ;
+    _isImage = widget.file.fileType == FileType.image ||
+        widget.file.fileType == FileType.livePhoto;
     if (_isImage) {
       _getExif().then((exif) {
         setState(() {
@@ -433,7 +434,7 @@ class _FileInfoWidgetState extends State<FileInfoWidget> {
 
   Widget _getFileSize() {
     return FutureBuilder(
-      future: getFile(widget.file).then((f) => f.lengthSync()),
+      future: getFile(widget.file).then((f) => f.length()),
       builder: (context, snapshot) {
         if (snapshot.hasData) {
           return Text(

+ 2 - 2
lib/utils/crypto_util.dart

@@ -47,7 +47,7 @@ Future<EncryptionResult> chachaEncryptFile(Map<String, dynamic> args) async {
   final logger = Logger("ChaChaEncrypt");
   final sourceFile = io.File(args["sourceFilePath"]);
   final destinationFile = io.File(args["destinationFilePath"]);
-  final sourceFileLength = sourceFile.lengthSync();
+  final sourceFileLength = await sourceFile.length();
   logger.info("Encrypting file of size " + sourceFileLength.toString());
 
   final inputFile = sourceFile.openSync(mode: io.FileMode.read);
@@ -81,7 +81,7 @@ Future<void> chachaDecryptFile(Map<String, dynamic> args) async {
   final decryptionStartTime = DateTime.now().millisecondsSinceEpoch;
   final sourceFile = io.File(args["sourceFilePath"]);
   final destinationFile = io.File(args["destinationFilePath"]);
-  final sourceFileLength = sourceFile.lengthSync();
+  final sourceFileLength = await sourceFile.length();
   logger.info("Decrypting file of size " + sourceFileLength.toString());
 
   final inputFile = sourceFile.openSync(mode: io.FileMode.read);

+ 1 - 1
lib/utils/file_download_util.dart

@@ -41,7 +41,7 @@ Future<io.File> downloadAndDecrypt(ente.File file,
     }
     _logger.info("File downloaded: " + file.uploadedFileID.toString());
     _logger.info("Download speed: " +
-        (io.File(encryptedFilePath).lengthSync() /
+        (await io.File(encryptedFilePath).length() /
                 (DateTime.now().millisecondsSinceEpoch - startTime))
             .toString() +
         "kBps");

+ 6 - 7
lib/utils/file_uploader.dart

@@ -336,10 +336,10 @@ class FileUploader {
           file,
           fileObjectKey,
           fileDecryptionHeader,
-          encryptedFile.lengthSync(),
+          await encryptedFile.length(),
           thumbnailObjectKey,
           thumbnailDecryptionHeader,
-          encryptedThumbnailFile.lengthSync(),
+          await encryptedThumbnailFile.length(),
           encryptedMetadata,
           metadataDecryptionHeader,
         );
@@ -352,10 +352,10 @@ class FileUploader {
           fileAttributes,
           fileObjectKey,
           fileDecryptionHeader,
-          encryptedFile.lengthSync(),
+          await encryptedFile.length(),
           thumbnailObjectKey,
           thumbnailDecryptionHeader,
-          encryptedThumbnailFile.lengthSync(),
+          await encryptedThumbnailFile.length(),
           encryptedMetadata,
           metadataDecryptionHeader,
         );
@@ -601,7 +601,7 @@ class FileUploader {
     int contentLength,
     int attempt = 1,
   }) async {
-    final fileSize = contentLength ?? file.lengthSync();
+    final fileSize = contentLength ?? await file.length();
     final startTime = DateTime.now().millisecondsSinceEpoch;
     try {
       await _dio.put(
@@ -614,8 +614,7 @@ class FileUploader {
         ),
       );
       _logger.info("Upload speed : " +
-          (file.lengthSync() /
-                  (DateTime.now().millisecondsSinceEpoch - startTime))
+          (fileSize / (DateTime.now().millisecondsSinceEpoch - startTime))
               .toString() +
           " kilo bytes per second");