From a64d65b80eacb6d7b5336d9f8068a7845f96b7ec Mon Sep 17 00:00:00 2001 From: Kamalpreet Kaur Date: Mon, 26 Aug 2024 20:09:24 +0530 Subject: [PATCH] update: accept gzip encoding for Local Binary --- lib/download.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/download.js b/lib/download.js index 34f93a8..b0b68f0 100644 --- a/lib/download.js +++ b/lib/download.js @@ -1,13 +1,15 @@ const https = require('https'), fs = require('fs'), HttpsProxyAgent = require('https-proxy-agent'), - url = require('url'); + url = require('url'), + zlib = require('zlib'); const binaryPath = process.argv[2], httpPath = process.argv[3], proxyHost = process.argv[4], proxyPort = process.argv[5], useCaCertificate = process.argv[6]; var fileStream = fs.createWriteStream(binaryPath); var options = url.parse(httpPath); +options.headers = { 'Accept-Encoding': 'gzip' }; if(proxyHost && proxyPort) { options.agent = new HttpsProxyAgent({ host: proxyHost, @@ -17,13 +19,13 @@ if(proxyHost && proxyPort) { try { options.ca = fs.readFileSync(useCaCertificate); } catch(err) { - console.log("failed to read cert file", err) + console.log('failed to read cert file', err); } } } https.get(options, function (response) { - response.pipe(fileStream); + response.pipe(zlib.createGunzip()).pipe(fileStream); // unzip response.on('error', function(err) { console.error('Got Error in binary download response', err); });