cross-spawn-cb 0.6.0 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,29 +13,37 @@ module.exports = function spawnCallback(command, args, options, callback) {
13
13
  callback = once(callback);
14
14
 
15
15
  var cp = spawn(command, args, options);
16
+
17
+ // collect output
16
18
  var stdout, stderr;
17
- if (cp.stdout) {
18
- stdout = [];
19
- cp.stdout.on('data', stdout.push.bind(stdout));
20
- }
21
- if (cp.stderr) {
22
- stderr = [];
23
- cp.stderr.on('data', stderr.push.bind(stderr));
19
+ if (options.encoding) {
20
+ if (cp.stdout) {
21
+ stdout = [];
22
+ cp.stdout.on('data', stdout.push.bind(stdout));
23
+ }
24
+ if (cp.stderr) {
25
+ stderr = [];
26
+ cp.stderr.on('data', stderr.push.bind(stderr));
27
+ }
24
28
  }
29
+
30
+ // some versions of node emit both an error and close
25
31
  cp.on('error', function error(err) {
26
- // some versions of node emit both an error and close
27
32
  err.code === 'OK' || callback(err);
28
33
  });
34
+
35
+ // done
29
36
  cp.on('close', function (status, signal) {
30
37
  nextTick(function closeNextTick() {
31
- // format results - buffer
32
- if (stdout) stdout = Buffer.concat(stdout);
33
- if (stderr) stderr = Buffer.concat(stderr);
38
+ // process output
39
+ if (options.encoding) {
40
+ stdout = Buffer.concat(stdout);
41
+ stderr = Buffer.concat(stderr);
34
42
 
35
- // format results - string
36
- if ((options.encoding && options.encoding !== 'buffer')) {
37
- stdout = stdout.toString(options.encoding);
38
- stderr = stderr.toString(options.encoding);
43
+ if (options.encoding !== 'buffer') {
44
+ stdout = stdout.toString(options.encoding);
45
+ stderr = stderr.toString(options.encoding);
46
+ }
39
47
  }
40
48
 
41
49
  // process errors
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cross-spawn-cb",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
4
4
  "description": "Cross spawn with a completion callback",
5
5
  "keywords": [
6
6
  "cross-spawn",