mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-11 22:06:17 +00:00
refactor: optimize chunk handling in JsHttpDownloader
This commit is contained in:
@@ -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") {
|
||||
|
||||
Reference in New Issue
Block a user