1
0
Fork 0
mirror of https://github.com/codedread/bitjs synced 2025-10-04 18:19:15 +02:00

Whitespace and a couple arrow functions

This commit is contained in:
codedread 2017-02-21 12:05:03 -08:00
parent 0d27e9d9c0
commit d2a4329893
5 changed files with 302 additions and 317 deletions

View file

@ -21,7 +21,6 @@ bitjs.archive.UnarchiveEvent = class {
constructor(type) {
/**
* The event type.
*
* @type {string}
*/
this.type = type;
@ -52,7 +51,6 @@ bitjs.archive.UnarchiveInfoEvent = class extends bitjs.archive.UnarchiveEvent {
/**
* The information message.
*
* @type {string}
*/
this.msg = msg;
@ -71,7 +69,6 @@ bitjs.archive.UnarchiveErrorEvent = class extends bitjs.archive.UnarchiveEvent {
/**
* The information message.
*
* @type {string}
*/
this.msg = msg;

View file

@ -135,9 +135,7 @@ const untar = function(arrayBuffer) {
totalFilesInArchive = localFiles.length;
// got all local files, now sort them
localFiles.sort(function(a,b) {
return a.filename > b.filename ? 1 : -1;
});
localFiles.sort((a,b) => a.filename > b.filename ? 1 : -1);
// report # files and total length
if (localFiles.length > 0) {

View file

@ -167,9 +167,7 @@ const unzip = function(arrayBuffer) {
totalFilesInArchive = localFiles.length;
// got all local files, now sort them
localFiles.sort(function(a,b) {
return a.filename > b.filename ? 1 : -1;
});
localFiles.sort((a,b) => a.filename > b.filename ? 1 : -1);
// archive extra data record
if (bstream.peekNumber(4) == zArchiveExtraDataSignature) {
@ -275,7 +273,6 @@ function getHuffmanCodes(bitLengths) {
if (bl_count[length] == undefined) bl_count[length] = 0;
// a length of zero means this symbol is not participating in the huffman coding
if (length > 0) bl_count[length]++;
if (length > MAX_BITS) MAX_BITS = length;
}
@ -465,13 +462,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 {
const lengthLookup = LengthLookupTable[symbol - 257];
let length = lengthLookup[1] + bstream.readBits(lengthLookup[0]);
const distLookup = DistLookupTable[decodeSymbol(bstream, hcDistanceTable)];
@ -576,20 +571,17 @@ function inflate(compressedData, numDecompressedBytes) {
if (symbol <= 15) {
literalCodeLengths.push(symbol);
prevCodeLength = symbol;
}
else if (symbol == 16) {
} else if (symbol == 16) {
let repeat = bstream.readBits(2) + 3;
while (repeat--) {
literalCodeLengths.push(prevCodeLength);
}
}
else if (symbol == 17) {
} else if (symbol == 17) {
let repeat = bstream.readBits(3) + 3;
while (repeat--) {
literalCodeLengths.push(0);
}
}
else if (symbol == 18) {
} else if (symbol == 18) {
let repeat = bstream.readBits(7) + 11;
while (repeat--) {
literalCodeLengths.push(0);
@ -604,9 +596,7 @@ function inflate(compressedData, numDecompressedBytes) {
const hcLiteralTable = getHuffmanCodes(literalCodeLengths);
const hcDistanceTable = getHuffmanCodes(distanceCodeLengths);
blockSize = inflateBlockData(bstream, hcLiteralTable, hcDistanceTable, buffer);
}
// error
else {
} else { // error
err("Error! Encountered deflate block of type 3");
return null;
}

View file

@ -124,7 +124,6 @@ bitjs.io.BitStream = class {
// shifting/masking it to just extract the bits we want.
// This could be considerably faster when reading more than 3 or 4 bits at a time.
while (n > 0) {
if (bytePtr >= bytes.length) {
throw "Error! Overflowed the bit stream! n=" + n + ", bytePtr=" + bytePtr + ", bytes.length=" +
bytes.length + ", bitPtr=" + bitPtr;

View file

@ -40,8 +40,9 @@ bitjs.io.ByteStream = class {
*/
peekNumber(n) {
// TODO: return error if n would go past the end of the stream?
if (n <= 0 || typeof n != typeof 1)
if (n <= 0 || typeof n != typeof 1) {
return -1;
}
let result = 0;
// read from last byte to first byte and roll them in