Contents of a tar.gz with nodejs

0

I have a file .tar.gz , which I have to decompress in a route, but I need to review what is inside it and then unzip it. I have the following code:

const targz = require('targz');

targz.decompress({
    src: 'archivo.tar.gz',
    dest: 'ruta' //ruta donde se realiza la descompresión ...
}, function(err){
    if(err) {
        console.log(err);
    } else {
        console.log("Done!");
    }
});

How could I check what contains the tar.gz before it is unzipped, for example that within a text.txt file, and that I can read that file from within and depending on whatever you say, unzip or not. Thanks in advance

    
asked by Travv 03.01.2018 в 15:44
source

1 answer

1

how are you?

I can think of the following:

1 - You can use the following module to run CMD on the server as shown in the documentation of that module: link

2 - Taking the first point into account, you can execute console command with which you can extract a specific file inside a tar.gz with the following command:

tar -zxvf <tar filename> <file you want to extract>

3 - After extracting the file you need, you can read it to see what you do next.

Remember to handle the callbacks well to wait and unzip the file and be able to read it.

Greetings and tell us how it went.

    
answered by 03.01.2018 / 16:06
source