Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch download to support proxies #11

Open
wants to merge 1 commit into
base: better-sqlcipher
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 24 additions & 19 deletions deps/download.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const https = require('https');
const axios = require('axios');
const fs = require('fs');
const path = require('path');
const crypto = require('crypto');
Expand Down Expand Up @@ -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();
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down