adding prettier

This commit is contained in:
Hare Sudhan 2024-02-25 16:31:23 -05:00
parent c5a1b69c30
commit ab0bc52d3c
717 changed files with 29324 additions and 18602 deletions

View file

@ -13,7 +13,6 @@
* as various data types.
*/
export default class Stream {
/**
* Stream constructor.
*
@ -32,12 +31,10 @@ export default class Stream {
* @param {number} [numBytes=null]
* @returns {Uint8Array}
*/
getBytes(numBytes=null) {
getBytes(numBytes = null) {
if (this.position > this.length) return undefined;
const newPosition = numBytes !== null ?
this.position + numBytes :
this.length;
const newPosition = numBytes !== null ? this.position + numBytes : this.length;
const bytes = this.bytes.slice(this.position, newPosition);
this.position = newPosition;
this.bitPos = 0;
@ -51,7 +48,7 @@ export default class Stream {
* @param {number} [numBytes=-1]
* @returns {string}
*/
readString(numBytes=-1) {
readString(numBytes = -1) {
if (this.position > this.length) return undefined;
if (numBytes === -1) numBytes = this.length - this.position;
@ -74,7 +71,7 @@ export default class Stream {
* @param {string} [endianness="be"]
* @returns {number}
*/
readInt(numBytes, endianness="be") {
readInt(numBytes, endianness = "be") {
if (this.position > this.length) return undefined;
let val = 0;
@ -101,7 +98,7 @@ export default class Stream {
* @param {string} [endianness="be"]
* @returns {number}
*/
readBits(numBits, endianness="be") {
readBits(numBits, endianness = "be") {
if (this.position > this.length) return undefined;
let bitBuf = 0,
@ -115,20 +112,16 @@ export default class Stream {
// Not enough bits yet
while (bitBufLen < numBits) {
if (endianness === "be")
bitBuf = (bitBuf << bitBufLen) | this.bytes[this.position++];
else
bitBuf |= this.bytes[this.position++] << bitBufLen;
if (endianness === "be") bitBuf = (bitBuf << bitBufLen) | this.bytes[this.position++];
else bitBuf |= this.bytes[this.position++] << bitBufLen;
bitBufLen += 8;
}
// Reverse back to numBits
if (bitBufLen > numBits) {
const excess = bitBufLen - numBits;
if (endianness === "be")
bitBuf >>>= excess;
else
bitBuf &= (1 << numBits) - 1;
if (endianness === "be") bitBuf >>>= excess;
else bitBuf &= (1 << numBits) - 1;
bitBufLen -= excess;
this.position--;
this.bitPos = 8 - excess;
@ -143,9 +136,7 @@ export default class Stream {
* @returns {number} The bit mask
*/
function bitMask(bitPos) {
return endianness === "be" ?
(1 << (8 - bitPos)) - 1 :
256 - (1 << bitPos);
return endianness === "be" ? (1 << (8 - bitPos)) - 1 : 256 - (1 << bitPos);
}
}
@ -184,7 +175,7 @@ export default class Stream {
}
const length = val.length;
const initial = val[length-1];
const initial = val[length - 1];
this.position = length;
// Get the skip table.
@ -193,12 +184,12 @@ export default class Stream {
while (this.position < this.length) {
// Until we hit the final element of val in the stream.
while ((this.position < this.length) && (this.bytes[this.position++] !== initial));
while (this.position < this.length && this.bytes[this.position++] !== initial);
found = true;
// Loop through the elements comparing them to val.
for (let x = length-1; x >= 0; x--) {
for (let x = length - 1; x >= 0; x--) {
if (this.bytes[this.position - length + x] !== val[x]) {
found = false;
@ -214,7 +205,6 @@ export default class Stream {
}
}
/**
* Consume bytes if they match the supplied value.
*
@ -319,9 +309,8 @@ export default class Stream {
* @param {number} [finish=this.position]
* @returns {Uint8Array}
*/
carve(start=0, finish=this.position) {
carve(start = 0, finish = this.position) {
if (this.bitPos > 0) finish++;
return this.bytes.slice(start, finish);
}
}