diff --git a/deps/download.js b/deps/download.js index 6be088c..1a4ffe5 100644 --- a/deps/download.js +++ b/deps/download.js @@ -1,4 +1,4 @@ -const https = require('https'); +const axios = require('axios'); const fs = require('fs'); const path = require('path'); const crypto = require('crypto'); @@ -33,30 +33,35 @@ async function main() { download(); } -function download() { +async function download() { console.log(`downloading ${URL}`); - https.get(URL, async (res) => { - const out = fs.createWriteStream(tmpFile); + const response = await axios({ + method: 'get', + url: URL, + responseType: 'stream' + }); - const hash = crypto.createHash('sha256'); - - const t = new Transform({ - transform(chunk, encoding, callback) { - hash.write(chunk, encoding); - callback(null, chunk); - } - }); + console.log(`Writing to temp file ${tmpFile}`); + const out = fs.createWriteStream(tmpFile); - await pipeline(res, t, out); + const hash = crypto.createHash('sha256'); - const actualDigest = hash.digest('hex'); - if (actualDigest !== HASH) { - fs.unlinkSync(tmpFile); - throw new Error(`Digest mismatch. Expected ${HASH} got ${actualDigest}`); + const t = new Transform({ + transform(chunk, encoding, callback) { + hash.write(chunk, encoding); + callback(null, chunk); } + }); + + await pipeline(response.data, t, out); + + const actualDigest = hash.digest('hex'); + if (actualDigest !== HASH) { + fs.unlinkSync(tmpFile); + throw new Error(`Digest mismatch. Expected ${HASH} got ${actualDigest}`); + } - fs.renameSync(tmpFile, finalFile); - }) + fs.renameSync(tmpFile, finalFile); } main(); diff --git a/package.json b/package.json index 2dc20b6..5d104c0 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "tar": "^6.1.0" }, "devDependencies": { + "axios": "^1.4.0", "chai": "^4.3.6", "cli-color": "^2.0.2", "fs-extra": "^10.1.0",