Search code examples
javascriptzipjszip

loadAsync in JSZip is not waiting to get completed


I am using JSZip library on browser UI and having a "content" which I am passing as body for creating a zip.

var contentDiff: async function(content){
      zip = await JSZip.loadAsync(content, {base64: true});
      return zip.files;
},//other functions below this

Now, I am new but this "zip.files" comes as undefined in a later method call, even after calling await. Kindly suggest what is missing in this js.

I tried different variations of async await and promises, but all in vain.


Solution

  • So, this worked for me. Calling the contentDiff function and using then function. The only hard thing was to rewrite lots of old js lines of code into different function calls and then chaining it under then statement and subsequently in other async then statements. Guess, there is no way, async await will pause/hold code flow in real time when used in synchronous JS processes.

    contentDiff(content).then(function (body){
       //do processing on body here.
    });