From 4975f2def92c81cc7ceccdd920bf3942560169be Mon Sep 17 00:00:00 2001 From: Moyasee Date: Tue, 6 Jan 2026 17:42:42 +0200 Subject: [PATCH] refactor: optimize chunk handling in JsHttpDownloader --- src/main/services/download/js-http-downloader.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/services/download/js-http-downloader.ts b/src/main/services/download/js-http-downloader.ts index 454ef197..4122cf34 100644 --- a/src/main/services/download/js-http-downloader.ts +++ b/src/main/services/download/js-http-downloader.ts @@ -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") {