Skip to content

armgit / ente

Public Imported from GitHub
0

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

strict

Manav Rathi824e73f150b0
diff --git a/desktop/src/main/stream.ts b/desktop/src/main/stream.ts
index 26021fdf1f..7b773baed3 100644
--- a/desktop/src/main/stream.ts
+++ b/desktop/src/main/stream.ts
@@ -102,11 +102,23 @@ const handleReadZip = async (zipPath: string, entryName: string) => {
const entry = await zip.entry(entryName);
if (!entry) return new Response("", { status: 404 });
+ // This returns an "old style" NodeJS.ReadableStream.
const stream = await zip.stream(entry);
-
- // TODO(MR): when to call zip.close()
-
- return new Response(Readable.toWeb(new Readable(stream)), {
+ // Convert it into a new style NodeJS.Readable.
+ const nodeReadable = new Readable().wrap(stream);
+ // Then convert it into a Web stream.
+ const webReadableStreamAny = Readable.toWeb(nodeReadable);
+ // However, we get a ReadableStream<any> now. This doesn't go into the
+ // `BodyInit` expected by the Response constructor, which wants a
+ // ReadableStream<Uint8Array>. Force a cast.
+ const webReadableStream =
+ webReadableStreamAny as ReadableStream<Uint8Array>;
+
+ // Close the zip handle when the underlying stream closes.
+ // TODO(MR): Verify
+ stream.on("end", () => zip.close());
+
+ return new Response(webReadableStream, {
headers: {
// We don't know the exact type, but it doesn't really matter,
// just set it to a generic binary content-type so that the