Skip to content

Read zip files recursively with zip.js #265

Discussion options

You must be logged in to vote

You could use the function below which accepts a ZipReader instance as parameter and returns all the entries recursively.

async function getAllEntries(zipReader, options) {
  let entries = await zipReader.getEntries(options);
  entries = await Promise.all(entries.map(async entry => {
    if (entry.filename.toLowerCase().endsWith(".zip")) {
      const innerZipReader = new zip.ZipReader(new zip.BlobReader(await entry.getData(new zip.BlobWriter())));
      return getAllEntries(innerZipReader, options);
    } else {
      return entry;
    }
  }));
  return entries.flat();
}

Here is below an example of code showing how to use it.

/* global zip, Blob */

"use strict";

const TEXT_CONTENT = "L…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Venkatesh0625
Comment options

Answer selected by Venkatesh0625
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants