Skip to content

Commit 6bb6399

Browse files
committed
perform actions on filestream close
1 parent 34e9528 commit 6bb6399

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

lib/LocalBinary.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function LocalBinary(){
2828

2929
var destBinaryName = (this.windows) ? 'BrowserStackLocal.exe' : 'BrowserStackLocal';
3030
var binaryPath = path.join(destParentDir, destBinaryName);
31-
var file = fs.createWriteStream(binaryPath);
31+
var fileStream = fs.createWriteStream(binaryPath);
3232

3333
var options = url.parse(this.httpPath);
3434
if(conf.proxyHost && conf.proxyPort){
@@ -39,12 +39,15 @@ function LocalBinary(){
3939
}
4040

4141
https.get(options, function (response) {
42-
response.on('end', function () {
42+
response.pipe(fileStream);
43+
fileStream.on('error', function (err) {
44+
console.error('Got Error while downloading binary file', err);
45+
});
46+
fileStream.on('close', function () {
4347
fs.chmod(binaryPath, '0755', function() {
4448
callback(binaryPath);
4549
});
4650
});
47-
response.pipe(file);
4851
});
4952
};
5053

0 commit comments

Comments
 (0)