From 93795e29d1e457c0dd56f8b0562600bbdae8a96e Mon Sep 17 00:00:00 2001 From: Onja Date: Tue, 10 Oct 2023 16:47:01 +0300 Subject: [PATCH] Add event listener for 'download.started' with the filepath and length information --- src/models/file.js | 1 + src/subscribers/consoleSubscriber.js | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/src/models/file.js b/src/models/file.js index 7eff0f1..20ce5cf 100644 --- a/src/models/file.js +++ b/src/models/file.js @@ -78,6 +78,7 @@ class File { // Get the content length and parse it to an integer const contentLength = parseInt(response.headers['content-length'], 10); + emitter.emit('download.started', { url: this.url, filepath: this.filepath, length: contentLength }); const step = Math.floor(contentLength / 100); let stepLimit = step; diff --git a/src/subscribers/consoleSubscriber.js b/src/subscribers/consoleSubscriber.js index b1ebf0a..369dbea 100644 --- a/src/subscribers/consoleSubscriber.js +++ b/src/subscribers/consoleSubscriber.js @@ -13,6 +13,11 @@ emitter.on('download.start', ({ url, filepath }) => { log('download.start', `Downloading to ${filepath}`); }); +// Create a new listener for the download.start event +emitter.on('download.started', ({ url, filepath, length }) => { + log('download.started', `Downloading to ${filepath} and length is ${length}`); +}); + // Create a new listener for the download.end event emitter.on('download.end', ({ url, filepath }) => { log('download.end', `Downloaded to ${filepath}`);