nodejs extract/decompress all content of .gz compressed files to directory

Viewed 331
  1. i have a file in the file system named temp.gz
  2. the temp gzip file contains files and folder
  3. i would like to extract them and have them in a folder like we would normally unzip a file in OS.

i have tried below code but thats not meant for extracting files to folder.

    const unzip = zlib.createUnzip();
    var input = fs.createReadStream(inFilename); /path/to/temp.gz
   
    var output = fs.createWriteStream(outFilename); /path/to/output/folder

Above didnt work and i believe the reason is that it writes to a file and i have provided a directoy.

my requirement is extract files to directory.

        zlib.gzip(responseData, (err, buffer) => {
  
         // Calling gunzip method
        zlib.gunzip(buffer, (err, buffer) => {
        
           console.log(buffer,pathFileName);
           fs.appendFileSync(pathFileName, buffer);

           });
        });

above i was trying to unzip as per the docs and write buffer to the output file and didnt create a folder as expected and didnt add the files there

sure i am missing something but not sure what.

0 Answers
Related