/** * @desc 解压缩文件的类; * @return UnZipArchive 的实例; * */ var UnZipArchive = function( blob ) { if( !blob ) { alert("参数不正确, 需要一个Blob类型的参数"); return ; }; if( !(blob instanceof Blob) ) { alert("参数不是Blob类型"); return ; }; function noop() {}; this.entries = {}; this.zipReader = {}; var _this = this; this.length = 0; this.onend = noop; this.onerror = noop; this.onprogress = noop; //创建一个延迟对象; var def = this.defer = new $.Deferred(); zip.createReader( new zip.BlobReader( blob ), function(zipReader) { _this.zipReader = zipReader; zipReader.getEntries(function(entries) { _this.entries = entries; //继续执行队列; def.resolve(); }); }, this.error.bind(_this) ); }; /** * @desc 把blob文件转化为dataUrl; * */ UnZipArchive.readBlobAsDataURL = function (blob, callback) { var f = new FileReader(); f.onload = function(e) {callback( e.target.result );}; f.readAsDataURL(blob); }; $.extend( UnZipArchive.prototype, { /** * @desc 获取压缩文件的所有入口; * @return ArrayList; * */ "getEntries" : function() { var result = []; for(var i= 0, len = this.entries.length ; i