Skip to content

Commit

Permalink
use spawning for child process, update version
Browse files Browse the repository at this point in the history
  • Loading branch information
TheTechsTech committed Dec 22, 2020
1 parent de7613a commit 03a592f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 24 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-7z-archive",
"version": "0.9.11",
"version": "1.0.0",
"description": "ESM front-end to 7-Zip, featuring alternative full 7z CLI tools, binaries for Linux, Windows, Mac OSX, seamlessly create 7zip SFX self extracting archives targeting different platforms.",
"type": "module",
"main": "lib/index.mjs",
Expand Down
48 changes: 26 additions & 22 deletions util/run.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import {
EOL
} from 'os';
import { spawn } from 'child_process';
import { spawning } from 'node-sys';
import when from 'when';
import {
normalize,
Expand Down Expand Up @@ -92,34 +92,38 @@ export default function (binary = '7z', command = null, switches = {}, override
// error's message. Otherwise progress with stdout message.
let err;
let reg = new RegExp('Error:(' + EOL + '|)?(.*)', 'i');
let onprogress = (object) => {
progress(object.output);
return args;
};

let onerror = (data) => {
let res = reg.exec(data);
if (res) {
err = new Error(res[2].substr(0, res[2].length - 1));
return err;
}
};

let res = {
cmd: cmd,
args: args,
options: {
stdio: 'pipe'
stdio: 'pipe',
onprogress: onprogress,
onerror: onerror
}
};

//console.log('>> ', res.cmd, res.args.join(' '), res.options,' <<');
let run = spawn(res.cmd, res.args, res.options);
run.stderr.on('data', function (data) {
let res = reg.exec(data.toString());
if (res) {
err = new Error(res[2].substr(0, res[2].length - 1));
}
});
run.stdout.on('data', function (data) {
return progress(data.toString());
});
run.on('error', function (err) {
reject(err);
});
run.on('close', function (code) {
if (code === 0) {
return fulfill(args);
}
return reject(err, code);
});
spawning(res.cmd, res.args, res.options)
.then((data) => {
if (data === args)
return fulfill(args);

return reject(err);
})
.catch((err) => {
return reject(err);
});
});
};

0 comments on commit 03a592f

Please sign in to comment.