From adbd182bcc54494e009cbe4a1a5ba6c371898043 Mon Sep 17 00:00:00 2001 From: codedread Date: Sun, 21 Jan 2018 02:24:13 -0800 Subject: [PATCH] Tidy up some comments --- io/bitstream.js | 9 ++------- io/bytestream.js | 13 ++++++++----- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/io/bitstream.js b/io/bitstream.js index 70f0d1f..52e7f15 100644 --- a/io/bitstream.js +++ b/io/bitstream.js @@ -15,7 +15,8 @@ bitjs.io = bitjs.io || {}; // 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 { /** @@ -101,9 +102,6 @@ bitjs.io.BitStream = class { let bitsIn = 0; // 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) { if (bytePtr >= curPage.length && this.pages_.length > 0) { curPage = this.pages_[pageIndex++]; @@ -168,9 +166,6 @@ bitjs.io.BitStream = class { let result = 0; // 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) { if (bytePtr >= curPage.length && this.pages_.length > 0) { curPage = this.pages_[pageIndex++]; diff --git a/io/bytestream.js b/io/bytestream.js index e80b960..90062c1 100644 --- a/io/bytestream.js +++ b/io/bytestream.js @@ -15,8 +15,9 @@ bitjs.io = bitjs.io || {}; // TODO: Add method for tee-ing off the stream with tests. /** - * This object allows you to peek and consume bytes as numbers and strings - * out of an ArrayBuffer. In this buffer, everything must be byte-aligned. + * This object allows you to peek and consume bytes as numbers and strings out + * of a stream. More bytes can be pushed into the back of the stream via the + * push() method. */ 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 - * pointer - * TODO: This apparently cannot read more than 4 bytes as a number? + * pointer. * @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. */ @@ -75,7 +75,10 @@ bitjs.io.ByteStream = class { 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) { throw 'Error! Overflowed the byte stream while peekNumber()! n=' + num +