From dfd4cca43fc0641470f64b162efb9d42a0bd039c Mon Sep 17 00:00:00 2001 From: n1073645 Date: Wed, 13 Nov 2019 09:02:36 +0000 Subject: [PATCH] Corrections --- src/core/lib/Stream.mjs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/core/lib/Stream.mjs b/src/core/lib/Stream.mjs index 58cb2d5b..0230b26a 100644 --- a/src/core/lib/Stream.mjs +++ b/src/core/lib/Stream.mjs @@ -158,14 +158,15 @@ export default class Stream { /** - * Build's the skip forward table from the value to be searched. + * Builds the skip forward table from the value to be searched. * - * @param val - * @param len + * @param {Uint8Array} val + * @param {Number} len + * @returns {Uint8Array} */ function preprocess(val, len) { const skiptable = new Array(); - val.forEach(function(element, index) { + val.forEach((element, index) => { skiptable[element] = len - index; }); return skiptable; @@ -189,8 +190,8 @@ export default class Stream { found = true; // Loop through the elements comparing them to val. - for (let x = length-1; x+1; x--) { - if (this.bytes[(this.position-length) + x] !== val[x]) { + for (let x = length-1; x > -1; x--) { + if (this.bytes[this.position-length + x] !== val[x]) { found = false; // If element is not equal to val's element then jump forward by the correct amount. @@ -199,7 +200,7 @@ export default class Stream { } } if (found) { - this.position = (this.position - length); + this.position -= length; break; } } @@ -209,10 +210,11 @@ export default class Stream { /** * Consume bytes if it matches the supplied value. * - * @param val + * @param {Number} val */ consumeWhile(val) { - while ((this.position < this.length) && (this.bytes[this.position++] === val)); + while ((this.position < this.length) && (this.bytes[(this.position++)] === val)) + this.position--; } /**