update
This commit is contained in:
+30
@@ -0,0 +1,30 @@
|
||||
// Download electron prebuild tarball via node (follows redirects)
|
||||
const https = require('https');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const url = process.argv[2];
|
||||
const out = process.argv[3];
|
||||
|
||||
function download(u, cb) {
|
||||
https.get(u, { headers: { 'User-Agent': 'node' } }, (res) => {
|
||||
if ([301, 302, 303, 307, 308].includes(res.statusCode)) {
|
||||
return download(res.headers.location, cb);
|
||||
}
|
||||
if (res.statusCode !== 200) {
|
||||
return cb(new Error('HTTP ' + res.statusCode));
|
||||
}
|
||||
const ws = fs.createWriteStream(out);
|
||||
res.pipe(ws);
|
||||
ws.on('finish', () => ws.close(() => cb(null)));
|
||||
ws.on('error', cb);
|
||||
}).on('error', cb);
|
||||
}
|
||||
|
||||
download(url, (err) => {
|
||||
if (err) {
|
||||
console.error('download failed:', err.message);
|
||||
process.exit(1);
|
||||
}
|
||||
console.log('downloaded:', out, fs.statSync(out).size, 'bytes');
|
||||
});
|
||||
Reference in New Issue
Block a user