|
|
@ -179,7 +179,7 @@ var unzip = function(arrayBuffer) {
|
|
|
|
info(" Found a Central File Header");
|
|
|
|
info(" Found a Central File Header");
|
|
|
|
|
|
|
|
|
|
|
|
// read all file headers
|
|
|
|
// read all file headers
|
|
|
|
while (bstream.peekNumber(4) == zCentralFileHeaderSignature) {
|
|
|
|
while (bstream.peekNumber(4) === zCentralFileHeaderSignature) {
|
|
|
|
bstream.readNumber(4); // signature
|
|
|
|
bstream.readNumber(4); // signature
|
|
|
|
bstream.readNumber(2); // version made by
|
|
|
|
bstream.readNumber(2); // version made by
|
|
|
|
bstream.readNumber(2); // version needed to extract
|
|
|
|
bstream.readNumber(2); // version needed to extract
|
|
|
@ -264,7 +264,7 @@ function getHuffmanCodes(bitLengths) {
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// increment the appropriate bitlength count
|
|
|
|
// increment the appropriate bitlength count
|
|
|
|
if (blCount[length] == undefined) blCount[length] = 0;
|
|
|
|
if (typeof blCount[length] === "undefined") blCount[length] = 0;
|
|
|
|
// a length of zero means this symbol is not participating in the huffman coding
|
|
|
|
// a length of zero means this symbol is not participating in the huffman coding
|
|
|
|
if (length > 0) blCount[length]++;
|
|
|
|
if (length > 0) blCount[length]++;
|
|
|
|
|
|
|
|
|
|
|
@ -277,7 +277,7 @@ function getHuffmanCodes(bitLengths) {
|
|
|
|
for (var bits = 1; bits <= MAX_BITS; ++bits) {
|
|
|
|
for (var bits = 1; bits <= MAX_BITS; ++bits) {
|
|
|
|
var length2 = bits - 1;
|
|
|
|
var length2 = bits - 1;
|
|
|
|
// ensure undefined lengths are zero
|
|
|
|
// ensure undefined lengths are zero
|
|
|
|
if (blCount[length2] == undefined) blCount[length2] = 0;
|
|
|
|
if (typeof blCount[length2] === "undefined") blCount[length2] = 0;
|
|
|
|
code = (code + blCount[bits - 1]) << 1;
|
|
|
|
code = (code + blCount[bits - 1]) << 1;
|
|
|
|
nextCode [bits] = code;
|
|
|
|
nextCode [bits] = code;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -522,11 +522,11 @@ function inflate(compressedData, numDecompressedBytes) {
|
|
|
|
bFinal = bstream.readBits(1);
|
|
|
|
bFinal = bstream.readBits(1);
|
|
|
|
var bType = bstream.readBits(2);
|
|
|
|
var bType = bstream.readBits(2);
|
|
|
|
blockSize = 0;
|
|
|
|
blockSize = 0;
|
|
|
|
++numBlocks;
|
|
|
|
// ++numBlocks;
|
|
|
|
// no compression
|
|
|
|
// no compression
|
|
|
|
if (bType == 0) {
|
|
|
|
if (bType == 0) {
|
|
|
|
// skip remaining bits in this byte
|
|
|
|
// skip remaining bits in this byte
|
|
|
|
while (bstream.bitPtr != 0) bstream.readBits(1);
|
|
|
|
while (bstream.bitPtr !== 0) bstream.readBits(1);
|
|
|
|
var len = bstream.readBits(16);
|
|
|
|
var len = bstream.readBits(16);
|
|
|
|
bstream.readBits(16);
|
|
|
|
bstream.readBits(16);
|
|
|
|
// TODO: check if nlen is the ones-complement of len?
|
|
|
|
// TODO: check if nlen is the ones-complement of len?
|
|
|
@ -535,11 +535,11 @@ function inflate(compressedData, numDecompressedBytes) {
|
|
|
|
blockSize = len;
|
|
|
|
blockSize = len;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// fixed Huffman codes
|
|
|
|
// fixed Huffman codes
|
|
|
|
else if (bType == 1) {
|
|
|
|
else if (bType === 1) {
|
|
|
|
blockSize = inflateBlockData(bstream, getFixedLiteralTable(), getFixedDistanceTable(), buffer);
|
|
|
|
blockSize = inflateBlockData(bstream, getFixedLiteralTable(), getFixedDistanceTable(), buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// dynamic Huffman codes
|
|
|
|
// dynamic Huffman codes
|
|
|
|
else if (bType == 2) {
|
|
|
|
else if (bType === 2) {
|
|
|
|
var numLiteralLengthCodes = bstream.readBits(5) + 257;
|
|
|
|
var numLiteralLengthCodes = bstream.readBits(5) + 257;
|
|
|
|
var numDistanceCodes = bstream.readBits(5) + 1,
|
|
|
|
var numDistanceCodes = bstream.readBits(5) + 1,
|
|
|
|
numCodeLengthCodes = bstream.readBits(4) + 4;
|
|
|
|
numCodeLengthCodes = bstream.readBits(4) + 4;
|
|
|
@ -576,8 +576,7 @@ function inflate(compressedData, numDecompressedBytes) {
|
|
|
|
if (symbol <= 15) {
|
|
|
|
if (symbol <= 15) {
|
|
|
|
literalCodeLengths.push(symbol);
|
|
|
|
literalCodeLengths.push(symbol);
|
|
|
|
prevCodeLength = symbol;
|
|
|
|
prevCodeLength = symbol;
|
|
|
|
}
|
|
|
|
} else if (symbol === 16) {
|
|
|
|
else if (symbol === 16) {
|
|
|
|
|
|
|
|
var repeat = bstream.readBits(2) + 3;
|
|
|
|
var repeat = bstream.readBits(2) + 3;
|
|
|
|
while (repeat--) {
|
|
|
|
while (repeat--) {
|
|
|
|
literalCodeLengths.push(prevCodeLength);
|
|
|
|
literalCodeLengths.push(prevCodeLength);
|
|
|
|