I have a file .tar.gz
, which I have to unzip in a path, but I need to check what is inside it to later 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!");
}
});
As I could review what it contains before it is decompressed, for example that there is a text.txttar.gz
file inside , and that I can read that file from inside and depending on what it says, I decompress or not. Thanks in advance
how are you?
The following occurs to me:
1 - You can use the following module to run CMD on the server as the documentation for that module shows: https://www.npmjs.com/package/node-command-line
2 - Taking the first point into account, you can execute a console command with which you can extract a specific file inside a tar.gz with the following command:
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 for the file to be uncompressed and to be able to read it.
Greetings and tell us how it went.