[desktop] Fix stream.end not always being emitted (#2296)
This caused the reference counts to not be zero when we'd go to clear the cache in `clearPendingUploads`. Bug introduced in the nightly build, but didn't have any negative impact except printing an error in the logs because of the unhandled promise rejection. Ref: https://github.com/nodejs/node/issues/10871#issuecomment-650150155
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user