Working on a nodejs implementation of JSZip to create a zip file in binary string format and store its value in a global variable however in spite of using async/await the zipstring is being printed before the zipping process is finished,
Here is my code so far:
const JSZip = require("jszip");
const zip = new JSZip();
let s="not yet done";
let zipstring = "";
async function dozipping() {
zip.file("Hello.txt", "Hello World\n");
zip.generateAsync({ type: "binarystring" })
.then(function(content) {
console.log("doing");
zipstring = content;
});
}
async function status() {
console.log(s)
await dozipping();
console.log(zipstring)
s = "done";
console.log(s)
}
status();
Expected Output
not yet done
doing
*zipstring value*
done
Output I am currently getting
not yet done
done
doing
I am new to node and working with jszip for the 1st time and the documentation is a little confusing, sorry in advance if the question is too trivial