fix: Upgrade yauzl, improve stream close handling

This commit is contained in:
Tom Moor
2026-05-27 20:33:33 -04:00
parent c3ba14f069
commit a4a67f2cdd
3 changed files with 29 additions and 8 deletions
+23 -2
View File
@@ -151,6 +151,7 @@ export default class ZipHelper {
}
const chunks: Buffer[] = [];
let bytesRead = 0;
let settled = false;
readStream.on("data", (chunk: Buffer) => {
bytesRead += chunk.length;
if (bytesRead > maxSize) {
@@ -161,8 +162,28 @@ export default class ZipHelper {
}
chunks.push(chunk);
});
readStream.on("end", () => res(Buffer.concat(chunks)));
readStream.on("error", rej);
readStream.on("end", () => {
if (!settled) {
settled = true;
res(Buffer.concat(chunks));
}
});
readStream.on("error", (err) => {
if (!settled) {
settled = true;
rej(err);
}
});
readStream.on("close", () => {
if (!settled) {
settled = true;
rej(
new Error(
`Stream closed before completing read of ${fileName}`
)
);
}
});
});
}),
};