-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathdownload.js
More file actions
31 lines (27 loc) · 922 Bytes
/
Copy pathdownload.js
File metadata and controls
31 lines (27 loc) · 922 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const https = require('https'),
fs = require('fs'),
HttpsProxyAgent = require('https-proxy-agent'),
url = require('url');
const binaryPath = process.argv[2],httpPath = process.argv[3], proxyHost = process.argv[4], proxyPort = process.argv[5];
var fileStream = fs.createWriteStream(binaryPath);
var options = url.parse(httpPath);
if(proxyHost && proxyPort) {
options.agent = new HttpsProxyAgent({
host: proxyHost,
port: proxyPort
});
}
https.get(options, function (response) {
response.pipe(fileStream);
response.on('error', function(err) {
console.error('Got Error in binary download response', err);
});
fileStream.on('error', function (err) {
console.error('Got Error while downloading binary file', err);
});
fileStream.on('close', function () {
console.log('Done');
});
}).on('error', function(err) {
console.error('Got Error in binary downloading request', err);
});