Search code examples
angularextractunzip

Extract Zip file and read the data inside the file in angular


I have a zip file which is uploaded using file input.I want to read the data from that zip file.Can anyone help me to read the data inside the zip file.


Solution

  • Use jszip library- https://stuk.github.io/jszip/.

    const jsZip = require('jszip');
      jsZip.loadAsync(fileList[0]).then((zip) => { // <----- HERE
        Object.keys(zip.files).forEach((filename) => { // <----- HERE
          zip.files[filename].async('string').then((fileData) => { // <----- HERE
             this.fileData = this.fileData + '**$$##$$**' + fileData;
          });
        });
      });
    

    Source: Reading zip file contents and assign it to local variable