Ver Fonte

Fix bug in speed calculation

Neeraj Gupta há 2 anos atrás
pai
commit
2de7bff9b7
1 ficheiros alterados com 6 adições e 7 exclusões
  1. 6 7
      lib/utils/file_download_util.dart

+ 6 - 7
lib/utils/file_download_util.dart

@@ -41,14 +41,13 @@ Future<io.File?> downloadAndDecrypt(
       _logger.warning('$logPrefix incomplete download, file not found');
       return null;
     }
-    _logger.info('$logPrefix download completed');
+    final int sizeInBytes = await encryptedFile.length();
+    final double speedInKBps = sizeInBytes /
+        1024.0 /
+        ((DateTime.now().millisecondsSinceEpoch - startTime) / 1000);
     _logger.info(
-      "$logPrefix avg speed: " +
-          (await io.File(encryptedFilePath).length() /
-                  (DateTime.now().millisecondsSinceEpoch - startTime))
-              .toString() +
-          "kBps",
-    );
+        "$logPrefix download completed, avg speed: ${speedInKBps.toStringAsFixed(2)} KB/s",);
+
     final decryptedFilePath = Configuration.instance.getTempDirectory() +
         file.generatedID.toString() +
         ".decrypted";