Use a standard converter

This commit is contained in:
Manav Rathi 2024-05-23 10:14:18 +05:30
parent 8a2117f9d4
commit 3b89471b87
No known key found for this signature in database
4 changed files with 10 additions and 18 deletions

View file

@ -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(

View file

@ -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}`);

View file

@ -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}`,

View file

@ -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