Skip to content

Commit

Permalink
Detect end of write stream better to prevent unzipping too early
Browse files Browse the repository at this point in the history
  • Loading branch information
aredridel committed Dec 9, 2017
1 parent 7057245 commit 7f80194
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const cp = P.promisifyAll(require('child_process'));
const yargs = require('yargs');
const pump = P.promisify(require('pump'));
const debug = require('util').debuglog('node-bin-gen');
const eos = P.promisify(require('end-of-stream'));

yargs.option('skip-binaries', { describe: 'Skip downloading the binaries', boolean: true });
yargs.option('only', { describe: 'Only download this binary package' });
Expand Down Expand Up @@ -87,7 +88,9 @@ function buildArchPackage(os, cpu, version, pre) {
if (os == 'win') {
const f = fs.createWriteStream(filename);
const written = pump(res.body, f);
return written.then(() => cp.execFileAsync('unzip', ['-d', `${dir}/bin`, '-o', '-j', filename, `${base}/node.exe` ]));
const closed = eos(f);

return P.all([written, closed]).then(() => cp.execFileAsync('unzip', ['-d', `${dir}/bin`, '-o', '-j', filename, `${base}/node.exe` ]));
} else {
const c = cp.spawn('tar', ['--strip-components=1', '-C', dir, '-x'], {
stdio: [ 'pipe', process.stdout, process.stderr ]
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
},
"dependencies": {
"bluebird": "^3.5.1",
"end-of-stream": "^1.4.0",
"make-fetch-happen": "^2.6.0",
"pump": "^2.0.0",
"rimraf": "^2.6.2",
Expand Down

0 comments on commit 7f80194

Please sign in to comment.