From e57f84f31a2c4fb16e29906f9d89257bc22f5bb5 Mon Sep 17 00:00:00 2001 From: bubenshchykov Date: Thu, 24 Aug 2017 00:00:39 +0300 Subject: [PATCH] safe postinstall - connects to #88 #89 --- postinstall.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/postinstall.js b/postinstall.js index 3f3547c..e85ff5a 100644 --- a/postinstall.js +++ b/postinstall.js @@ -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) @@ -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);