Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Use a standard converter

Manav Rathi3b89471b875b
diff --git a/web/apps/photos/src/services/download/index.ts b/web/apps/photos/src/services/download/index.ts
index ee7e91fb5d..eb979af875 100644
--- a/web/apps/photos/src/services/download/index.ts
+++ b/web/apps/photos/src/services/download/index.ts
@@ -11,7 +11,7 @@ import { Remote } from "comlink";
import isElectron from "is-electron";
import * as ffmpeg from "services/ffmpeg";
import { EnteFile } from "types/file";
-import { generateStreamFromArrayBuffer, getRenderableImage } from "utils/file";
+import { getRenderableImage } from "utils/file";
import { PhotosDownloadClient } from "./clients/photos";
import { PublicAlbumsDownloadClient } from "./clients/publicAlbums";
@@ -289,7 +289,7 @@ class DownloadManagerImpl {
await this.cryptoWorker.fromB64(file.file.decryptionHeader),
file.key,
);
- return generateStreamFromArrayBuffer(decrypted);
+ return new Response(decrypted).body;
} catch (e) {
if (e.message === CustomError.PROCESSING_FAILED) {
log.error(
diff --git a/web/apps/photos/src/services/export/index.ts b/web/apps/photos/src/services/export/index.ts
index 3a68837e75..16472b3b4f 100644
--- a/web/apps/photos/src/services/export/index.ts
+++ b/web/apps/photos/src/services/export/index.ts
@@ -29,7 +29,6 @@ import {
getNonEmptyPersonalCollections,
} from "utils/collection";
import {
- generateStreamFromArrayBuffer,
getPersonalFiles,
getUpdatedEXIFFileForDownload,
mergeMetadata,
@@ -1026,7 +1025,6 @@ class ExportService {
videoExportName,
);
- const imageStream = generateStreamFromArrayBuffer(livePhoto.imageData);
await this.saveMetadataFile(
collectionExportPath,
imageExportName,
@@ -1035,10 +1033,9 @@ class ExportService {
await writeStream(
electron,
`${collectionExportPath}/${imageExportName}`,
- imageStream,
+ new Response(livePhoto.imageData).body,
);
- const videoStream = generateStreamFromArrayBuffer(livePhoto.videoData);
await this.saveMetadataFile(
collectionExportPath,
videoExportName,
@@ -1048,7 +1045,7 @@ class ExportService {
await writeStream(
electron,
`${collectionExportPath}/${videoExportName}`,
- videoStream,
+ new Response(livePhoto.videoData).body,
);
} catch (e) {
await fs.rm(`${collectionExportPath}/${imageExportName}`);
diff --git a/web/apps/photos/src/utils/file/index.ts b/web/apps/photos/src/utils/file/index.ts
index af5c06e8e0..f2f9932dd8 100644
--- a/web/apps/photos/src/utils/file/index.ts
+++ b/web/apps/photos/src/utils/file/index.ts
@@ -262,15 +262,6 @@ export async function decryptFile(
}
}
-export function generateStreamFromArrayBuffer(data: Uint8Array) {
- return new ReadableStream({
- async start(controller: ReadableStreamDefaultController) {
- controller.enqueue(data);
- controller.close();
- },
- });
-}
-
/**
* The returned blob.type is filled in, whenever possible, with the MIME type of
* the data that we're dealing with.
@@ -649,7 +640,7 @@ async function downloadFileDesktop(
imageFileName,
fs.exists,
);
- const imageStream = generateStreamFromArrayBuffer(imageData);
+ const imageStream = new Response(imageData).body;
await writeStream(
electron,
`${downloadDir}/${imageExportName}`,
@@ -661,7 +652,7 @@ async function downloadFileDesktop(
videoFileName,
fs.exists,
);
- const videoStream = generateStreamFromArrayBuffer(videoData);
+ const videoStream = new Response(videoData).body;
await writeStream(
electron,
`${downloadDir}/${videoExportName}`,
diff --git a/web/packages/next/blob-cache.ts b/web/packages/next/blob-cache.ts
index 7223d0fdc1..0db9464521 100644
--- a/web/packages/next/blob-cache.ts
+++ b/web/packages/next/blob-cache.ts
@@ -136,6 +136,10 @@ export const openBlobCache = async (
*
* new Blob([arrayBuffer, andOrAnyArray, andOrstring])
*
+ * To convert from a Uint8Array/ArrayBuffer/Blob to a ReadableStream
+ *
+ * new Response(array).body
+ *
* Refs:
* - https://github.com/yigitunallar/arraybuffer-vs-blob
* - https://stackoverflow.com/questions/11821096/what-is-the-difference-between-an-arraybuffer-and-a-blob