Skip to content

Commit

Permalink
safe postinstall - connects to #88 #89
Browse files Browse the repository at this point in the history
  • Loading branch information
bubenshchykov committed Aug 23, 2017
1 parent 62b878c commit e57f84f
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions postinstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,10 @@ function download(cb) {
var progress = downloaded + (total ? ('/' + total) : '');
process.stdout.write('ngrok - downloading progress: ' + progress);
shouldClearLine= true;
}
};

var tempFile = path.join(os.tmpdir(), 'ngrok.zip');
var outputStream = fs.createWriteStream(tempFile);
var outputStream = fs.createWriteStream(tempFile).on('error', cb);

request
.get(cdnFile)
Expand All @@ -119,10 +120,13 @@ function download(cb) {
})
.on('complete', function () {
console.log('\nngrok - binary downloaded to ' + localFile);
var readStream = fs.createReadStream(tempFile);
var readStream = fs.createReadStream(tempFile).on('error', cb);
var writeStream = fs.createWriteStream(localFile).on('error', cb);
readStream
.pipe(fs.createWriteStream(localFile))
.on('finish', () => extract(cb));
.pipe(writeStream)
.on('finish', function() {
extract(cb);
});
})
.on('error', function(e) {
console.warn('ngrok - error downloading binary', e);
Expand Down

0 comments on commit e57f84f

Please sign in to comment.