mirror of
https://github.com/smallmain/cocos-enhance-kit.git
synced 2025-10-09 02:25:22 +00:00
初始化
This commit is contained in:
77
engine/cocos2d/compression/ZipUtils.js
Normal file
77
engine/cocos2d/compression/ZipUtils.js
Normal file
@@ -0,0 +1,77 @@
|
||||
/*--
|
||||
Copyright 2009-2010 by Stefan Rusterholz.
|
||||
All rights reserved.
|
||||
You can choose between MIT and BSD-3-Clause license. License file will be added later.
|
||||
--*/
|
||||
|
||||
var codec = {name:'Jacob__Codec'};
|
||||
|
||||
codec.Base64 = require('./base64');
|
||||
codec.GZip = require('./gzip');
|
||||
|
||||
/**
|
||||
* Unpack a gzipped byte array
|
||||
* @param {Array} input Byte array
|
||||
* @returns {String} Unpacked byte string
|
||||
*/
|
||||
codec.unzip = function () {
|
||||
return codec.GZip.gunzip.apply(codec.GZip, arguments);
|
||||
};
|
||||
|
||||
/**
|
||||
* Unpack a gzipped byte string encoded as base64
|
||||
* @param {String} input Byte string encoded as base64
|
||||
* @returns {String} Unpacked byte string
|
||||
*/
|
||||
codec.unzipBase64 = function () {
|
||||
var buffer = codec.Base64.decode.apply(codec.Base64, arguments);
|
||||
try {
|
||||
return codec.GZip.gunzip.call(codec.GZip, buffer);
|
||||
}
|
||||
catch(e) {
|
||||
// if not zipped, just skip
|
||||
return buffer.slice(7); // get image data
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Unpack a gzipped byte string encoded as base64
|
||||
* @param {String} input Byte string encoded as base64
|
||||
* @param {Number} bytes Bytes per array item
|
||||
* @returns {Array} Unpacked byte array
|
||||
*/
|
||||
codec.unzipBase64AsArray = function (input, bytes) {
|
||||
bytes = bytes || 1;
|
||||
|
||||
var dec = this.unzipBase64(input),
|
||||
ar = [], i, j, len;
|
||||
for (i = 0, len = dec.length / bytes; i < len; i++) {
|
||||
ar[i] = 0;
|
||||
for (j = bytes - 1; j >= 0; --j) {
|
||||
ar[i] += dec.charCodeAt((i * bytes) + j) << (j * 8);
|
||||
}
|
||||
}
|
||||
return ar;
|
||||
};
|
||||
|
||||
/**
|
||||
* Unpack a gzipped byte array
|
||||
* @param {Array} input Byte array
|
||||
* @param {Number} bytes Bytes per array item
|
||||
* @returns {Array} Unpacked byte array
|
||||
*/
|
||||
codec.unzipAsArray = function (input, bytes) {
|
||||
bytes = bytes || 1;
|
||||
|
||||
var dec = this.unzip(input),
|
||||
ar = [], i, j, len;
|
||||
for (i = 0, len = dec.length / bytes; i < len; i++) {
|
||||
ar[i] = 0;
|
||||
for (j = bytes - 1; j >= 0; --j) {
|
||||
ar[i] += dec.charCodeAt((i * bytes) + j) << (j * 8);
|
||||
}
|
||||
}
|
||||
return ar;
|
||||
};
|
||||
|
||||
cc.codec = module.exports = codec;
|
85
engine/cocos2d/compression/base64.js
Normal file
85
engine/cocos2d/compression/base64.js
Normal file
@@ -0,0 +1,85 @@
|
||||
/*--
|
||||
Copyright 2009-2010 by Stefan Rusterholz.
|
||||
All rights reserved.
|
||||
You can choose between MIT and BSD-3-Clause license. License file will be added later.
|
||||
--*/
|
||||
|
||||
var misc = require('../core/utils/misc');
|
||||
var strValue = misc.BASE64_VALUES;
|
||||
|
||||
/**
|
||||
* mixin cc.Codec.Base64
|
||||
*/
|
||||
var Base64 = {name:'Jacob__Codec__Base64'};
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* cc.Codec.Base64.decode(input[, unicode=false]) -> String (http://en.wikipedia.org/wiki/Base64).
|
||||
* </p>
|
||||
* @function
|
||||
* @param {String} input The base64 encoded string to decode
|
||||
* @return {String} Decodes a base64 encoded String
|
||||
* @example
|
||||
* //decode string
|
||||
* cc.Codec.Base64.decode("U29tZSBTdHJpbmc="); // => "Some String"
|
||||
*/
|
||||
Base64.decode = function Jacob__Codec__Base64__decode(input) {
|
||||
var output = [],
|
||||
chr1, chr2, chr3,
|
||||
enc1, enc2, enc3, enc4,
|
||||
i = 0;
|
||||
|
||||
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
|
||||
|
||||
while (i < input.length) {
|
||||
enc1 = strValue[input.charCodeAt(i++)];
|
||||
enc2 = strValue[input.charCodeAt(i++)];
|
||||
enc3 = strValue[input.charCodeAt(i++)];
|
||||
enc4 = strValue[input.charCodeAt(i++)];
|
||||
|
||||
chr1 = (enc1 << 2) | (enc2 >> 4);
|
||||
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
|
||||
chr3 = ((enc3 & 3) << 6) | enc4;
|
||||
|
||||
output.push(String.fromCharCode(chr1));
|
||||
|
||||
if (enc3 !== 64) {
|
||||
output.push(String.fromCharCode(chr2));
|
||||
}
|
||||
if (enc4 !== 64) {
|
||||
output.push(String.fromCharCode(chr3));
|
||||
}
|
||||
}
|
||||
|
||||
output = output.join('');
|
||||
|
||||
return output;
|
||||
};
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Converts an input string encoded in base64 to an array of integers whose<br/>
|
||||
* values represent the decoded string's characters' bytes.
|
||||
* </p>
|
||||
* @function
|
||||
* @param {String} input The String to convert to an array of Integers
|
||||
* @param {Number} bytes
|
||||
* @return {Array}
|
||||
* @example
|
||||
* //decode string to array
|
||||
* var decodeArr = cc.Codec.Base64.decodeAsArray("U29tZSBTdHJpbmc=");
|
||||
*/
|
||||
Base64.decodeAsArray = function Jacob__Codec__Base64___decodeAsArray(input, bytes) {
|
||||
var dec = this.decode(input),
|
||||
ar = [], i, j, len;
|
||||
for (i = 0, len = dec.length / bytes; i < len; i++) {
|
||||
ar[i] = 0;
|
||||
for (j = bytes - 1; j >= 0; --j) {
|
||||
ar[i] += dec.charCodeAt((i * bytes) + j) << (j * 8);
|
||||
}
|
||||
}
|
||||
|
||||
return ar;
|
||||
};
|
||||
|
||||
module.exports = Base64;
|
733
engine/cocos2d/compression/gzip.js
Normal file
733
engine/cocos2d/compression/gzip.js
Normal file
@@ -0,0 +1,733 @@
|
||||
/*--
|
||||
Copyright 2009-2010 by Stefan Rusterholz.
|
||||
All rights reserved.
|
||||
You can choose between MIT and BSD-3-Clause license. License file will be added later.
|
||||
--*/
|
||||
|
||||
/**
|
||||
* See cc.Codec.GZip.gunzip.
|
||||
* @param {Array | String} data The bytestream to decompress
|
||||
* Constructor
|
||||
*/
|
||||
var GZip = function Jacob__GZip(data) {
|
||||
this.data = data;
|
||||
|
||||
this.debug = false;
|
||||
this.gpflags = undefined;
|
||||
this.files = 0;
|
||||
this.unzipped = [];
|
||||
this.buf32k = new Array(32768);
|
||||
this.bIdx = 0;
|
||||
this.modeZIP = false;
|
||||
this.bytepos = 0;
|
||||
this.bb = 1;
|
||||
this.bits = 0;
|
||||
this.nameBuf = [];
|
||||
this.fileout = undefined;
|
||||
this.literalTree = new Array(GZip.LITERALS);
|
||||
this.distanceTree = new Array(32);
|
||||
this.treepos = 0;
|
||||
this.Places = null;
|
||||
this.len = 0;
|
||||
this.fpos = new Array(17);
|
||||
this.fpos[0] = 0;
|
||||
this.flens = undefined;
|
||||
this.fmax = undefined;
|
||||
};
|
||||
|
||||
/**
|
||||
* Unzips the gzipped data of the 'data' argument.
|
||||
* @param string The bytestream to decompress. Either an array of Integers between 0 and 255, or a String.
|
||||
* @return {String}
|
||||
*/
|
||||
GZip.gunzip = function (string) {
|
||||
if (string.constructor === Array) {
|
||||
} else if (string.constructor === String) {
|
||||
}
|
||||
var gzip = new GZip(string);
|
||||
return gzip.gunzip()[0][0];
|
||||
};
|
||||
|
||||
GZip.HufNode = function () {
|
||||
this.b0 = 0;
|
||||
this.b1 = 0;
|
||||
this.jump = null;
|
||||
this.jumppos = -1;
|
||||
};
|
||||
|
||||
/**
|
||||
* @constant
|
||||
* @type Number
|
||||
*/
|
||||
GZip.LITERALS = 288;
|
||||
/**
|
||||
* @constant
|
||||
* @type Number
|
||||
*/
|
||||
GZip.NAMEMAX = 256;
|
||||
|
||||
GZip.bitReverse = [
|
||||
0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,
|
||||
0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0,
|
||||
0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8,
|
||||
0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8,
|
||||
0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4,
|
||||
0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4,
|
||||
0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec,
|
||||
0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc,
|
||||
0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2,
|
||||
0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2,
|
||||
0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea,
|
||||
0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa,
|
||||
0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6,
|
||||
0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6,
|
||||
0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee,
|
||||
0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe,
|
||||
0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1,
|
||||
0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1,
|
||||
0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9,
|
||||
0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9,
|
||||
0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5,
|
||||
0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5,
|
||||
0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed,
|
||||
0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd,
|
||||
0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3,
|
||||
0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3,
|
||||
0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb,
|
||||
0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb,
|
||||
0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7,
|
||||
0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7,
|
||||
0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef,
|
||||
0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff
|
||||
];
|
||||
GZip.cplens = [
|
||||
3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
|
||||
35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0
|
||||
];
|
||||
GZip.cplext = [
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
|
||||
3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 99, 99
|
||||
];
|
||||
/* 99==invalid */
|
||||
GZip.cpdist = [
|
||||
0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0007, 0x0009, 0x000d,
|
||||
0x0011, 0x0019, 0x0021, 0x0031, 0x0041, 0x0061, 0x0081, 0x00c1,
|
||||
0x0101, 0x0181, 0x0201, 0x0301, 0x0401, 0x0601, 0x0801, 0x0c01,
|
||||
0x1001, 0x1801, 0x2001, 0x3001, 0x4001, 0x6001
|
||||
];
|
||||
GZip.cpdext = [
|
||||
0, 0, 0, 0, 1, 1, 2, 2,
|
||||
3, 3, 4, 4, 5, 5, 6, 6,
|
||||
7, 7, 8, 8, 9, 9, 10, 10,
|
||||
11, 11, 12, 12, 13, 13
|
||||
];
|
||||
GZip.border = [16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15];
|
||||
|
||||
|
||||
/**
|
||||
* gunzip
|
||||
* @return {Array}
|
||||
*/
|
||||
GZip.prototype.gunzip = function () {
|
||||
this.outputArr = [];
|
||||
|
||||
//convertToByteArray(input);
|
||||
//if (this.debug) alert(this.data);
|
||||
|
||||
this.nextFile();
|
||||
return this.unzipped;
|
||||
};
|
||||
|
||||
GZip.prototype.readByte = function () {
|
||||
this.bits += 8;
|
||||
if (this.bytepos < this.data.length) {
|
||||
//return this.data[this.bytepos++]; // Array
|
||||
return this.data.charCodeAt(this.bytepos++);
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
};
|
||||
|
||||
GZip.prototype.byteAlign = function () {
|
||||
this.bb = 1;
|
||||
};
|
||||
|
||||
GZip.prototype.readBit = function () {
|
||||
var carry;
|
||||
this.bits++;
|
||||
carry = (this.bb & 1);
|
||||
this.bb >>= 1;
|
||||
if (this.bb === 0) {
|
||||
this.bb = this.readByte();
|
||||
carry = (this.bb & 1);
|
||||
this.bb = (this.bb >> 1) | 0x80;
|
||||
}
|
||||
return carry;
|
||||
};
|
||||
|
||||
GZip.prototype.readBits = function (a) {
|
||||
var res = 0,
|
||||
i = a;
|
||||
|
||||
while (i--) res = (res << 1) | this.readBit();
|
||||
if (a) res = GZip.bitReverse[res] >> (8 - a);
|
||||
|
||||
return res;
|
||||
};
|
||||
|
||||
GZip.prototype.flushBuffer = function () {
|
||||
this.bIdx = 0;
|
||||
};
|
||||
|
||||
GZip.prototype.addBuffer = function (a) {
|
||||
this.buf32k[this.bIdx++] = a;
|
||||
this.outputArr.push(String.fromCharCode(a));
|
||||
if (this.bIdx === 0x8000) this.bIdx = 0;
|
||||
};
|
||||
|
||||
GZip.prototype.IsPat = function () {
|
||||
while (1) {
|
||||
if (this.fpos[this.len] >= this.fmax) return -1;
|
||||
if (this.flens[this.fpos[this.len]] === this.len) return this.fpos[this.len]++;
|
||||
this.fpos[this.len]++;
|
||||
}
|
||||
};
|
||||
|
||||
GZip.prototype.Rec = function () {
|
||||
var curplace = this.Places[this.treepos];
|
||||
var tmp;
|
||||
//if (this.debug) document.write("<br>len:"+this.len+" treepos:"+this.treepos);
|
||||
if (this.len === 17) { //war 17
|
||||
return -1;
|
||||
}
|
||||
this.treepos++;
|
||||
this.len++;
|
||||
|
||||
tmp = this.IsPat();
|
||||
//if (this.debug) document.write("<br>IsPat "+tmp);
|
||||
if (tmp >= 0) {
|
||||
curplace.b0 = tmp;
|
||||
/* leaf cell for 0-bit */
|
||||
//if (this.debug) document.write("<br>b0 "+curplace.b0);
|
||||
} else {
|
||||
/* Not a Leaf cell */
|
||||
curplace.b0 = 0x8000;
|
||||
//if (this.debug) document.write("<br>b0 "+curplace.b0);
|
||||
if (this.Rec()) return -1;
|
||||
}
|
||||
tmp = this.IsPat();
|
||||
if (tmp >= 0) {
|
||||
curplace.b1 = tmp;
|
||||
/* leaf cell for 1-bit */
|
||||
//if (this.debug) document.write("<br>b1 "+curplace.b1);
|
||||
curplace.jump = null;
|
||||
/* Just for the display routine */
|
||||
} else {
|
||||
/* Not a Leaf cell */
|
||||
curplace.b1 = 0x8000;
|
||||
//if (this.debug) document.write("<br>b1 "+curplace.b1);
|
||||
curplace.jump = this.Places[this.treepos];
|
||||
curplace.jumppos = this.treepos;
|
||||
if (this.Rec()) return -1;
|
||||
}
|
||||
this.len--;
|
||||
return 0;
|
||||
};
|
||||
|
||||
GZip.prototype.CreateTree = function (currentTree, numval, lengths, show) {
|
||||
var i;
|
||||
/* Create the Huffman decode tree/table */
|
||||
//if (this.debug) document.write("currentTree "+currentTree+" numval "+numval+" lengths "+lengths+" show "+show);
|
||||
this.Places = currentTree;
|
||||
this.treepos = 0;
|
||||
this.flens = lengths;
|
||||
this.fmax = numval;
|
||||
for (i = 0; i < 17; i++) this.fpos[i] = 0;
|
||||
this.len = 0;
|
||||
if (this.Rec()) {
|
||||
//if (this.debug) alert("invalid huffman tree\n");
|
||||
return -1;
|
||||
}
|
||||
// if (this.debug) {
|
||||
// document.write('<br>Tree: '+this.Places.length);
|
||||
// for (var a=0;a<32;a++){
|
||||
// document.write("Places["+a+"].b0="+this.Places[a].b0+"<br>");
|
||||
// document.write("Places["+a+"].b1="+this.Places[a].b1+"<br>");
|
||||
// }
|
||||
// }
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
GZip.prototype.DecodeValue = function (currentTree) {
|
||||
var len, i,
|
||||
xtreepos = 0,
|
||||
X = currentTree[xtreepos],
|
||||
b;
|
||||
|
||||
/* decode one symbol of the data */
|
||||
while (1) {
|
||||
b = this.readBit();
|
||||
// if (this.debug) document.write("b="+b);
|
||||
if (b) {
|
||||
if (!(X.b1 & 0x8000)) {
|
||||
// if (this.debug) document.write("ret1");
|
||||
return X.b1;
|
||||
/* If leaf node, return data */
|
||||
}
|
||||
X = X.jump;
|
||||
len = currentTree.length;
|
||||
for (i = 0; i < len; i++) {
|
||||
if (currentTree[i] === X) {
|
||||
xtreepos = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!(X.b0 & 0x8000)) {
|
||||
// if (this.debug) document.write("ret2");
|
||||
return X.b0;
|
||||
/* If leaf node, return data */
|
||||
}
|
||||
xtreepos++;
|
||||
X = currentTree[xtreepos];
|
||||
}
|
||||
}
|
||||
// if (this.debug) document.write("ret3");
|
||||
|
||||
return -1;
|
||||
};
|
||||
|
||||
GZip.prototype.DeflateLoop = function () {
|
||||
var last, c, type, i, len;
|
||||
do {
|
||||
last = this.readBit();
|
||||
type = this.readBits(2);
|
||||
|
||||
if (type === 0) {
|
||||
var blockLen, cSum;
|
||||
|
||||
// Stored
|
||||
this.byteAlign();
|
||||
blockLen = this.readByte();
|
||||
blockLen |= (this.readByte() << 8);
|
||||
|
||||
cSum = this.readByte();
|
||||
cSum |= (this.readByte() << 8);
|
||||
|
||||
if (((blockLen ^ ~cSum) & 0xffff)) {
|
||||
document.write("BlockLen checksum mismatch\n"); // FIXME: use throw
|
||||
}
|
||||
while (blockLen--) {
|
||||
c = this.readByte();
|
||||
this.addBuffer(c);
|
||||
}
|
||||
} else if (type === 1) {
|
||||
var j;
|
||||
|
||||
/* Fixed Huffman tables -- fixed decode routine */
|
||||
while (1) {
|
||||
/*
|
||||
256 0000000 0
|
||||
: : :
|
||||
279 0010111 23
|
||||
0 00110000 48
|
||||
: : :
|
||||
143 10111111 191
|
||||
280 11000000 192
|
||||
: : :
|
||||
287 11000111 199
|
||||
144 110010000 400
|
||||
: : :
|
||||
255 111111111 511
|
||||
|
||||
Note the bit order!
|
||||
*/
|
||||
j = (GZip.bitReverse[this.readBits(7)] >> 1);
|
||||
if (j > 23) {
|
||||
j = (j << 1) | this.readBit();
|
||||
/* 48..255 */
|
||||
|
||||
if (j > 199) { /* 200..255 */
|
||||
j -= 128;
|
||||
/* 72..127 */
|
||||
j = (j << 1) | this.readBit();
|
||||
/* 144..255 << */
|
||||
} else { /* 48..199 */
|
||||
j -= 48;
|
||||
/* 0..151 */
|
||||
if (j > 143) {
|
||||
j = j + 136;
|
||||
/* 280..287 << */
|
||||
/* 0..143 << */
|
||||
}
|
||||
}
|
||||
} else { /* 0..23 */
|
||||
j += 256;
|
||||
/* 256..279 << */
|
||||
}
|
||||
if (j < 256) {
|
||||
this.addBuffer(j);
|
||||
} else if (j === 256) {
|
||||
/* EOF */
|
||||
break; // FIXME: make this the loop-condition
|
||||
} else {
|
||||
var len, dist;
|
||||
|
||||
j -= 256 + 1;
|
||||
/* bytes + EOF */
|
||||
len = this.readBits(GZip.cplext[j]) + GZip.cplens[j];
|
||||
|
||||
j = GZip.bitReverse[this.readBits(5)] >> 3;
|
||||
if (GZip.cpdext[j] > 8) {
|
||||
dist = this.readBits(8);
|
||||
dist |= (this.readBits(GZip.cpdext[j] - 8) << 8);
|
||||
} else {
|
||||
dist = this.readBits(GZip.cpdext[j]);
|
||||
}
|
||||
dist += GZip.cpdist[j];
|
||||
|
||||
for (j = 0; j < len; j++) {
|
||||
var c = this.buf32k[(this.bIdx - dist) & 0x7fff];
|
||||
this.addBuffer(c);
|
||||
}
|
||||
}
|
||||
} // while
|
||||
|
||||
} else if (type === 2) {
|
||||
var j, n, literalCodes, distCodes, lenCodes;
|
||||
var ll = new Array(288 + 32); // "static" just to preserve stack
|
||||
|
||||
// Dynamic Huffman tables
|
||||
|
||||
literalCodes = 257 + this.readBits(5);
|
||||
distCodes = 1 + this.readBits(5);
|
||||
lenCodes = 4 + this.readBits(4);
|
||||
for (j = 0; j < 19; j++) {
|
||||
ll[j] = 0;
|
||||
}
|
||||
|
||||
// Get the decode tree code lengths
|
||||
|
||||
for (j = 0; j < lenCodes; j++) {
|
||||
ll[GZip.border[j]] = this.readBits(3);
|
||||
}
|
||||
len = this.distanceTree.length;
|
||||
for (i = 0; i < len; i++) this.distanceTree[i] = new GZip.HufNode();
|
||||
if (this.CreateTree(this.distanceTree, 19, ll, 0)) {
|
||||
this.flushBuffer();
|
||||
return 1;
|
||||
}
|
||||
// if (this.debug) {
|
||||
// document.write("<br>distanceTree");
|
||||
// for(var a=0;a<this.distanceTree.length;a++){
|
||||
// document.write("<br>"+this.distanceTree[a].b0+" "+this.distanceTree[a].b1+" "+this.distanceTree[a].jump+" "+this.distanceTree[a].jumppos);
|
||||
// }
|
||||
// }
|
||||
|
||||
//read in literal and distance code lengths
|
||||
n = literalCodes + distCodes;
|
||||
i = 0;
|
||||
var z = -1;
|
||||
// if (this.debug) document.write("<br>n="+n+" bits: "+this.bits+"<br>");
|
||||
while (i < n) {
|
||||
z++;
|
||||
j = this.DecodeValue(this.distanceTree);
|
||||
// if (this.debug) document.write("<br>"+z+" i:"+i+" decode: "+j+" bits "+this.bits+"<br>");
|
||||
if (j < 16) { // length of code in bits (0..15)
|
||||
ll[i++] = j;
|
||||
} else if (j === 16) { // repeat last length 3 to 6 times
|
||||
var l;
|
||||
j = 3 + this.readBits(2);
|
||||
if (i + j > n) {
|
||||
this.flushBuffer();
|
||||
return 1;
|
||||
}
|
||||
l = i ? ll[i - 1] : 0;
|
||||
while (j--) {
|
||||
ll[i++] = l;
|
||||
}
|
||||
} else {
|
||||
if (j === 17) { // 3 to 10 zero length codes
|
||||
j = 3 + this.readBits(3);
|
||||
} else { // j == 18: 11 to 138 zero length codes
|
||||
j = 11 + this.readBits(7);
|
||||
}
|
||||
if (i + j > n) {
|
||||
this.flushBuffer();
|
||||
return 1;
|
||||
}
|
||||
while (j--) {
|
||||
ll[i++] = 0;
|
||||
}
|
||||
}
|
||||
} // while
|
||||
|
||||
// Can overwrite tree decode tree as it is not used anymore
|
||||
len = this.literalTree.length;
|
||||
for (i = 0; i < len; i++)
|
||||
this.literalTree[i] = new GZip.HufNode();
|
||||
if (this.CreateTree(this.literalTree, literalCodes, ll, 0)) {
|
||||
this.flushBuffer();
|
||||
return 1;
|
||||
}
|
||||
len = this.literalTree.length;
|
||||
for (i = 0; i < len; i++) this.distanceTree[i] = new GZip.HufNode();
|
||||
var ll2 = new Array();
|
||||
for (i = literalCodes; i < ll.length; i++) ll2[i - literalCodes] = ll[i];
|
||||
if (this.CreateTree(this.distanceTree, distCodes, ll2, 0)) {
|
||||
this.flushBuffer();
|
||||
return 1;
|
||||
}
|
||||
// if (this.debug) document.write("<br>literalTree");
|
||||
while (1) {
|
||||
j = this.DecodeValue(this.literalTree);
|
||||
if (j >= 256) { // In C64: if carry set
|
||||
var len, dist;
|
||||
j -= 256;
|
||||
if (j === 0) {
|
||||
// EOF
|
||||
break;
|
||||
}
|
||||
j--;
|
||||
len = this.readBits(GZip.cplext[j]) + GZip.cplens[j];
|
||||
|
||||
j = this.DecodeValue(this.distanceTree);
|
||||
if (GZip.cpdext[j] > 8) {
|
||||
dist = this.readBits(8);
|
||||
dist |= (this.readBits(GZip.cpdext[j] - 8) << 8);
|
||||
} else {
|
||||
dist = this.readBits(GZip.cpdext[j]);
|
||||
}
|
||||
dist += GZip.cpdist[j];
|
||||
while (len--) {
|
||||
var c = this.buf32k[(this.bIdx - dist) & 0x7fff];
|
||||
this.addBuffer(c);
|
||||
}
|
||||
} else {
|
||||
this.addBuffer(j);
|
||||
}
|
||||
} // while
|
||||
}
|
||||
} while (!last);
|
||||
this.flushBuffer();
|
||||
|
||||
this.byteAlign();
|
||||
return 0;
|
||||
};
|
||||
|
||||
GZip.prototype.unzipFile = function (name) {
|
||||
var i;
|
||||
this.gunzip();
|
||||
for (i = 0; i < this.unzipped.length; i++) {
|
||||
if (this.unzipped[i][1] === name) {
|
||||
return this.unzipped[i][0];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
GZip.prototype.nextFile = function () {
|
||||
// if (this.debug) alert("NEXTFILE");
|
||||
|
||||
this.outputArr = [];
|
||||
this.modeZIP = false;
|
||||
|
||||
var tmp = [];
|
||||
tmp[0] = this.readByte();
|
||||
tmp[1] = this.readByte();
|
||||
// if (this.debug) alert("type: "+tmp[0]+" "+tmp[1]);
|
||||
|
||||
if (tmp[0] === 0x78 && tmp[1] === 0xda) { //GZIP
|
||||
// if (this.debug) alert("GEONExT-GZIP");
|
||||
this.DeflateLoop();
|
||||
// if (this.debug) alert(this.outputArr.join(''));
|
||||
this.unzipped[this.files] = [this.outputArr.join(''), "geonext.gxt"];
|
||||
this.files++;
|
||||
}
|
||||
if (tmp[0] === 0x1f && tmp[1] === 0x8b) { //GZIP
|
||||
// if (this.debug) alert("GZIP");
|
||||
this.skipdir();
|
||||
// if (this.debug) alert(this.outputArr.join(''));
|
||||
this.unzipped[this.files] = [this.outputArr.join(''), "file"];
|
||||
this.files++;
|
||||
}
|
||||
if (tmp[0] === 0x50 && tmp[1] === 0x4b) { //ZIP
|
||||
this.modeZIP = true;
|
||||
tmp[2] = this.readByte();
|
||||
tmp[3] = this.readByte();
|
||||
if (tmp[2] === 0x03 && tmp[3] === 0x04) {
|
||||
//MODE_ZIP
|
||||
tmp[0] = this.readByte();
|
||||
tmp[1] = this.readByte();
|
||||
// if (this.debug) alert("ZIP-Version: "+tmp[1]+" "+tmp[0]/10+"."+tmp[0]%10);
|
||||
|
||||
this.gpflags = this.readByte();
|
||||
this.gpflags |= (this.readByte() << 8);
|
||||
// if (this.debug) alert("gpflags: "+this.gpflags);
|
||||
|
||||
var method = this.readByte();
|
||||
method |= (this.readByte() << 8);
|
||||
// if (this.debug) alert("method: "+method);
|
||||
|
||||
this.readByte();
|
||||
this.readByte();
|
||||
this.readByte();
|
||||
this.readByte();
|
||||
|
||||
// var crc = this.readByte();
|
||||
// crc |= (this.readByte()<<8);
|
||||
// crc |= (this.readByte()<<16);
|
||||
// crc |= (this.readByte()<<24);
|
||||
|
||||
var compSize = this.readByte();
|
||||
compSize |= (this.readByte() << 8);
|
||||
compSize |= (this.readByte() << 16);
|
||||
compSize |= (this.readByte() << 24);
|
||||
|
||||
var size = this.readByte();
|
||||
size |= (this.readByte() << 8);
|
||||
size |= (this.readByte() << 16);
|
||||
size |= (this.readByte() << 24);
|
||||
|
||||
// if (this.debug) alert("local CRC: "+crc+"\nlocal Size: "+size+"\nlocal CompSize: "+compSize);
|
||||
|
||||
var filelen = this.readByte();
|
||||
filelen |= (this.readByte() << 8);
|
||||
|
||||
var extralen = this.readByte();
|
||||
extralen |= (this.readByte() << 8);
|
||||
|
||||
// if (this.debug) alert("filelen "+filelen);
|
||||
i = 0;
|
||||
this.nameBuf = [];
|
||||
while (filelen--) {
|
||||
var c = this.readByte();
|
||||
if (c === "/" | c === ":") {
|
||||
i = 0;
|
||||
} else if (i < GZip.NAMEMAX - 1) {
|
||||
this.nameBuf[i++] = String.fromCharCode(c);
|
||||
}
|
||||
}
|
||||
// if (this.debug) alert("nameBuf: "+this.nameBuf);
|
||||
|
||||
if (!this.fileout) this.fileout = this.nameBuf;
|
||||
|
||||
var i = 0;
|
||||
while (i < extralen) {
|
||||
c = this.readByte();
|
||||
i++;
|
||||
}
|
||||
|
||||
// if (size = 0 && this.fileOut.charAt(this.fileout.length-1)=="/"){
|
||||
// //skipdir
|
||||
// // if (this.debug) alert("skipdir");
|
||||
// }
|
||||
if (method === 8) {
|
||||
this.DeflateLoop();
|
||||
// if (this.debug) alert(this.outputArr.join(''));
|
||||
this.unzipped[this.files] = [this.outputArr.join(''), this.nameBuf.join('')];
|
||||
this.files++;
|
||||
}
|
||||
this.skipdir();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
GZip.prototype.skipdir = function () {
|
||||
var tmp = [];
|
||||
var compSize, size, os, i, c;
|
||||
|
||||
if ((this.gpflags & 8)) {
|
||||
tmp[0] = this.readByte();
|
||||
tmp[1] = this.readByte();
|
||||
tmp[2] = this.readByte();
|
||||
tmp[3] = this.readByte();
|
||||
|
||||
// if (tmp[0] == 0x50 && tmp[1] == 0x4b && tmp[2] == 0x07 && tmp[3] == 0x08) {
|
||||
// crc = this.readByte();
|
||||
// crc |= (this.readByte()<<8);
|
||||
// crc |= (this.readByte()<<16);
|
||||
// crc |= (this.readByte()<<24);
|
||||
// } else {
|
||||
// crc = tmp[0] | (tmp[1]<<8) | (tmp[2]<<16) | (tmp[3]<<24);
|
||||
// }
|
||||
|
||||
compSize = this.readByte();
|
||||
compSize |= (this.readByte() << 8);
|
||||
compSize |= (this.readByte() << 16);
|
||||
compSize |= (this.readByte() << 24);
|
||||
|
||||
size = this.readByte();
|
||||
size |= (this.readByte() << 8);
|
||||
size |= (this.readByte() << 16);
|
||||
size |= (this.readByte() << 24);
|
||||
}
|
||||
|
||||
if (this.modeZIP) this.nextFile();
|
||||
|
||||
tmp[0] = this.readByte();
|
||||
if (tmp[0] !== 8) {
|
||||
// if (this.debug) alert("Unknown compression method!");
|
||||
return 0;
|
||||
}
|
||||
|
||||
this.gpflags = this.readByte();
|
||||
// if (this.debug && (this.gpflags & ~(0x1f))) alert("Unknown flags set!");
|
||||
|
||||
this.readByte();
|
||||
this.readByte();
|
||||
this.readByte();
|
||||
this.readByte();
|
||||
|
||||
this.readByte();
|
||||
os = this.readByte();
|
||||
|
||||
if ((this.gpflags & 4)) {
|
||||
tmp[0] = this.readByte();
|
||||
tmp[2] = this.readByte();
|
||||
this.len = tmp[0] + 256 * tmp[1];
|
||||
// if (this.debug) alert("Extra field size: "+this.len);
|
||||
for (i = 0; i < this.len; i++)
|
||||
this.readByte();
|
||||
}
|
||||
|
||||
if ((this.gpflags & 8)) {
|
||||
i = 0;
|
||||
this.nameBuf = [];
|
||||
while (c = this.readByte()) {
|
||||
if (c === "7" || c === ":")
|
||||
i = 0;
|
||||
if (i < GZip.NAMEMAX - 1)
|
||||
this.nameBuf[i++] = c;
|
||||
}
|
||||
//this.nameBuf[i] = "\0";
|
||||
// if (this.debug) alert("original file name: "+this.nameBuf);
|
||||
}
|
||||
|
||||
if ((this.gpflags & 16)) {
|
||||
while (c = this.readByte()) { // FIXME: looks like they read to the end of the stream, should be doable more efficiently
|
||||
//FILE COMMENT
|
||||
}
|
||||
}
|
||||
|
||||
if ((this.gpflags & 2)) {
|
||||
this.readByte();
|
||||
this.readByte();
|
||||
}
|
||||
|
||||
this.DeflateLoop();
|
||||
|
||||
// crc = this.readByte();
|
||||
// crc |= (this.readByte()<<8);
|
||||
// crc |= (this.readByte()<<16);
|
||||
// crc |= (this.readByte()<<24);
|
||||
|
||||
size = this.readByte();
|
||||
size |= (this.readByte() << 8);
|
||||
size |= (this.readByte() << 16);
|
||||
size |= (this.readByte() << 24);
|
||||
|
||||
if (this.modeZIP) this.nextFile();
|
||||
};
|
||||
|
||||
module.exports = GZip;
|
55
engine/cocos2d/compression/zlib.min.js
vendored
Normal file
55
engine/cocos2d/compression/zlib.min.js
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
/** @license zlib.js 2012 - imaya [ https://github.com/imaya/zlib.js ] The MIT License */
|
||||
(function() {'use strict';function i(a){throw a;}var r=void 0,v=!0,aa=this;function y(a,c){var b=a.split("."),e=aa;!(b[0]in e)&&e.execScript&&e.execScript("var "+b[0]);for(var f;b.length&&(f=b.shift());)!b.length&&c!==r?e[f]=c:e=e[f]?e[f]:e[f]={}};var H="undefined"!==typeof Uint8Array&&"undefined"!==typeof Uint16Array&&"undefined"!==typeof Uint32Array;function ba(a){if("string"===typeof a){var c=a.split(""),b,e;b=0;for(e=c.length;b<e;b++)c[b]=(c[b].charCodeAt(0)&255)>>>0;a=c}for(var f=1,d=0,g=a.length,h,m=0;0<g;){h=1024<g?1024:g;g-=h;do f+=a[m++],d+=f;while(--h);f%=65521;d%=65521}return(d<<16|f)>>>0};function J(a,c){this.index="number"===typeof c?c:0;this.i=0;this.buffer=a instanceof(H?Uint8Array:Array)?a:new (H?Uint8Array:Array)(32768);2*this.buffer.length<=this.index&&i(Error("invalid index"));this.buffer.length<=this.index&&this.f()}J.prototype.f=function(){var a=this.buffer,c,b=a.length,e=new (H?Uint8Array:Array)(b<<1);if(H)e.set(a);else for(c=0;c<b;++c)e[c]=a[c];return this.buffer=e};
|
||||
J.prototype.d=function(a,c,b){var e=this.buffer,f=this.index,d=this.i,g=e[f],h;b&&1<c&&(a=8<c?(N[a&255]<<24|N[a>>>8&255]<<16|N[a>>>16&255]<<8|N[a>>>24&255])>>32-c:N[a]>>8-c);if(8>c+d)g=g<<c|a,d+=c;else for(h=0;h<c;++h)g=g<<1|a>>c-h-1&1,8===++d&&(d=0,e[f++]=N[g],g=0,f===e.length&&(e=this.f()));e[f]=g;this.buffer=e;this.i=d;this.index=f};J.prototype.finish=function(){var a=this.buffer,c=this.index,b;0<this.i&&(a[c]<<=8-this.i,a[c]=N[a[c]],c++);H?b=a.subarray(0,c):(a.length=c,b=a);return b};
|
||||
var ca=new (H?Uint8Array:Array)(256),ha;for(ha=0;256>ha;++ha){for(var R=ha,ia=R,ja=7,R=R>>>1;R;R>>>=1)ia<<=1,ia|=R&1,--ja;ca[ha]=(ia<<ja&255)>>>0}var N=ca;var ka=[0,1996959894,3993919788,2567524794,124634137,1886057615,3915621685,2657392035,249268274,2044508324,3772115230,2547177864,162941995,2125561021,3887607047,2428444049,498536548,1789927666,4089016648,2227061214,450548861,1843258603,4107580753,2211677639,325883990,1684777152,4251122042,2321926636,335633487,1661365465,4195302755,2366115317,997073096,1281953886,3579855332,2724688242,1006888145,1258607687,3524101629,2768942443,901097722,1119000684,3686517206,2898065728,853044451,1172266101,3705015759,
|
||||
2882616665,651767980,1373503546,3369554304,3218104598,565507253,1454621731,3485111705,3099436303,671266974,1594198024,3322730930,2970347812,795835527,1483230225,3244367275,3060149565,1994146192,31158534,2563907772,4023717930,1907459465,112637215,2680153253,3904427059,2013776290,251722036,2517215374,3775830040,2137656763,141376813,2439277719,3865271297,1802195444,476864866,2238001368,4066508878,1812370925,453092731,2181625025,4111451223,1706088902,314042704,2344532202,4240017532,1658658271,366619977,
|
||||
2362670323,4224994405,1303535960,984961486,2747007092,3569037538,1256170817,1037604311,2765210733,3554079995,1131014506,879679996,2909243462,3663771856,1141124467,855842277,2852801631,3708648649,1342533948,654459306,3188396048,3373015174,1466479909,544179635,3110523913,3462522015,1591671054,702138776,2966460450,3352799412,1504918807,783551873,3082640443,3233442989,3988292384,2596254646,62317068,1957810842,3939845945,2647816111,81470997,1943803523,3814918930,2489596804,225274430,2053790376,3826175755,
|
||||
2466906013,167816743,2097651377,4027552580,2265490386,503444072,1762050814,4150417245,2154129355,426522225,1852507879,4275313526,2312317920,282753626,1742555852,4189708143,2394877945,397917763,1622183637,3604390888,2714866558,953729732,1340076626,3518719985,2797360999,1068828381,1219638859,3624741850,2936675148,906185462,1090812512,3747672003,2825379669,829329135,1181335161,3412177804,3160834842,628085408,1382605366,3423369109,3138078467,570562233,1426400815,3317316542,2998733608,733239954,1555261956,
|
||||
3268935591,3050360625,752459403,1541320221,2607071920,3965973030,1969922972,40735498,2617837225,3943577151,1913087877,83908371,2512341634,3803740692,2075208622,213261112,2463272603,3855990285,2094854071,198958881,2262029012,4057260610,1759359992,534414190,2176718541,4139329115,1873836001,414664567,2282248934,4279200368,1711684554,285281116,2405801727,4167216745,1634467795,376229701,2685067896,3608007406,1308918612,956543938,2808555105,3495958263,1231636301,1047427035,2932959818,3654703836,1088359270,
|
||||
936918E3,2847714899,3736837829,1202900863,817233897,3183342108,3401237130,1404277552,615818150,3134207493,3453421203,1423857449,601450431,3009837614,3294710456,1567103746,711928724,3020668471,3272380065,1510334235,755167117];H&&new Uint32Array(ka);function la(a){this.buffer=new (H?Uint16Array:Array)(2*a);this.length=0}la.prototype.getParent=function(a){return 2*((a-2)/4|0)};la.prototype.push=function(a,c){var b,e,f=this.buffer,d;b=this.length;f[this.length++]=c;for(f[this.length++]=a;0<b;)if(e=this.getParent(b),f[b]>f[e])d=f[b],f[b]=f[e],f[e]=d,d=f[b+1],f[b+1]=f[e+1],f[e+1]=d,b=e;else break;return this.length};
|
||||
la.prototype.pop=function(){var a,c,b=this.buffer,e,f,d;c=b[0];a=b[1];this.length-=2;b[0]=b[this.length];b[1]=b[this.length+1];for(d=0;;){f=2*d+2;if(f>=this.length)break;f+2<this.length&&b[f+2]>b[f]&&(f+=2);if(b[f]>b[d])e=b[d],b[d]=b[f],b[f]=e,e=b[d+1],b[d+1]=b[f+1],b[f+1]=e;else break;d=f}return{index:a,value:c,length:this.length}};function S(a){var c=a.length,b=0,e=Number.POSITIVE_INFINITY,f,d,g,h,m,j,s,n,l;for(n=0;n<c;++n)a[n]>b&&(b=a[n]),a[n]<e&&(e=a[n]);f=1<<b;d=new (H?Uint32Array:Array)(f);g=1;h=0;for(m=2;g<=b;){for(n=0;n<c;++n)if(a[n]===g){j=0;s=h;for(l=0;l<g;++l)j=j<<1|s&1,s>>=1;for(l=j;l<f;l+=m)d[l]=g<<16|n;++h}++g;h<<=1;m<<=1}return[d,b,e]};function ma(a,c){this.h=pa;this.w=0;this.input=a;this.b=0;c&&(c.lazy&&(this.w=c.lazy),"number"===typeof c.compressionType&&(this.h=c.compressionType),c.outputBuffer&&(this.a=H&&c.outputBuffer instanceof Array?new Uint8Array(c.outputBuffer):c.outputBuffer),"number"===typeof c.outputIndex&&(this.b=c.outputIndex));this.a||(this.a=new (H?Uint8Array:Array)(32768))}var pa=2,qa={NONE:0,r:1,j:pa,N:3},ra=[],T;
|
||||
for(T=0;288>T;T++)switch(v){case 143>=T:ra.push([T+48,8]);break;case 255>=T:ra.push([T-144+400,9]);break;case 279>=T:ra.push([T-256+0,7]);break;case 287>=T:ra.push([T-280+192,8]);break;default:i("invalid literal: "+T)}
|
||||
ma.prototype.n=function(){var a,c,b,e,f=this.input;switch(this.h){case 0:b=0;for(e=f.length;b<e;){c=H?f.subarray(b,b+65535):f.slice(b,b+65535);b+=c.length;var d=c,g=b===e,h=r,m=r,j=r,s=r,n=r,l=this.a,q=this.b;if(H){for(l=new Uint8Array(this.a.buffer);l.length<=q+d.length+5;)l=new Uint8Array(l.length<<1);l.set(this.a)}h=g?1:0;l[q++]=h|0;m=d.length;j=~m+65536&65535;l[q++]=m&255;l[q++]=m>>>8&255;l[q++]=j&255;l[q++]=j>>>8&255;if(H)l.set(d,q),q+=d.length,l=l.subarray(0,q);else{s=0;for(n=d.length;s<n;++s)l[q++]=
|
||||
d[s];l.length=q}this.b=q;this.a=l}break;case 1:var E=new J(new Uint8Array(this.a.buffer),this.b);E.d(1,1,v);E.d(1,2,v);var t=sa(this,f),z,K,A;z=0;for(K=t.length;z<K;z++)if(A=t[z],J.prototype.d.apply(E,ra[A]),256<A)E.d(t[++z],t[++z],v),E.d(t[++z],5),E.d(t[++z],t[++z],v);else if(256===A)break;this.a=E.finish();this.b=this.a.length;break;case pa:var x=new J(new Uint8Array(this.a),this.b),B,k,p,D,C,da=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],W,Ma,ea,Na,na,va=Array(19),Oa,$,oa,F,Pa;B=pa;x.d(1,
|
||||
1,v);x.d(B,2,v);k=sa(this,f);W=ta(this.L,15);Ma=ua(W);ea=ta(this.K,7);Na=ua(ea);for(p=286;257<p&&0===W[p-1];p--);for(D=30;1<D&&0===ea[D-1];D--);var Qa=p,Ra=D,M=new (H?Uint32Array:Array)(Qa+Ra),u,O,w,fa,L=new (H?Uint32Array:Array)(316),I,G,P=new (H?Uint8Array:Array)(19);for(u=O=0;u<Qa;u++)M[O++]=W[u];for(u=0;u<Ra;u++)M[O++]=ea[u];if(!H){u=0;for(fa=P.length;u<fa;++u)P[u]=0}u=I=0;for(fa=M.length;u<fa;u+=O){for(O=1;u+O<fa&&M[u+O]===M[u];++O);w=O;if(0===M[u])if(3>w)for(;0<w--;)L[I++]=0,P[0]++;else for(;0<
|
||||
w;)G=138>w?w:138,G>w-3&&G<w&&(G=w-3),10>=G?(L[I++]=17,L[I++]=G-3,P[17]++):(L[I++]=18,L[I++]=G-11,P[18]++),w-=G;else if(L[I++]=M[u],P[M[u]]++,w--,3>w)for(;0<w--;)L[I++]=M[u],P[M[u]]++;else for(;0<w;)G=6>w?w:6,G>w-3&&G<w&&(G=w-3),L[I++]=16,L[I++]=G-3,P[16]++,w-=G}a=H?L.subarray(0,I):L.slice(0,I);na=ta(P,7);for(F=0;19>F;F++)va[F]=na[da[F]];for(C=19;4<C&&0===va[C-1];C--);Oa=ua(na);x.d(p-257,5,v);x.d(D-1,5,v);x.d(C-4,4,v);for(F=0;F<C;F++)x.d(va[F],3,v);F=0;for(Pa=a.length;F<Pa;F++)if($=a[F],x.d(Oa[$],
|
||||
na[$],v),16<=$){F++;switch($){case 16:oa=2;break;case 17:oa=3;break;case 18:oa=7;break;default:i("invalid code: "+$)}x.d(a[F],oa,v)}var Sa=[Ma,W],Ta=[Na,ea],Q,Ua,ga,ya,Va,Wa,Xa,Ya;Va=Sa[0];Wa=Sa[1];Xa=Ta[0];Ya=Ta[1];Q=0;for(Ua=k.length;Q<Ua;++Q)if(ga=k[Q],x.d(Va[ga],Wa[ga],v),256<ga)x.d(k[++Q],k[++Q],v),ya=k[++Q],x.d(Xa[ya],Ya[ya],v),x.d(k[++Q],k[++Q],v);else if(256===ga)break;this.a=x.finish();this.b=this.a.length;break;default:i("invalid compression type")}return this.a};
|
||||
function wa(a,c){this.length=a;this.G=c}
|
||||
function xa(){var a=za;switch(v){case 3===a:return[257,a-3,0];case 4===a:return[258,a-4,0];case 5===a:return[259,a-5,0];case 6===a:return[260,a-6,0];case 7===a:return[261,a-7,0];case 8===a:return[262,a-8,0];case 9===a:return[263,a-9,0];case 10===a:return[264,a-10,0];case 12>=a:return[265,a-11,1];case 14>=a:return[266,a-13,1];case 16>=a:return[267,a-15,1];case 18>=a:return[268,a-17,1];case 22>=a:return[269,a-19,2];case 26>=a:return[270,a-23,2];case 30>=a:return[271,a-27,2];case 34>=a:return[272,a-
|
||||
31,2];case 42>=a:return[273,a-35,3];case 50>=a:return[274,a-43,3];case 58>=a:return[275,a-51,3];case 66>=a:return[276,a-59,3];case 82>=a:return[277,a-67,4];case 98>=a:return[278,a-83,4];case 114>=a:return[279,a-99,4];case 130>=a:return[280,a-115,4];case 162>=a:return[281,a-131,5];case 194>=a:return[282,a-163,5];case 226>=a:return[283,a-195,5];case 257>=a:return[284,a-227,5];case 258===a:return[285,a-258,0];default:i("invalid length: "+a)}}var Aa=[],za,Ba;
|
||||
for(za=3;258>=za;za++)Ba=xa(),Aa[za]=Ba[2]<<24|Ba[1]<<16|Ba[0];var Ca=H?new Uint32Array(Aa):Aa;
|
||||
function sa(a,c){function b(a,c){var b=a.G,d=[],e=0,f;f=Ca[a.length];d[e++]=f&65535;d[e++]=f>>16&255;d[e++]=f>>24;var g;switch(v){case 1===b:g=[0,b-1,0];break;case 2===b:g=[1,b-2,0];break;case 3===b:g=[2,b-3,0];break;case 4===b:g=[3,b-4,0];break;case 6>=b:g=[4,b-5,1];break;case 8>=b:g=[5,b-7,1];break;case 12>=b:g=[6,b-9,2];break;case 16>=b:g=[7,b-13,2];break;case 24>=b:g=[8,b-17,3];break;case 32>=b:g=[9,b-25,3];break;case 48>=b:g=[10,b-33,4];break;case 64>=b:g=[11,b-49,4];break;case 96>=b:g=[12,b-
|
||||
65,5];break;case 128>=b:g=[13,b-97,5];break;case 192>=b:g=[14,b-129,6];break;case 256>=b:g=[15,b-193,6];break;case 384>=b:g=[16,b-257,7];break;case 512>=b:g=[17,b-385,7];break;case 768>=b:g=[18,b-513,8];break;case 1024>=b:g=[19,b-769,8];break;case 1536>=b:g=[20,b-1025,9];break;case 2048>=b:g=[21,b-1537,9];break;case 3072>=b:g=[22,b-2049,10];break;case 4096>=b:g=[23,b-3073,10];break;case 6144>=b:g=[24,b-4097,11];break;case 8192>=b:g=[25,b-6145,11];break;case 12288>=b:g=[26,b-8193,12];break;case 16384>=
|
||||
b:g=[27,b-12289,12];break;case 24576>=b:g=[28,b-16385,13];break;case 32768>=b:g=[29,b-24577,13];break;default:i("invalid distance")}f=g;d[e++]=f[0];d[e++]=f[1];d[e++]=f[2];var h,j;h=0;for(j=d.length;h<j;++h)l[q++]=d[h];t[d[0]]++;z[d[3]]++;E=a.length+c-1;n=null}var e,f,d,g,h,m={},j,s,n,l=H?new Uint16Array(2*c.length):[],q=0,E=0,t=new (H?Uint32Array:Array)(286),z=new (H?Uint32Array:Array)(30),K=a.w,A;if(!H){for(d=0;285>=d;)t[d++]=0;for(d=0;29>=d;)z[d++]=0}t[256]=1;e=0;for(f=c.length;e<f;++e){d=h=0;
|
||||
for(g=3;d<g&&e+d!==f;++d)h=h<<8|c[e+d];m[h]===r&&(m[h]=[]);j=m[h];if(!(0<E--)){for(;0<j.length&&32768<e-j[0];)j.shift();if(e+3>=f){n&&b(n,-1);d=0;for(g=f-e;d<g;++d)A=c[e+d],l[q++]=A,++t[A];break}if(0<j.length){var x=r,B=r,k=0,p=r,D=r,C=r,da=r,W=c.length,D=0,da=j.length;a:for(;D<da;D++){x=j[da-D-1];p=3;if(3<k){for(C=k;3<C;C--)if(c[x+C-1]!==c[e+C-1])continue a;p=k}for(;258>p&&e+p<W&&c[x+p]===c[e+p];)++p;p>k&&(B=x,k=p);if(258===p)break}s=new wa(k,e-B);n?n.length<s.length?(A=c[e-1],l[q++]=A,++t[A],b(s,
|
||||
0)):b(n,-1):s.length<K?n=s:b(s,0)}else n?b(n,-1):(A=c[e],l[q++]=A,++t[A])}j.push(e)}l[q++]=256;t[256]++;a.L=t;a.K=z;return H?l.subarray(0,q):l}
|
||||
function ta(a,c){function b(a){var c=z[a][K[a]];c===n?(b(a+1),b(a+1)):--E[c];++K[a]}var e=a.length,f=new la(572),d=new (H?Uint8Array:Array)(e),g,h,m,j,s;if(!H)for(j=0;j<e;j++)d[j]=0;for(j=0;j<e;++j)0<a[j]&&f.push(j,a[j]);g=Array(f.length/2);h=new (H?Uint32Array:Array)(f.length/2);if(1===g.length)return d[f.pop().index]=1,d;j=0;for(s=f.length/2;j<s;++j)g[j]=f.pop(),h[j]=g[j].value;var n=h.length,l=new (H?Uint16Array:Array)(c),q=new (H?Uint8Array:Array)(c),E=new (H?Uint8Array:Array)(n),t=Array(c),z=
|
||||
Array(c),K=Array(c),A=(1<<c)-n,x=1<<c-1,B,k,p,D,C;l[c-1]=n;for(k=0;k<c;++k)A<x?q[k]=0:(q[k]=1,A-=x),A<<=1,l[c-2-k]=(l[c-1-k]/2|0)+n;l[0]=q[0];t[0]=Array(l[0]);z[0]=Array(l[0]);for(k=1;k<c;++k)l[k]>2*l[k-1]+q[k]&&(l[k]=2*l[k-1]+q[k]),t[k]=Array(l[k]),z[k]=Array(l[k]);for(B=0;B<n;++B)E[B]=c;for(p=0;p<l[c-1];++p)t[c-1][p]=h[p],z[c-1][p]=p;for(B=0;B<c;++B)K[B]=0;1===q[c-1]&&(--E[0],++K[c-1]);for(k=c-2;0<=k;--k){D=B=0;C=K[k+1];for(p=0;p<l[k];p++)D=t[k+1][C]+t[k+1][C+1],D>h[B]?(t[k][p]=D,z[k][p]=n,C+=2):
|
||||
(t[k][p]=h[B],z[k][p]=B,++B);K[k]=0;1===q[k]&&b(k)}m=E;j=0;for(s=g.length;j<s;++j)d[g[j].index]=m[j];return d}function ua(a){var c=new (H?Uint16Array:Array)(a.length),b=[],e=[],f=0,d,g,h,m;d=0;for(g=a.length;d<g;d++)b[a[d]]=(b[a[d]]|0)+1;d=1;for(g=16;d<=g;d++)e[d]=f,f+=b[d]|0,f>1<<d&&i("overcommitted"),f<<=1;65536>f&&i("undercommitted");d=0;for(g=a.length;d<g;d++){f=e[a[d]];e[a[d]]+=1;h=c[d]=0;for(m=a[d];h<m;h++)c[d]=c[d]<<1|f&1,f>>>=1}return c};function Da(a,c){this.input=a;this.a=new (H?Uint8Array:Array)(32768);this.h=U.j;var b={},e;if((c||!(c={}))&&"number"===typeof c.compressionType)this.h=c.compressionType;for(e in c)b[e]=c[e];b.outputBuffer=this.a;this.z=new ma(this.input,b)}var U=qa;
|
||||
Da.prototype.n=function(){var a,c,b,e,f,d,g,h=0;g=this.a;a=Ea;switch(a){case Ea:c=Math.LOG2E*Math.log(32768)-8;break;default:i(Error("invalid compression method"))}b=c<<4|a;g[h++]=b;switch(a){case Ea:switch(this.h){case U.NONE:f=0;break;case U.r:f=1;break;case U.j:f=2;break;default:i(Error("unsupported compression type"))}break;default:i(Error("invalid compression method"))}e=f<<6|0;g[h++]=e|31-(256*b+e)%31;d=ba(this.input);this.z.b=h;g=this.z.n();h=g.length;H&&(g=new Uint8Array(g.buffer),g.length<=
|
||||
h+4&&(this.a=new Uint8Array(g.length+4),this.a.set(g),g=this.a),g=g.subarray(0,h+4));g[h++]=d>>24&255;g[h++]=d>>16&255;g[h++]=d>>8&255;g[h++]=d&255;return g};y("Zlib.Deflate",Da);y("Zlib.Deflate.compress",function(a,c){return(new Da(a,c)).n()});y("Zlib.Deflate.CompressionType",U);y("Zlib.Deflate.CompressionType.NONE",U.NONE);y("Zlib.Deflate.CompressionType.FIXED",U.r);y("Zlib.Deflate.CompressionType.DYNAMIC",U.j);function V(a,c){this.k=[];this.l=32768;this.e=this.g=this.c=this.q=0;this.input=H?new Uint8Array(a):a;this.s=!1;this.m=Fa;this.B=!1;if(c||!(c={}))c.index&&(this.c=c.index),c.bufferSize&&(this.l=c.bufferSize),c.bufferType&&(this.m=c.bufferType),c.resize&&(this.B=c.resize);switch(this.m){case Ga:this.b=32768;this.a=new (H?Uint8Array:Array)(32768+this.l+258);break;case Fa:this.b=0;this.a=new (H?Uint8Array:Array)(this.l);this.f=this.J;this.t=this.H;this.o=this.I;break;default:i(Error("invalid inflate mode"))}}
|
||||
var Ga=0,Fa=1,Ha={D:Ga,C:Fa};
|
||||
V.prototype.p=function(){for(;!this.s;){var a=X(this,3);a&1&&(this.s=v);a>>>=1;switch(a){case 0:var c=this.input,b=this.c,e=this.a,f=this.b,d=r,g=r,h=r,m=e.length,j=r;this.e=this.g=0;d=c[b++];d===r&&i(Error("invalid uncompressed block header: LEN (first byte)"));g=d;d=c[b++];d===r&&i(Error("invalid uncompressed block header: LEN (second byte)"));g|=d<<8;d=c[b++];d===r&&i(Error("invalid uncompressed block header: NLEN (first byte)"));h=d;d=c[b++];d===r&&i(Error("invalid uncompressed block header: NLEN (second byte)"));h|=
|
||||
d<<8;g===~h&&i(Error("invalid uncompressed block header: length verify"));b+g>c.length&&i(Error("input buffer is broken"));switch(this.m){case Ga:for(;f+g>e.length;){j=m-f;g-=j;if(H)e.set(c.subarray(b,b+j),f),f+=j,b+=j;else for(;j--;)e[f++]=c[b++];this.b=f;e=this.f();f=this.b}break;case Fa:for(;f+g>e.length;)e=this.f({v:2});break;default:i(Error("invalid inflate mode"))}if(H)e.set(c.subarray(b,b+g),f),f+=g,b+=g;else for(;g--;)e[f++]=c[b++];this.c=b;this.b=f;this.a=e;break;case 1:this.o(Ia,Ja);break;
|
||||
case 2:Ka(this);break;default:i(Error("unknown BTYPE: "+a))}}return this.t()};
|
||||
var La=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],Za=H?new Uint16Array(La):La,$a=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,258,258],ab=H?new Uint16Array($a):$a,bb=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0],cb=H?new Uint8Array(bb):bb,db=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577],eb=H?new Uint16Array(db):db,fb=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,
|
||||
10,11,11,12,12,13,13],gb=H?new Uint8Array(fb):fb,hb=new (H?Uint8Array:Array)(288),Y,ib;Y=0;for(ib=hb.length;Y<ib;++Y)hb[Y]=143>=Y?8:255>=Y?9:279>=Y?7:8;var Ia=S(hb),jb=new (H?Uint8Array:Array)(30),kb,lb;kb=0;for(lb=jb.length;kb<lb;++kb)jb[kb]=5;var Ja=S(jb);function X(a,c){for(var b=a.g,e=a.e,f=a.input,d=a.c,g;e<c;)g=f[d++],g===r&&i(Error("input buffer is broken")),b|=g<<e,e+=8;g=b&(1<<c)-1;a.g=b>>>c;a.e=e-c;a.c=d;return g}
|
||||
function mb(a,c){for(var b=a.g,e=a.e,f=a.input,d=a.c,g=c[0],h=c[1],m,j,s;e<h;)m=f[d++],m===r&&i(Error("input buffer is broken")),b|=m<<e,e+=8;j=g[b&(1<<h)-1];s=j>>>16;a.g=b>>s;a.e=e-s;a.c=d;return j&65535}
|
||||
function Ka(a){function c(a,b,c){var d,e,f,g;for(g=0;g<a;)switch(d=mb(this,b),d){case 16:for(f=3+X(this,2);f--;)c[g++]=e;break;case 17:for(f=3+X(this,3);f--;)c[g++]=0;e=0;break;case 18:for(f=11+X(this,7);f--;)c[g++]=0;e=0;break;default:e=c[g++]=d}return c}var b=X(a,5)+257,e=X(a,5)+1,f=X(a,4)+4,d=new (H?Uint8Array:Array)(Za.length),g,h,m,j;for(j=0;j<f;++j)d[Za[j]]=X(a,3);g=S(d);h=new (H?Uint8Array:Array)(b);m=new (H?Uint8Array:Array)(e);a.o(S(c.call(a,b,g,h)),S(c.call(a,e,g,m)))}
|
||||
V.prototype.o=function(a,c){var b=this.a,e=this.b;this.u=a;for(var f=b.length-258,d,g,h,m;256!==(d=mb(this,a));)if(256>d)e>=f&&(this.b=e,b=this.f(),e=this.b),b[e++]=d;else{g=d-257;m=ab[g];0<cb[g]&&(m+=X(this,cb[g]));d=mb(this,c);h=eb[d];0<gb[d]&&(h+=X(this,gb[d]));e>=f&&(this.b=e,b=this.f(),e=this.b);for(;m--;)b[e]=b[e++-h]}for(;8<=this.e;)this.e-=8,this.c--;this.b=e};
|
||||
V.prototype.I=function(a,c){var b=this.a,e=this.b;this.u=a;for(var f=b.length,d,g,h,m;256!==(d=mb(this,a));)if(256>d)e>=f&&(b=this.f(),f=b.length),b[e++]=d;else{g=d-257;m=ab[g];0<cb[g]&&(m+=X(this,cb[g]));d=mb(this,c);h=eb[d];0<gb[d]&&(h+=X(this,gb[d]));e+m>f&&(b=this.f(),f=b.length);for(;m--;)b[e]=b[e++-h]}for(;8<=this.e;)this.e-=8,this.c--;this.b=e};
|
||||
V.prototype.f=function(){var a=new (H?Uint8Array:Array)(this.b-32768),c=this.b-32768,b,e,f=this.a;if(H)a.set(f.subarray(32768,a.length));else{b=0;for(e=a.length;b<e;++b)a[b]=f[b+32768]}this.k.push(a);this.q+=a.length;if(H)f.set(f.subarray(c,c+32768));else for(b=0;32768>b;++b)f[b]=f[c+b];this.b=32768;return f};
|
||||
V.prototype.J=function(a){var c,b=this.input.length/this.c+1|0,e,f,d,g=this.input,h=this.a;a&&("number"===typeof a.v&&(b=a.v),"number"===typeof a.F&&(b+=a.F));2>b?(e=(g.length-this.c)/this.u[2],d=258*(e/2)|0,f=d<h.length?h.length+d:h.length<<1):f=h.length*b;H?(c=new Uint8Array(f),c.set(h)):c=h;return this.a=c};
|
||||
V.prototype.t=function(){var a=0,c=this.a,b=this.k,e,f=new (H?Uint8Array:Array)(this.q+(this.b-32768)),d,g,h,m;if(0===b.length)return H?this.a.subarray(32768,this.b):this.a.slice(32768,this.b);d=0;for(g=b.length;d<g;++d){e=b[d];h=0;for(m=e.length;h<m;++h)f[a++]=e[h]}d=32768;for(g=this.b;d<g;++d)f[a++]=c[d];this.k=[];return this.buffer=f};
|
||||
V.prototype.H=function(){var a,c=this.b;H?this.B?(a=new Uint8Array(c),a.set(this.a.subarray(0,c))):a=this.a.subarray(0,c):(this.a.length>c&&(this.a.length=c),a=this.a);return this.buffer=a};function nb(a,c){var b,e;this.input=a;this.c=0;if(c||!(c={}))c.index&&(this.c=c.index),c.verify&&(this.M=c.verify);b=a[this.c++];e=a[this.c++];switch(b&15){case Ea:this.method=Ea;break;default:i(Error("unsupported compression method"))}0!==((b<<8)+e)%31&&i(Error("invalid fcheck flag:"+((b<<8)+e)%31));e&32&&i(Error("fdict flag is not supported"));this.A=new V(a,{index:this.c,bufferSize:c.bufferSize,bufferType:c.bufferType,resize:c.resize})}
|
||||
nb.prototype.p=function(){var a=this.input,c,b;c=this.A.p();this.c=this.A.c;this.M&&(b=(a[this.c++]<<24|a[this.c++]<<16|a[this.c++]<<8|a[this.c++])>>>0,b!==ba(c)&&i(Error("invalid adler-32 checksum")));return c};y("Zlib.Inflate",nb);y("Zlib.Inflate.BufferType",Ha);Ha.ADAPTIVE=Ha.C;Ha.BLOCK=Ha.D;y("Zlib.Inflate.prototype.decompress",nb.prototype.p);var ob=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15];H&&new Uint16Array(ob);var pb=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,258,258];H&&new Uint16Array(pb);var qb=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0];H&&new Uint8Array(qb);var rb=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577];H&&new Uint16Array(rb);
|
||||
var sb=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13];H&&new Uint8Array(sb);var tb=new (H?Uint8Array:Array)(288),Z,ub;Z=0;for(ub=tb.length;Z<ub;++Z)tb[Z]=143>=Z?8:255>=Z?9:279>=Z?7:8;S(tb);var vb=new (H?Uint8Array:Array)(30),wb,xb;wb=0;for(xb=vb.length;wb<xb;++wb)vb[wb]=5;S(vb);var Ea=8;}).call(window);
|
||||
|
||||
//add for cocos2d-html5
|
||||
var _p = window.Zlib;
|
||||
_p.Deflate = _p["Deflate"];
|
||||
_p.Deflate.compress = _p.Deflate["compress"];
|
||||
_p.Inflate = _p["Inflate"];
|
||||
_p.Inflate.BufferType = _p.Inflate["BufferType"];
|
||||
_p.Inflate.prototype.decompress = _p.Inflate.prototype["decompress"];
|
||||
module.exports = _p;
|
Reference in New Issue
Block a user