-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.js
More file actions
39 lines (37 loc) · 1.31 KB
/
install.js
File metadata and controls
39 lines (37 loc) · 1.31 KB
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
32
33
34
35
36
37
38
39
var pkg = require('./package.json');
var host = pkg.author.name + '.github.io';
var options = {
method: 'GET',
host: host,
path: '/' + pkg.name + '/dists/' + process.platform + '-' + process.arch + '-' + process.versions.modules + '.gz',
headers: {
Host: host,
'Accept-Encoding': 'gzip, deflate',
Connection: 'close'
}
};
require('http').request(options, function (tres) {
if (tres.statusCode !== 200) {
return onerror({message: 'file not found'});
}
var zlib = require('zlib');
if (tres.headers['content-encoding'] === 'gzip') {
tres = tres.pipe(zlib.createGunzip())
} else if (tres.headers['content-encoding'] === 'deflate') {
tres = tres.pipe(zlib.createInflateRaw())
}
tres = tres.pipe(zlib.createGunzip());
var fs = require('fs');
if (!fs.existsSync('build/Release')) {
fs.existsSync('build') || fs.mkdirSync('build');
fs.mkdirSync('build/Release');
}
tres.pipe(require('fs').createWriteStream('build/Release/java.node'));
tres.on('end', function () {
console.log('binary installed');
});
}).on('error', onerror).end();
function onerror(err) {
console.error(err.message);
console.error('binary installation failed, please rebuild it manually...');
}