node-gpg icon indicating copy to clipboard operation
node-gpg copied to clipboard

not working for me

Open elangelo opened this issue 9 years ago • 5 comments

I'm probably doing something very stupid but i guess i'll need some help.

var gpg = require('gpg');
var fs = require('fs');

var keyFile = '/home/samuel/file-enc-pubkey.txt'

gpg.importKeyFromFile(keyFile, function (err, result, fingerprint) {
    if (err) {
        console.log(err);
    }

    var readStream = fs.createReadStream('file.txt');
    var writeStream = fs.createWriteStream('file.txt.gpg'); 
    var args = [
        '--encrypt',
        '--recipient', fingerprint,
        '--armor',
        '--trust-model', 'always'
    ];
    gpg.encryptToStream({source: readStream, dest: writeStream, args: args}, function(error, writeStream){
        if (error){
            console.log(error);
        }
    });
});

This code give me no errors at all but i get an empty file at the end... if i use the simple encrypt method i can see that my callback does contain 'stuff'

elangelo avatar Feb 25 '17 15:02 elangelo

I welcome bug reports, but this sounds like it may be a question better directed to stack overflow

freewil avatar Apr 03 '17 05:04 freewil

I'd call it a bug in the documentation then.

elangelo avatar Apr 03 '17 06:04 elangelo

Hi, it is a known bug relative to the node-gpg streaming API. It swallow every critical error as gpg binary is unclear on how to trigger errors correctly.

You may have to check if your key and parameters are well set.

Try to build a shell command line with them.

A fix is in the pipe for this bug, but its pretty hard to manage error flows from gpg so dont expect it to come early.

Cheers

Champii avatar Apr 27 '17 18:04 Champii

The problem is possibly that the callback you provide in gpg.encryptToStream() is only called once here. This is done as soon as the subprocess is spawned. If an error occurs later, the shot is already fired.

It worked for me with L104 commented out. The callback at that time makes IMHO no sense anyway.

florianbehrens avatar Oct 25 '17 07:10 florianbehrens

Did you fix it? do you have the source code? @elangelo

victorjoel44 avatar Apr 22 '18 02:04 victorjoel44