Saving unzipped content using jszip's forEach method is a useful technique that allows you

I'm trying to understand why the zip.files[filename].async('blob') isn't being added to the promises list in the code below. When I check console.log(data.length), it always shows 0. Can anyone help me figure out what's going wrong?

 const promises = [];

  var jsZip = require('jszip');
  jsZip.loadAsync(file.object).then(function (zip) {
    Object.keys(zip.files).forEach(function (filename) {
      promises.push(zip.files[filename].async('blob'));
      console.log(promises.length);
    })
  });

  Promise.all(promises).then(function(data){
    console.log(data.length);
  });

Answer №1

After some trial and error, I finally cracked the code on how to make it work:

  const jsZip = require('jszip');
  jsZip.loadAsync(file.object).then(function (zip) {

    const filePromises = [];
    Object.keys(zip.files).forEach(function (filename) {
      filePromises.push(zip.files[filename].async('blob'));
    })

    Promise.all(filePromises).then(function(data){
      console.log(data.length);
    });
  });

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Guide on transferring text from .txt document to .xlsx file in a Node.js environment with the assistance of the xlsx library

I recently extracted names from my cypress test and stored them in a text file called 'name.txt' located in the root directory of my project. Now, I am looking to transfer all the text from 'name.txt' into an excel file named 'qaau ...

Nested MongoDB object within multiple arrays

I need help with handling this JSON data structure: { data : { fields_data : [ [ { key1 : val }, { key1 : val } ], [ { key2 : val }, { key2 : val ...

Best practices for organizing an array of objects in JavaScript

I have an array of objects with nested arrays inside, and I need to restructure it according to my API requirements. [{ containerId: 'c12', containerNumber: '4321dkjkfdj', goods: [{ w ...

The issue with the Z-index being ineffective is causing the button to appear behind a container in the HTML-CSS

I am currently using Metro CSS (Windows 8 style) and running into an issue. Within my container, there are alerts displayed in blue, and above that is 'IT-CENTER'. When I click on 'IT-CENTER', a button should appear, but it seems to be ...

Determining the class or ID name of an element by assessing the value of a specific attribute

Is it possible to retrieve the class or ID names of all elements with a specific attribute value? For instance, given the code below: <rect class="rect0" x="45" y="0px" width="40px" height="40px" fill="#ff0000" selected="0"></rect> <rect cl ...

How come my directive is being updated when there are changes in a different instance of the same directive?

For the purpose of enabling Angular binding to work, I developed a straightforward directive wrapper around the HTML file input. Below is the code for my directive: angular.module('myApp').directive('inputFile', InputFileDirective); f ...

The addition of ngRoute causes the controller in AngularJS to malfunction

Currently, I am attempting to implement routes in my angularJS application and have encountered an issue where integrating 'ngRoute' into the app causes the main controller to malfunction. Furthermore, I am experiencing difficulties with ngRoute ...

Emphasize SELENIDE rows

My goal is to achieve the following: @Test public void tableTest() { getDriver().get(BASE_URL + "tabulka.php"); List<WebElement> rows = getDriver().findElements(By.xpath("//table//tbody//tr")); for (We ...

Measuring the Unquantifiable: Embracing Undefined Values in MongoDB

Issue Despite multiple attempts, the Node.js MongoDB library consistently returns undefined for collection.count({}). I have thoroughly researched previous solutions to similar questions without success - the problem persists and the result is always unde ...

Disabling the submit button in Vue.js by implementing error validation for input fields

computed: { isDisabled: function(){ return !(this.errmsg.email < this.email.minemail) } watch: { email(value){ // binding this to the data value in the email input this.email = value; ...

Unexpected '->' found on page during loading

After migrating my WordPress site from localhost to the live server, I encountered an issue where "-->" appeared before the page finished loading. Can anyone explain this strange behavior? In addition to this issue, the jQuery scripts I had implemented ...

Transfer the imageURI to a different HTML page

My mobile app, created using PhoneGap, allows users to select an image from their album. I want to pass that selected image and display it on another HTML page. Does anyone have any suggestions on how to achieve this? Below is the code snippet: selectImag ...

Achieving consistent scroll position when utilizing the history.js library to navigate back with the click of a button

I need help implementing a feature that allows users to return to the same position on a webpage when clicking the back button. A common example is on ecommerce sites where if you scroll down, click on a product, then go back, you should be taken back to t ...

Establishing standard emit actions in a Vue JS component layout

I am dealing with a complex situation involving two nested Vue JS components. The child component is emitting certain events to the parent function, which I have defined within the parent component declaration. The issue here is that these events are being ...

Monitor the most recent ajax request made by the website

I have a curious question that may seem silly and insignificant, but I am interested in finding out if there is a way to track the last ajax call made on a page. The issue I am facing is that I have developed an application that relies heavily on ajax cal ...

Having trouble with catching errors in try/catch using Async/Await in JavaScript?

I've encountered an issue with the JavaScript code snippet below while using async/await in our ES6 project. I've observed that a 404 response code is not triggering the catch block as expected. Moreover, the .json() method is causing a console e ...

Using Javascript calls with the Ajax WebMethod technique

I've been facing issues running a JavaScript program on my online server. I'm considering another approach: Using Ajax WebMethod with JavaScript calls: <script type="text/javascript"> function gettime(){ var hour = new Date(). ...

Troubleshooting issues with logging out in AngularJS

After attempting to logout of my current session, I realized that the logout feature is not working. Below is the code I have used: view <a ui-sref="logout"> <i class="fa fa-sign-out"></i> Log out </a> config.js $stateProvide ...

I successfully made a GET request using Postman, but encountered an issue when trying to do the same request through a

Currently, my objective is to send URL encoded parameters through a GET request using the fetch function. To achieve this, I am attempting to display the parameters via Express in the following manner: app.get('/api', function (req, res) { c ...

I am encountering an issue where I am using Getserversideprops within a page to retrieve data from Strapi, but I am consistently

Having an issue with fetching data from a Strapi backend using getServerSideProps in Next.js. The data appears to be undefined, even though the link works correctly in the browser. I am fetching inside a page, not a component, following the method descri ...