Beautify bitjs

pull/911/head
subdiox 6 years ago
parent 7982ed877c
commit 867aa2f0bd

@ -7,7 +7,6 @@
*
* Copyright(c) 2011 Google Inc.
*/
var bitjs = bitjs || {};
bitjs.archive = bitjs.archive || {};
@ -25,8 +24,7 @@ bitjs.base = function(me, opt_methodName, var_args) {
var args = Array.prototype.slice.call(arguments, 2);
var foundCaller = false;
for (var ctor = me.constructor;
ctor; ctor = ctor.superClass_ && ctor.superClass_.constructor) {
for (var ctor = me.constructor; ctor; ctor = ctor.superClass_ && ctor.superClass_.constructor) {
if (ctor.prototype[opt_methodName] === caller) {
foundCaller = true;
} else if (foundCaller) {
@ -269,7 +267,9 @@ bitjs.archive.Unarchiver.prototype.removeEventListener = function(type, listener
bitjs.archive.Unarchiver.prototype.handleWorkerEvent_ = function(e) {
if ((e instanceof bitjs.archive.UnarchiveEvent || e.type) &&
this.listeners_[e.type] instanceof Array) {
this.listeners_[e.type].forEach(function (listener) { listener(e) });
this.listeners_[e.type].forEach(function(listener) {
listener(e)
});
if (e.type == bitjs.archive.UnarchiveEvent.Type.FINISH) {
this.worker_.terminate();
}
@ -303,7 +303,9 @@ bitjs.archive.Unarchiver.prototype.handleWorkerEvent_ = function(e) {
}
};
this.worker_.postMessage({file: this.ab});
this.worker_.postMessage({
file: this.ab
});
}
};
@ -326,7 +328,9 @@ bitjs.archive.Unzipper = function(arrayBuffer, opt_pathToBitJS) {
bitjs.base(this, arrayBuffer, opt_pathToBitJS);
};
bitjs.inherits(bitjs.archive.Unzipper, bitjs.archive.Unarchiver);
bitjs.archive.Unzipper.prototype.getScriptFileName = function() { return 'unzip.js' };
bitjs.archive.Unzipper.prototype.getScriptFileName = function() {
return 'unzip.js'
};
/**
* Unrarrer
@ -337,7 +341,9 @@ bitjs.archive.Unrarrer = function(arrayBuffer, opt_pathToBitJS) {
bitjs.base(this, arrayBuffer, opt_pathToBitJS);
};
bitjs.inherits(bitjs.archive.Unrarrer, bitjs.archive.Unarchiver);
bitjs.archive.Unrarrer.prototype.getScriptFileName = function() { return 'unrar.js' };
bitjs.archive.Unrarrer.prototype.getScriptFileName = function() {
return 'unrar.js'
};
/**
* Untarrer
@ -348,7 +354,9 @@ bitjs.archive.Untarrer = function(arrayBuffer, opt_pathToBitJS) {
bitjs.base(this, arrayBuffer, opt_pathToBitJS);
};
bitjs.inherits(bitjs.archive.Untarrer, bitjs.archive.Unarchiver);
bitjs.archive.Untarrer.prototype.getScriptFileName = function() { return 'untar.js' };
bitjs.archive.Untarrer.prototype.getScriptFileName = function() {
return 'untar.js'
};
/**
* Factory method that creates an unarchiver based on the byte signature found

@ -224,11 +224,11 @@ VM_PreparedOperand.prototype.toString = function() {
if (this.Type === null) {
return 'Error: Type was null in VM_PreparedOperand';
}
return '{ '
+ 'Type: ' + getDebugString(VM_OpType, this.Type)
+ ', Data: ' + this.Data
+ ', Base: ' + this.Base
+ ' }';
return '{ ' +
'Type: ' + getDebugString(VM_OpType, this.Type) +
', Data: ' + this.Data +
', Base: ' + this.Base +
' }';
};
/**
@ -255,12 +255,12 @@ VM_PreparedCommand.prototype.toString = function(indent) {
return 'Error: OpCode was null in VM_PreparedCommand';
}
indent = indent || '';
return indent + '{\n'
+ indent + ' OpCode: ' + getDebugString(VM_Commands, this.OpCode) + ',\n'
+ indent + ' ByteMode: ' + this.ByteMode + ',\n'
+ indent + ' Op1: ' + this.Op1.toString() + ',\n'
+ indent + ' Op2: ' + this.Op2.toString() + ',\n'
+ indent + '}';
return indent + '{\n' +
indent + ' OpCode: ' + getDebugString(VM_Commands, this.OpCode) + ',\n' +
indent + ' ByteMode: ' + this.ByteMode + ',\n' +
indent + ' Op1: ' + this.Op1.toString() + ',\n' +
indent + ' Op2: ' + this.Op2.toString() + ',\n' +
indent + '}';
};
/**
@ -339,46 +339,86 @@ var VMCF_USEFLAGS = 32;
var VMCF_CHFLAGS = 64;
var VM_CmdFlags = [
/* VM_MOV */ VMCF_OP2 | VMCF_BYTEMODE ,
/* VM_CMP */ VMCF_OP2 | VMCF_BYTEMODE | VMCF_CHFLAGS ,
/* VM_ADD */ VMCF_OP2 | VMCF_BYTEMODE | VMCF_CHFLAGS ,
/* VM_SUB */ VMCF_OP2 | VMCF_BYTEMODE | VMCF_CHFLAGS ,
/* VM_JZ */ VMCF_OP1 | VMCF_JUMP | VMCF_USEFLAGS ,
/* VM_JNZ */ VMCF_OP1 | VMCF_JUMP | VMCF_USEFLAGS ,
/* VM_INC */ VMCF_OP1 | VMCF_BYTEMODE | VMCF_CHFLAGS ,
/* VM_DEC */ VMCF_OP1 | VMCF_BYTEMODE | VMCF_CHFLAGS ,
/* VM_JMP */ VMCF_OP1 | VMCF_JUMP ,
/* VM_XOR */ VMCF_OP2 | VMCF_BYTEMODE | VMCF_CHFLAGS ,
/* VM_AND */ VMCF_OP2 | VMCF_BYTEMODE | VMCF_CHFLAGS ,
/* VM_OR */ VMCF_OP2 | VMCF_BYTEMODE | VMCF_CHFLAGS ,
/* VM_TEST */ VMCF_OP2 | VMCF_BYTEMODE | VMCF_CHFLAGS ,
/* VM_JS */ VMCF_OP1 | VMCF_JUMP | VMCF_USEFLAGS ,
/* VM_JNS */ VMCF_OP1 | VMCF_JUMP | VMCF_USEFLAGS ,
/* VM_JB */ VMCF_OP1 | VMCF_JUMP | VMCF_USEFLAGS ,
/* VM_JBE */ VMCF_OP1 | VMCF_JUMP | VMCF_USEFLAGS ,
/* VM_JA */ VMCF_OP1 | VMCF_JUMP | VMCF_USEFLAGS ,
/* VM_JAE */ VMCF_OP1 | VMCF_JUMP | VMCF_USEFLAGS ,
/* VM_PUSH */ VMCF_OP1 ,
/* VM_POP */ VMCF_OP1 ,
/* VM_CALL */ VMCF_OP1 | VMCF_PROC ,
/* VM_RET */ VMCF_OP0 | VMCF_PROC ,
/* VM_NOT */ VMCF_OP1 | VMCF_BYTEMODE ,
/* VM_SHL */ VMCF_OP2 | VMCF_BYTEMODE | VMCF_CHFLAGS ,
/* VM_SHR */ VMCF_OP2 | VMCF_BYTEMODE | VMCF_CHFLAGS ,
/* VM_SAR */ VMCF_OP2 | VMCF_BYTEMODE | VMCF_CHFLAGS ,
/* VM_NEG */ VMCF_OP1 | VMCF_BYTEMODE | VMCF_CHFLAGS ,
/* VM_PUSHA */ VMCF_OP0 ,
/* VM_POPA */ VMCF_OP0 ,
/* VM_PUSHF */ VMCF_OP0 | VMCF_USEFLAGS ,
/* VM_POPF */ VMCF_OP0 | VMCF_CHFLAGS ,
/* VM_MOVZX */ VMCF_OP2 ,
/* VM_MOVSX */ VMCF_OP2 ,
/* VM_XCHG */ VMCF_OP2 | VMCF_BYTEMODE ,
/* VM_MUL */ VMCF_OP2 | VMCF_BYTEMODE ,
/* VM_DIV */ VMCF_OP2 | VMCF_BYTEMODE ,
/* VM_ADC */ VMCF_OP2 | VMCF_BYTEMODE | VMCF_USEFLAGS | VMCF_CHFLAGS ,
/* VM_SBB */ VMCF_OP2 | VMCF_BYTEMODE | VMCF_USEFLAGS | VMCF_CHFLAGS ,
/* VM_PRINT */ VMCF_OP0 ,
/* VM_MOV */
VMCF_OP2 | VMCF_BYTEMODE,
/* VM_CMP */
VMCF_OP2 | VMCF_BYTEMODE | VMCF_CHFLAGS,
/* VM_ADD */
VMCF_OP2 | VMCF_BYTEMODE | VMCF_CHFLAGS,
/* VM_SUB */
VMCF_OP2 | VMCF_BYTEMODE | VMCF_CHFLAGS,
/* VM_JZ */
VMCF_OP1 | VMCF_JUMP | VMCF_USEFLAGS,
/* VM_JNZ */
VMCF_OP1 | VMCF_JUMP | VMCF_USEFLAGS,
/* VM_INC */
VMCF_OP1 | VMCF_BYTEMODE | VMCF_CHFLAGS,
/* VM_DEC */
VMCF_OP1 | VMCF_BYTEMODE | VMCF_CHFLAGS,
/* VM_JMP */
VMCF_OP1 | VMCF_JUMP,
/* VM_XOR */
VMCF_OP2 | VMCF_BYTEMODE | VMCF_CHFLAGS,
/* VM_AND */
VMCF_OP2 | VMCF_BYTEMODE | VMCF_CHFLAGS,
/* VM_OR */
VMCF_OP2 | VMCF_BYTEMODE | VMCF_CHFLAGS,
/* VM_TEST */
VMCF_OP2 | VMCF_BYTEMODE | VMCF_CHFLAGS,
/* VM_JS */
VMCF_OP1 | VMCF_JUMP | VMCF_USEFLAGS,
/* VM_JNS */
VMCF_OP1 | VMCF_JUMP | VMCF_USEFLAGS,
/* VM_JB */
VMCF_OP1 | VMCF_JUMP | VMCF_USEFLAGS,
/* VM_JBE */
VMCF_OP1 | VMCF_JUMP | VMCF_USEFLAGS,
/* VM_JA */
VMCF_OP1 | VMCF_JUMP | VMCF_USEFLAGS,
/* VM_JAE */
VMCF_OP1 | VMCF_JUMP | VMCF_USEFLAGS,
/* VM_PUSH */
VMCF_OP1,
/* VM_POP */
VMCF_OP1,
/* VM_CALL */
VMCF_OP1 | VMCF_PROC,
/* VM_RET */
VMCF_OP0 | VMCF_PROC,
/* VM_NOT */
VMCF_OP1 | VMCF_BYTEMODE,
/* VM_SHL */
VMCF_OP2 | VMCF_BYTEMODE | VMCF_CHFLAGS,
/* VM_SHR */
VMCF_OP2 | VMCF_BYTEMODE | VMCF_CHFLAGS,
/* VM_SAR */
VMCF_OP2 | VMCF_BYTEMODE | VMCF_CHFLAGS,
/* VM_NEG */
VMCF_OP1 | VMCF_BYTEMODE | VMCF_CHFLAGS,
/* VM_PUSHA */
VMCF_OP0,
/* VM_POPA */
VMCF_OP0,
/* VM_PUSHF */
VMCF_OP0 | VMCF_USEFLAGS,
/* VM_POPF */
VMCF_OP0 | VMCF_CHFLAGS,
/* VM_MOVZX */
VMCF_OP2,
/* VM_MOVSX */
VMCF_OP2,
/* VM_XCHG */
VMCF_OP2 | VMCF_BYTEMODE,
/* VM_MUL */
VMCF_OP2 | VMCF_BYTEMODE,
/* VM_DIV */
VMCF_OP2 | VMCF_BYTEMODE,
/* VM_ADC */
VMCF_OP2 | VMCF_BYTEMODE | VMCF_USEFLAGS | VMCF_CHFLAGS,
/* VM_SBB */
VMCF_OP2 | VMCF_BYTEMODE | VMCF_USEFLAGS | VMCF_CHFLAGS,
/* VM_PRINT */
VMCF_OP0,
];

@ -226,11 +226,13 @@ var rDDecode = [0, 1, 2, 3, 4, 6, 8, 12, 16, 24, 32,
48, 64, 96, 128, 192, 256, 384, 512, 768, 1024, 1536, 2048, 3072,
4096, 6144, 8192, 12288, 16384, 24576, 32768, 49152, 65536, 98304,
131072, 196608, 262144, 327680, 393216, 458752, 524288, 589824,
655360, 720896, 786432, 851968, 917504, 983040];
655360, 720896, 786432, 851968, 917504, 983040
];
var rDBits = [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, 14, 14,
15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16];
15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16
];
var rLOW_DIST_REP_COUNT = 16;
@ -328,15 +330,13 @@ function RarReadTables(bstream) {
var ZeroCount = bstream.readBits(4);
if (ZeroCount == 0) {
BitLength[I] = 15;
}
else {
} else {
ZeroCount += 2;
while (ZeroCount-- > 0 && I < rBC)
BitLength[I++] = 0;
--I;
}
}
else {
} else {
BitLength[I] = Length;
}
}
@ -381,24 +381,26 @@ function RarReadTables(bstream) {
function RarDecodeNumber(bstream, dec) {
var DecodeLen = dec.DecodeLen, DecodePos = dec.DecodePos, DecodeNum = dec.DecodeNum;
var DecodeLen = dec.DecodeLen,
DecodePos = dec.DecodePos,
DecodeNum = dec.DecodeNum;
var bitField = bstream.getBits() & 0xfffe;
//some sort of rolled out binary search
var bits = ((bitField < DecodeLen[8]) ?
((bitField < DecodeLen[4]) ?
((bitField < DecodeLen[2]) ?
((bitField < DecodeLen[1])?1:2)
:((bitField < DecodeLen[3])?3:4))
:(bitField < DecodeLen[6])?
((bitField < DecodeLen[5])?5:6)
:((bitField < DecodeLen[7])?7:8))
:((bitField < DecodeLen[12])?
((bitField < DecodeLen[1]) ? 1 : 2) :
((bitField < DecodeLen[3]) ? 3 : 4)) :
(bitField < DecodeLen[6]) ?
((bitField < DecodeLen[5]) ? 5 : 6) :
((bitField < DecodeLen[7]) ? 7 : 8)) :
((bitField < DecodeLen[12]) ?
((bitField < DecodeLen[10]) ?
((bitField < DecodeLen[9])?9:10)
:((bitField < DecodeLen[11])?11:12))
:(bitField < DecodeLen[14])?
((bitField < DecodeLen[13])?13:14)
:15));
((bitField < DecodeLen[9]) ? 9 : 10) :
((bitField < DecodeLen[11]) ? 11 : 12)) :
(bitField < DecodeLen[14]) ?
((bitField < DecodeLen[13]) ? 13 : 14) :
15));
bstream.readBits(bits);
var N = DecodePos[bits] + ((bitField - DecodeLen[bits - 1]) >>> (16 - bits));
@ -716,9 +718,9 @@ function RarAddVMCode(firstByte, vmCode) {
if (firstByte & 0x20) {
stackFilter.BlockLength = RarVM.readData(bstream);
} else {
stackFilter.BlockLength = filtPos < OldFilterLengths.length
? OldFilterLengths[filtPos]
: 0;
stackFilter.BlockLength = filtPos < OldFilterLengths.length ?
OldFilterLengths[filtPos] :
0;
}
stackFilter.NextWindow = (wBuffer.ptr != rBuffer.ptr) &&
(((wBuffer.ptr - rBuffer.ptr) & MAXWINMASK) <= blockStart);
@ -1138,8 +1140,7 @@ function RarWriteData(offset, numBytes) {
/**
* @param {VM_PreparedProgram} prg
*/
function RarExecuteCode(prg)
{
function RarExecuteCode(prg) {
if (prg.GlobalData.length > 0) {
var writtenFileSize = wBuffer.ptr;
prg.InitR[6] = writtenFileSize;
@ -1152,7 +1153,8 @@ function RarExecuteCode(prg)
function RarReadEndOfBlock(bstream) {
RarUpdateProgress();
var NewTable = false, NewFile = false;
var NewTable = false,
NewFile = false;
if (bstream.readBits(1)) {
NewTable = true;
} else {
@ -1242,8 +1244,7 @@ var RarLocalFile = function(bstream) {
if (this.header.headType != FILE_HEAD && this.header.headType != ENDARC_HEAD) {
this.isValid = false;
info("Error! RAR Volume did not include a FILE_HEAD header ");
}
else {
} else {
// read in the compressed data
this.fileData = null;
if (this.header.packSize > 0) {
@ -1296,8 +1297,7 @@ var unrar = function(arrayBuffer) {
var mhead = new RarVolumeHeader(bstream);
if (mhead.headType != MAIN_HEAD) {
info("Error! RAR did not include a MAIN_HEAD header");
}
else {
} else {
var localFiles = [],
localFile = null;
do {
@ -1325,7 +1325,9 @@ var unrar = function(arrayBuffer) {
return aname > bname ? 1 : -1;
});
info(localFiles.map(function(a){return a.filename}).join(', '));
info(localFiles.map(function(a) {
return a.filename
}).join(', '));
for (var i = 0; i < localFiles.length; ++i) {
var localfile = localFiles[i];
@ -1344,8 +1346,7 @@ var unrar = function(arrayBuffer) {
postProgress();
}
}
else {
} else {
err("Invalid RAR file");
}
postMessage(new bitjs.archive.UnarchiveFinishEvent());

@ -52,7 +52,8 @@ var zEndOfCentralDirLocatorSignature = 0x07064b50;
// takes a ByteStream and parses out the local file information
var ZipLocalFile = function(bstream) {
if (typeof bstream != typeof {} || !bstream.readNumber || typeof bstream.readNumber != typeof function(){}) {
if (typeof bstream != typeof {} || !bstream.readNumber || typeof bstream.readNumber != typeof
function() {}) {
return null;
}
@ -123,8 +124,7 @@ ZipLocalFile.prototype.unzip = function() {
else if (this.compressionMethod == 8) {
info("ZIP v2.0, DEFLATE: " + this.filename + " (" + this.compressedSize + " bytes)");
this.fileData = inflate(this.fileData, this.uncompressedSize);
}
else {
} else {
err("UNSUPPORTED VERSION/FORMAT: ZIP v" + this.version + ", compression method=" + this.compressionMethod + ": " + this.filename + " (" + this.compressedSize + " bytes)");
this.fileData = null;
}
@ -307,11 +307,15 @@ function getHuffmanCodes(bitLengths) {
}
// Step 3: Assign numerical values to all codes
var table = {}, tableLength = 0;
var table = {},
tableLength = 0;
for (var n = 0; n < numLengths; ++n) {
var len = bitLengths[n];
if (len != 0) {
table[next_code[len]] = { length: len, symbol: n }; //, bitstring: binaryValueToString(next_code[len],len) };
table[next_code[len]] = {
length: len,
symbol: n
}; //, bitstring: binaryValueToString(next_code[len],len) };
tableLength++;
next_code[len]++;
}
@ -340,6 +344,7 @@ function getHuffmanCodes(bitLengths) {
// fixed Huffman codes go from 7-9 bits, so we need an array whose index can hold up to 9 bits
var fixedHCtoLiteral = null;
var fixedHCtoDistance = null;
function getFixedLiteralTable() {
// create once
if (!fixedHCtoLiteral) {
@ -359,7 +364,9 @@ function getFixedDistanceTable() {
// create once
if (!fixedHCtoDistance) {
var bitlengths = new Array(32);
for (var i = 0; i < 32; ++i) { bitlengths[i] = 5; }
for (var i = 0; i < 32; ++i) {
bitlengths[i] = 5;
}
// get huffman code table
fixedHCtoDistance = getHuffmanCodes(bitlengths);
@ -370,7 +377,8 @@ function getFixedDistanceTable() {
// extract one bit at a time until we find a matching Huffman Code
// then return that symbol
function decodeSymbol(bstream, hcTable) {
var code = 0, len = 0;
var code = 0,
len = 0;
var match = false;
// loop until we match
@ -411,13 +419,34 @@ var CodeLengthCodeOrder = [16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2
266 1 13,14 276 3 59-66
*/
var LengthLookupTable = [
[0,3], [0,4], [0,5], [0,6],
[0,7], [0,8], [0,9], [0,10],
[1,11], [1,13], [1,15], [1,17],
[2,19], [2,23], [2,27], [2,31],
[3,35], [3,43], [3,51], [3,59],
[4,67], [4,83], [4,99], [4,115],
[5,131], [5,163], [5,195], [5,227],
[0, 3],
[0, 4],
[0, 5],
[0, 6],
[0, 7],
[0, 8],
[0, 9],
[0, 10],
[1, 11],
[1, 13],
[1, 15],
[1, 17],
[2, 19],
[2, 23],
[2, 27],
[2, 31],
[3, 35],
[3, 43],
[3, 51],
[3, 59],
[4, 67],
[4, 83],
[4, 99],
[4, 115],
[5, 131],
[5, 163],
[5, 195],
[5, 227],
[0, 258]
];
/*
@ -436,20 +465,36 @@ var LengthLookupTable = [
9 3 25-32 19 8 769-1024 29 13 24577-32768
*/
var DistLookupTable = [
[0,1], [0,2], [0,3], [0,4],
[1,5], [1,7],
[2,9], [2,13],
[3,17], [3,25],
[4,33], [4,49],
[5,65], [5,97],
[6,129], [6,193],
[7,257], [7,385],
[8,513], [8,769],
[9,1025], [9,1537],
[10,2049], [10,3073],
[11,4097], [11,6145],
[12,8193], [12,12289],
[13,16385], [13,24577]
[0, 1],
[0, 2],
[0, 3],
[0, 4],
[1, 5],
[1, 7],
[2, 9],
[2, 13],
[3, 17],
[3, 25],
[4, 33],
[4, 49],
[5, 65],
[5, 97],
[6, 129],
[6, 193],
[7, 257],
[7, 385],
[8, 513],
[8, 769],
[9, 1025],
[9, 1537],
[10, 2049],
[10, 3073],
[11, 4097],
[11, 6145],
[12, 8193],
[12, 12289],
[13, 16385],
[13, 24577]
];
function inflateBlockData(bstream, hcLiteralTable, hcDistanceTable, buffer) {
@ -468,7 +513,8 @@ function inflateBlockData(bstream, hcLiteralTable, hcDistanceTable, buffer) {
stream, and copy length bytes from this
position to the output stream.
*/
var numSymbols = 0, blockSize = 0;
var numSymbols = 0,
blockSize = 0;
for (;;) {
var symbol = decodeSymbol(bstream, hcLiteralTable);
++numSymbols;
@ -476,13 +522,11 @@ function inflateBlockData(bstream, hcLiteralTable, hcDistanceTable, buffer) {
// copy literal byte to output
buffer.insertByte(symbol);
blockSize++;
}
else {
} else {
// end of block reached
if (symbol == 256) {
break;
}
else {
} else {
var lengthLookup = LengthLookupTable[symbol - 257],
length = lengthLookup[1] + bstream.readBits(lengthLookup[0]),
distLookup = DistLookupTable[decodeSymbol(bstream, hcDistanceTable)],
@ -525,7 +569,8 @@ function inflate(compressedData, numDecompressedBytes) {
compressedData.byteOffset,
compressedData.byteLength);
var buffer = new bitjs.io.ByteBuffer(numDecompressedBytes);
var numBlocks = 0, blockSize = 0;
var numBlocks = 0,
blockSize = 0;
// block format: http://tools.ietf.org/html/rfc1951#page-9
do {
@ -585,20 +630,17 @@ function inflate(compressedData, numDecompressedBytes) {
if (symbol <= 15) {
literalCodeLengths.push(symbol);
prevCodeLength = symbol;
}
else if (symbol == 16) {
} else if (symbol == 16) {
var repeat = bstream.readBits(2) + 3;
while (repeat--) {
literalCodeLengths.push(prevCodeLength);
}
}
else if (symbol == 17) {
} else if (symbol == 17) {
var repeat = bstream.readBits(3) + 3;
while (repeat--) {
literalCodeLengths.push(0);
}
}
else if (symbol == 18) {
} else if (symbol == 18) {
var repeat = bstream.readBits(7) + 11;
while (repeat--) {
literalCodeLengths.push(0);

@ -8,7 +8,6 @@
* Copyright(c) 2011 Google Inc.
* Copyright(c) 2011 antimatter15
*/
var bitjs = bitjs || {};
bitjs.io = bitjs.io || {};
@ -18,7 +17,8 @@ bitjs.io = bitjs.io || {};
bitjs.BIT = [0x01, 0x02, 0x04, 0x08,
0x10, 0x20, 0x40, 0x80,
0x100, 0x200, 0x400, 0x800,
0x1000, 0x2000, 0x4000, 0x8000];
0x1000, 0x2000, 0x4000, 0x8000
];
// mask for getting N number of bits (0-8)
var BITMASK = [0, 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x7F, 0xFF];
@ -89,8 +89,7 @@ bitjs.io.BitStream.prototype.peekBits_ltr = function(n, movePointers) {
bitPtr = 0;
bitsIn += numBitsLeftInThisByte;
n -= numBitsLeftInThisByte;
}
else {
} else {
var mask = (BITMASK[n] << bitPtr);
result |= (((bytes[bytePtr] & mask) >> bitPtr) << bitsIn);
@ -149,8 +148,7 @@ bitjs.io.BitStream.prototype.peekBits_rtl = function(n, movePointers) {
bytePtr++;
bitPtr = 0;
n -= numBitsLeftInThisByte;
}
else {
} else {
result <<= n;
result |= ((bytes[bytePtr] & (BITMASK[n] << (8 - n - bitPtr))) >> (8 - n - bitPtr));

@ -8,7 +8,6 @@
* Copyright(c) 2011 Google Inc.
* Copyright(c) 2011 antimatter15
*/
var bitjs = bitjs || {};
bitjs.io = bitjs.io || {};

@ -8,7 +8,6 @@
* Copyright(c) 2011 Google Inc.
* Copyright(c) 2011 antimatter15
*/
var bitjs = bitjs || {};
bitjs.io = bitjs.io || {};

Loading…
Cancel
Save