How to Create Zip files by using JSZIP library

25 November 2020 | 4 Min Read

JS Zip is an open-source and free library to easily create Zip files without any pain which provides an easy and good API. You can use this library in your app to build easily Zip files. You can use this library when you want your users to download their data, like their images, their videos, their documents, and their other data.


You can download the package by:


With npm : npm install jszip

With bowerbower install Stuk/jszip

With component : component install Stuk/jszip

Manuallydownload JSZip and include the file dist/jszip.js or dist/jszip.min.js


Let’s create an example:


Import JSZIP:


var JSZip = require("jszip");


Create instance: 


var zip = new JSZip();


Basically there are two main functions that make this open-source framework awesome, They are .file(name, content) and .folder(name). These methods return the instance of the functions so you can run the chains on it. Now let’s add a file to it:


zip.file("hello.txt", "Hello[p my)6cxsw2q");


Creating a folder


var photoZip = zip.folder("photos");

photoZip.file("README", "a folder with photos");

The above method will create a foler called photos that will save a file inside photos folder. Here is a example demo: https://jsfiddle.net/c0jmn85o/4/.

More From Web Development

Subscribe to our news letter

Enter your email to get wapgee notification