Manav Rathi 1 anno fa
parent
commit
e8c2717bf7
1 ha cambiato i file con 9 aggiunte e 6 eliminazioni
  1. 9 6
      web/apps/photos/src/services/download/index.ts

+ 9 - 6
web/apps/photos/src/services/download/index.ts

@@ -361,9 +361,14 @@ class DownloadManagerImpl {
                             buffer.set(new Uint8Array(data), 0);
                             buffer.set(new Uint8Array(value), data.byteLength);
 
+                            // Note that buffer.length might be a multiple of
+                            // decryptionChunkSizes. We let that accumulate, and
+                            // drain it all with a while loop when done.
+
                             if (buffer.length > decryptionChunkSize) {
-                                const fileData = new Uint8Array(
-                                    buffer.slice(0, decryptionChunkSize),
+                                const fileData = buffer.slice(
+                                    0,
+                                    decryptionChunkSize,
                                 );
 
                                 const { decryptedData } =
@@ -372,11 +377,9 @@ class DownloadManagerImpl {
                                         pullState,
                                     );
                                 controller.enqueue(decryptedData);
-                                data = new Uint8Array(
-                                    buffer.slice(decryptionChunkSize),
-                                );
+                                data = buffer.slice(decryptionChunkSize);
                             } else {
-                                data = new Uint8Array(buffer);
+                                data = buffer;
                             }
                             more = true;
                         } else {