Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion lib/spawnGPG.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,39 @@ module.exports.streaming = function(options, args, cb) {
// Go for it
var gpg = spawnIt(args, cb);

let stderrData = []
gpg.stderr.on('data', (data) => {
stderrData.push(data);
});
Comment on lines +99 to +102
Copy link
Collaborator

@freewil freewil Dec 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll have to take a closer look at how this streaming func is used, but initial thoughts:

can you rename stderrData to error, rename data to buf and initialize error as an empty string and then change the push so that it appends to error so it is consistent with this:

node-gpg/lib/spawnGPG.js

Lines 28 to 38 in 510c58c

var error = '';
var gpg = spawnIt(gpgArgs, cb);
gpg.stdout.on('data', function (buf){
buffers.push(buf);
buffersLength += buf.length;
});
gpg.stderr.on('data', function(buf){
error += buf.toString('utf8');
});


if (!isDestStream) {
gpg.on('close', function (code){
cb(null);
if (code!=0) {
cb(new Error(`gpg: exit code ${code}\n${stderrData.join('')}`));
} else {
cb(null);
}
});
} else {
cb(null, destStream);
}

sourceStream.on('error', function(error) {
console.log(error);
})

destStream.on('error', function(error) {
console.log(error);
})

gpg.stdin.on('error', function(error) {
console.log(error);
})

gpg.stdout.on('error', function(error) {
console.log(error);
})

// Pipe input file into gpg stdin; gpg stdout into output file..
sourceStream.pipe(gpg.stdin);
gpg.stdout.pipe(destStream);
Expand Down