Skip to content

armgit / ente

Public Imported from GitHub
0

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

[desktop] Fix stream.end not always being emitted

Manav Rathic354c80b1f68
diff --git a/desktop/src/main/stream.ts b/desktop/src/main/stream.ts
index beddab8488..749c94f491 100644
--- a/desktop/src/main/stream.ts
+++ b/desktop/src/main/stream.ts
@@ -115,12 +115,15 @@ const handleRead = async (path: string) => {
const handleReadZip = async (zipPath: string, entryName: string) => {
const zip = openZip(zipPath);
const entry = await zip.entry(entryName);
- if (!entry) return new Response("", { status: 404 });
+ if (!entry) {
+ markClosableZip(zipPath);
+ return new Response("", { status: 404 });
+ }
// This returns an "old style" NodeJS.ReadableStream.
const stream = await zip.stream(entry);
// Convert it into a new style NodeJS.Readable.
- const nodeReadable = new Readable().wrap(stream);
+ const nodeReadable = new Readable({ emitClose: true }).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
@@ -130,7 +133,7 @@ const handleReadZip = async (zipPath: string, entryName: string) => {
webReadableStreamAny as ReadableStream<Uint8Array>;
// Let go of the zip handle when the underlying stream closes.
- stream.on("end", () => markClosableZip(zipPath));
+ nodeReadable.on("close", () => markClosableZip(zipPath));
// While it is documented that entry.time is the modification time,
// the units are not mentioned. By seeing the source code, we can