js 通过 zip.js打开服务器(本地)中的压缩文件

3/3/2017来源:C/C++教程人气:2047

文件目录: 这里写图片描述 index.html

<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> <style> code{ display: block; padding: 10px; background: #eee; } </style> </head> <body> <input type="button" id="button" value="提交"/> </body> <script src="zip.js"></script> <!--先申请fs空间 再调用ext里的函数 两者顺序不能写反--> <script src="zip-fs.js"></script> <script src="zip-ext.js"></script> <script type="text/javascript" src="config.js"></script> <script> document.getElementById("button").onclick = function () { //本地或服务器上的压缩文件夹路径 var URL = "testData.zip"; var zipFs = new zip.fs.FS(); function onerror(message) { console.error(message); } function zipImportedZip(callback) { var directory = zipFs.root.addDirectory("import"); console.log("bbb") directory.importHttpContent(URL, false, function() { zipFs.exportBlob(callback); console.log("ccc"); }, onerror); } function unzipBlob(blob, callback) { zipFs.importBlob(blob, function() { var directory = zipFs.root.getChildByName("import"); var firstEntry = directory.children[0]; firstEntry.getText(callback); var secendEntry = directory.children[1]; console.log(secendEntry); secendEntry.getText(callback); }, onerror); } function logText(text) { console.log(text); console.log("--------------"); } zipImportedZip(function(zippedBlob) { unzipBlob(zippedBlob, function(unzippedText) { logText(unzippedText); }); }); } </script> </html>

zip.js: http://gildas-lormeau.github.io/zip.js/