Use a standard converter
This commit is contained in:
parent
8a2117f9d4
commit
3b89471b87
4 changed files with 10 additions and 18 deletions
|
@ -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(
|
||||
|
|
|
@ -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}`);
|
||||
|
|
|
@ -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}`,
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue