ad

Create ZIP Files in JavaScript With JSZip

zip-box-example

jsZip

Zip file format is very useful while compressing files. It is widely used over the internet for reducing size of a file before uploading or downloading. I have already posted some articles on creating zip files with PHP. In this article, i will show you the way of creating zip files with the help of javascript.
There is a nice javascript api JSZIP which generated zip files. All you need to include this js file in your document.

See the example below in which we are going to add 2 text files into a zip with the help of javascript.
Include this javascript api in your webpage where you want to create a zip file. See the jsZip example code below

<HTML>
<HEAD>
<script type="text/javascript" src="jszip.js"></script>
</HEAD>

<BODY>

<input type="button" onclick="create_zip()" value="Create Zip File"></input>

</BODY>
<SCRIPT>

function create_zip() {
var zip = new JSZip();
zip.add("hello1.txt", "Hello World First file in the zip\n");
zip.add("hello2.txt", "Hello World Second File in the zip\n");
content = zip.generate();
location.href="data:application/zip;base64," + content;
}

</SCRIPT>
</HTML>

Download the API

Tags: |
Nord VPN Sale

Deepanker Verma is the founder of Techlomedia. He is a tech blogger, developer and gadget freak.


Similar Articles

1 Comments

Leave a comment

Comment policy: We love comments and appreciate the time that readers spend to share ideas and give feedback. However, all comments are manually moderated and those deemed to be spam or solely promotional will be deleted.

2020 UseThisTip | Developed By Deepanker