From d2227a7d105a7830fa8a5561b83f5093f3ecdd02 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 27 Apr 2021 13:17:24 +0200 Subject: [PATCH] Convert `src/core/ascii_hex_stream.js` to use standard classes --- src/core/ascii_hex_stream.js | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/src/core/ascii_hex_stream.js b/src/core/ascii_hex_stream.js index 07d1ee6f0..69e902171 100644 --- a/src/core/ascii_hex_stream.js +++ b/src/core/ascii_hex_stream.js @@ -15,25 +15,22 @@ import { DecodeStream } from "./stream.js"; -const AsciiHexStream = (function AsciiHexStreamClosure() { - // eslint-disable-next-line no-shadow - function AsciiHexStream(str, maybeLength) { - this.str = str; - this.dict = str.dict; - - this.firstDigit = -1; - +class AsciiHexStream extends DecodeStream { + constructor(str, maybeLength) { // Most streams increase in size when decoded, but AsciiHex streams shrink // by 50%. if (maybeLength) { maybeLength = 0.5 * maybeLength; } - DecodeStream.call(this, maybeLength); + super(maybeLength); + + this.str = str; + this.dict = str.dict; + + this.firstDigit = -1; } - AsciiHexStream.prototype = Object.create(DecodeStream.prototype); - - AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() { + readBlock() { const UPSTREAM_BLOCK_SIZE = 8000; const bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE); if (!bytes.length) { @@ -46,8 +43,7 @@ const AsciiHexStream = (function AsciiHexStreamClosure() { let bufferLength = this.bufferLength; let firstDigit = this.firstDigit; - for (let i = 0, ii = bytes.length; i < ii; i++) { - const ch = bytes[i]; + for (const ch of bytes) { let digit; if (ch >= /* '0' = */ 0x30 && ch <= /* '9' = */ 0x39) { digit = ch & 0x0f; @@ -77,9 +73,7 @@ const AsciiHexStream = (function AsciiHexStreamClosure() { } this.firstDigit = firstDigit; this.bufferLength = bufferLength; - }; - - return AsciiHexStream; -})(); + } +} export { AsciiHexStream };