Jszip: Decompressing Folder to files (text)

Created on 8 Oct 2017  路  5Comments  路  Source: Stuk/jszip

I needed to Un-Zip a folder in node js.

I could easily get to the list of fileNames, but could only do the following to extract the file content.

String.fromCharCode.apply(null, zip.files[fileName]._data.compressedContent)

I am sure this is not the right approach, but could find nothing in the documentation to advise me to the correct method.

Most helpful comment

Just for future use, after that you can read the content of each file by the help of async:
http://stuk.github.io/jszip/documentation/api_zipobject/async.html
like this:

  // Closure to capture the file information.
  function handleFile(f) {
    JSZip.loadAsync(f)                                  
      .then(function(zip) {
          zip.forEach(function (relativePath, zipEntry) {  
              zipEntry.async("blob") .then(function (content) { fileReader.readAsArrayBuffer(content); });
          });
      }, function (e) {
          alert("Error reading " + f.name + ": " + e.message);
      });
  }

All 5 comments

I'm trying to find an example for extracting all contents of a zip to a folder too. All examples stop after

zip.loadAsync(data)
.then(content => {
  // list all the files
  console.log(Object.keys(content.files));
  // what next?
})

Just for future use, after that you can read the content of each file by the help of async:
http://stuk.github.io/jszip/documentation/api_zipobject/async.html
like this:

  // Closure to capture the file information.
  function handleFile(f) {
    JSZip.loadAsync(f)                                  
      .then(function(zip) {
          zip.forEach(function (relativePath, zipEntry) {  
              zipEntry.async("blob") .then(function (content) { fileReader.readAsArrayBuffer(content); });
          });
      }, function (e) {
          alert("Error reading " + f.name + ": " + e.message);
      });
  }

@pesarkhobeee The URL seems to be broken, changing it to a https URL seems to work:
http://stuk.github.io/jszip/documentation/api_zipobject/async.html

How can we extract files from .zip using jszip?
I want to open those files in different application...

Was this page helpful?
0 / 5 - 0 ratings