1
0
Fork 0
mirror of https://github.com/codedread/bitjs synced 2025-10-03 17:49:16 +02:00

Tidy up some comments

This commit is contained in:
codedread 2018-01-21 02:24:13 -08:00
parent 5aa0110faf
commit adbd182bcc
2 changed files with 10 additions and 12 deletions

View file

@ -15,7 +15,8 @@ bitjs.io = bitjs.io || {};
// TODO: Add method for tee-ing off the stream with tests. // TODO: Add method for tee-ing off the stream with tests.
/** /**
* This bit stream peeks and consumes bits out of a binary stream. * This object allows you to peek and consume bits and bytes out of a stream.
* More bits can be pushed into the back of the stream via the push() method.
*/ */
bitjs.io.BitStream = class { bitjs.io.BitStream = class {
/** /**
@ -101,9 +102,6 @@ bitjs.io.BitStream = class {
let bitsIn = 0; let bitsIn = 0;
// keep going until we have no more bits left to peek at // keep going until we have no more bits left to peek at
// TODO: Consider putting all bits from bytes we will need into a variable and then
// 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 (num > 0) { while (num > 0) {
if (bytePtr >= curPage.length && this.pages_.length > 0) { if (bytePtr >= curPage.length && this.pages_.length > 0) {
curPage = this.pages_[pageIndex++]; curPage = this.pages_[pageIndex++];
@ -168,9 +166,6 @@ bitjs.io.BitStream = class {
let result = 0; let result = 0;
// keep going until we have no more bits left to peek at // keep going until we have no more bits left to peek at
// TODO: Consider putting all bits from bytes we will need into a variable and then
// 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 (num > 0) { while (num > 0) {
if (bytePtr >= curPage.length && this.pages_.length > 0) { if (bytePtr >= curPage.length && this.pages_.length > 0) {
curPage = this.pages_[pageIndex++]; curPage = this.pages_[pageIndex++];

View file

@ -15,8 +15,9 @@ bitjs.io = bitjs.io || {};
// TODO: Add method for tee-ing off the stream with tests. // TODO: Add method for tee-ing off the stream with tests.
/** /**
* This object allows you to peek and consume bytes as numbers and strings * This object allows you to peek and consume bytes as numbers and strings out
* out of an ArrayBuffer. In this buffer, everything must be byte-aligned. * of a stream. More bytes can be pushed into the back of the stream via the
* push() method.
*/ */
bitjs.io.ByteStream = class { bitjs.io.ByteStream = class {
/** /**
@ -62,8 +63,7 @@ bitjs.io.ByteStream = class {
/** /**
* Peeks at the next n bytes as an unsigned number but does not advance the * Peeks at the next n bytes as an unsigned number but does not advance the
* pointer * pointer.
* TODO: This apparently cannot read more than 4 bytes as a number?
* @param {number} n The number of bytes to peek at. Must be a positive integer. * @param {number} n The number of bytes to peek at. Must be a positive integer.
* @return {number} The n bytes interpreted as an unsigned number. * @return {number} The n bytes interpreted as an unsigned number.
*/ */
@ -75,7 +75,10 @@ bitjs.io.ByteStream = class {
return 0; return 0;
} }
// TODO: Throw an error if n > 4. if (n > 4) {
throw 'Error! Called peekNumber(' + n +
') but this method can only reliably read numbers up to 4 bytes long';
}
if (this.getNumBytesLeft_() < num) { if (this.getNumBytesLeft_() < num) {
throw 'Error! Overflowed the byte stream while peekNumber()! n=' + num + throw 'Error! Overflowed the byte stream while peekNumber()! n=' + num +