Sometimes, we want to unzip files with JavaScript.
In this article, we’ll look at how to unzip files with JavaScript.
How to unzip files with JavaScript?
To unzip files with JavaScript, we use the JSZip library.
To install it, we run
npm install jszip
Then we use it by writing
const JSZip = require("jszip");
const zip = new JSZip();
zip.load(file);
zip.files["doc.xml"].asText()
to create the zip
JSZip
object.
Then we call zip.load
to load the file
that we get from the file input.
Next, we get the doc.xml file with zip.files["doc.xml"]
.
And we read it as text with asText
.
Conclusion
To unzip files with JavaScript, we use the JSZip library.