网页端压缩解压缩插件JSZIP库的使用

时间:2021-09-08 02:57:38

  JSZIP这个库支持在网页端生成zip格式的文件,  官方网站是:http://stuk.github.io/jszip/

  因为官方的API发生改变, 最新的DEMO如下:

<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script src="http://stuk.github.io/jszip/dist/jszip.js"></script> <script type="text/javascript" src="http://stuk.github.io/jszip-utils/dist/jszip-utils.js"></script>
<!--[if IE]>
<script type="text/javascript" src="http://stuk.github.io/jszip-utils/dist/jszip-utils-ie.js"></script>
<![endif]-->
<script src="http://stuk.github.io/jszip/test/jquery-1.8.3.min.js"></script>
<script src="http://stuk.github.io/jszip/vendor/FileSaver.js"></script> </head>
<body>
<script>
var imgData = "R0lGODdhBQAFAIACAAAAAP/eACwAAAAABQAFAAACCIwPkWerClIBADs=";
var zip = new JSZip();
zip.file("Hello.txt", "Hello World\n");
var img = zip.folder("images");
img.file("smile.gif", imgData, {base64: true}); zip.generateAsync({type:"blob"}).then(function(content) {
// see FileSaver.js
saveAs(content, "example.zip");
});
</script>
</body>
</html>

作者: NONO
出处:http://www.cnblogs.com/diligenceday/

QQ:287101329