refactor: optimize chunk handling in JsHttpDownloader

This commit is contained in:
Moyasee
2026-01-06 17:42:42 +02:00
parent 77af7509ac
commit 4975f2def9

View File

@@ -108,7 +108,10 @@ export class JsHttpDownloader {
this.writeStream = fs.createWriteStream(filePath, { flags });
const reader = response.body.getReader();
const self = this;
const onChunk = (length: number) => {
this.bytesDownloaded += length;
this.updateSpeed();
};
const readableStream = new Readable({
async read() {
@@ -120,8 +123,7 @@ export class JsHttpDownloader {
return;
}
self.bytesDownloaded += value.length;
self.updateSpeed();
onChunk(value.length);
this.push(Buffer.from(value));
} catch (err) {
if ((err as Error).name === "AbortError") {