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

Fix broken fs.unlink call and add proxy support #151

Closed
wants to merge 1 commit into from
Closed
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
16 changes: 14 additions & 2 deletions install.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
* @License MIT
*/

var urlparser = require('url')
var https = require('https');
var HttpsProxyAgent = require('https-proxy-agent');
var fs = require('fs');
var path = require('path');
var exec = require('child_process').exec;
Expand Down Expand Up @@ -140,13 +142,22 @@ function download(url, dest, cb) {
cb(null);
}
var file = fs.createWriteStream(dest);
var request = https.get(url, function(response) {

var proxyServer = process.env.http_proxy ||
process.env.HTTP_PROXY ||
process.env.https_proxy ||
process.env.HTTPS_PROXY;
var agent = new HttpsProxyAgent(proxyServer);
var options = urlparser.parse(url)
options.agent = agent

var request = https.get(options, function(response) {
response.pipe(file);
file.on('finish', function() {
file.close(cb); // close() is async, call cb after close completes.
});
}).on('error', function(err) { // Handle errors
fs.unlink(dest); // Delete the file async. (But we don't check the result)
fs.unlinkSync(dest);
if (cb) cb(err);
});
}
Expand Down Expand Up @@ -178,6 +189,7 @@ function downloadAll(files, baseURL, basePath, next) {
console.log('Download: ' + url);
download(url, path, function(err) {
if (err) {
console.log(err);
throw err;
}
downloadAll(files, baseURL, basePath, next);
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"main": "index.js",
"description": "Lib Sodium port for node.js",
"dependencies": {
"https-proxy-agent": "^2.2.1",
"node-addon-api": "*"
},
"devDependencies": {
Expand Down