Jelajahi Sumber

Remove all writeAsBytesSync ops

vishnukvmd 3 tahun lalu
induk
melakukan
1d6fc95593
3 mengubah file dengan 13 tambahan dan 13 penghapusan
  1. 4 4
      lib/utils/crypto_util.dart
  2. 2 2
      lib/utils/file_uploader.dart
  3. 7 7
      lib/utils/file_util.dart

+ 4 - 4
lib/utils/crypto_util.dart

@@ -42,7 +42,7 @@ EncryptionResult chachaEncryptData(Map<String, dynamic> args) {
       encryptedData: encryptedData, header: initPushResult.header);
 }
 
-EncryptionResult chachaEncryptFile(Map<String, dynamic> args) {
+Future<EncryptionResult> chachaEncryptFile(Map<String, dynamic> args) async {
   final encryptionStartTime = DateTime.now().millisecondsSinceEpoch;
   final logger = Logger("ChaChaEncrypt");
   final sourceFile = io.File(args["sourceFilePath"]);
@@ -66,7 +66,7 @@ EncryptionResult chachaEncryptFile(Map<String, dynamic> args) {
     bytesRead += chunkSize;
     final encryptedData = Sodium.cryptoSecretstreamXchacha20poly1305Push(
         initPushResult.state, buffer, null, tag);
-    destinationFile.writeAsBytesSync(encryptedData, mode: io.FileMode.append);
+    await destinationFile.writeAsBytes(encryptedData, mode: io.FileMode.append);
   }
   inputFile.closeSync();
 
@@ -76,7 +76,7 @@ EncryptionResult chachaEncryptFile(Map<String, dynamic> args) {
   return EncryptionResult(key: key, header: initPushResult.header);
 }
 
-void chachaDecryptFile(Map<String, dynamic> args) {
+Future<void> chachaDecryptFile(Map<String, dynamic> args) async {
   final logger = Logger("ChaChaDecrypt");
   final decryptionStartTime = DateTime.now().millisecondsSinceEpoch;
   final sourceFile = io.File(args["sourceFilePath"]);
@@ -99,7 +99,7 @@ void chachaDecryptFile(Map<String, dynamic> args) {
     bytesRead += chunkSize;
     final pullResult =
         Sodium.cryptoSecretstreamXchacha20poly1305Pull(pullState, buffer, null);
-    destinationFile.writeAsBytesSync(pullResult.m, mode: io.FileMode.append);
+    await destinationFile.writeAsBytes(pullResult.m, mode: io.FileMode.append);
     tag = pullResult.tag;
   }
   inputFile.closeSync();

+ 2 - 2
lib/utils/file_uploader.dart

@@ -308,8 +308,8 @@ class FileUploader {
         await io.File(encryptedThumbnailPath).delete();
       }
       final encryptedThumbnailFile = io.File(encryptedThumbnailPath);
-      encryptedThumbnailFile
-          .writeAsBytesSync(encryptedThumbnailData.encryptedData);
+      await encryptedThumbnailFile
+          .writeAsBytes(encryptedThumbnailData.encryptedData);
 
       final thumbnailUploadURL = await _getUploadURL();
       String thumbnailObjectKey =

+ 7 - 7
lib/utils/file_util.dart

@@ -136,9 +136,9 @@ Future<io.File> _downloadLivePhoto(ente.File file,
             tempPath + file.uploadedFileID.toString() + filename;
         List<int> data = archiveFile.content;
         if (filename.startsWith("image")) {
-          io.File imageFile = io.File(decodePath)
-            ..createSync(recursive: true)
-            ..writeAsBytesSync(data);
+          final imageFile = io.File(decodePath);
+          await imageFile.create(recursive: true);
+          await imageFile.writeAsBytes(data);
           io.File imageConvertedFile = imageFile;
           if ((fileExtension == "unknown") ||
               (io.Platform.isAndroid && fileExtension == "heic")) {
@@ -151,16 +151,16 @@ Future<io.File> _downloadLivePhoto(ente.File file,
           }
           imageFileCache = await DefaultCacheManager().putFile(
             file.getDownloadUrl(),
-            imageConvertedFile.readAsBytesSync(),
+            await imageConvertedFile.readAsBytes(),
             eTag: file.getDownloadUrl(),
             maxAge: Duration(days: 365),
             fileExtension: fileExtension,
           );
           await imageConvertedFile.delete();
         } else if (filename.startsWith("video")) {
-          io.File videoFile = io.File(decodePath)
-            ..createSync(recursive: true)
-            ..writeAsBytesSync(data);
+          final videoFile = io.File(decodePath);
+          await videoFile.create(recursive: true);
+          await videoFile.writeAsBytes(data);
           videoFileCache = await VideoCacheManager.instance.putFile(
             file.getDownloadUrl(),
             videoFile.readAsBytesSync(),