Convert src/core/ascii_hex_stream.js to use standard classes

This commit is contained in:
Jonas Jenwald 2021-04-27 13:17:24 +02:00
parent 59591f8788
commit d2227a7d10

View File

@ -15,25 +15,22 @@
import { DecodeStream } from "./stream.js"; import { DecodeStream } from "./stream.js";
const AsciiHexStream = (function AsciiHexStreamClosure() { class AsciiHexStream extends DecodeStream {
// eslint-disable-next-line no-shadow constructor(str, maybeLength) {
function AsciiHexStream(str, maybeLength) {
this.str = str;
this.dict = str.dict;
this.firstDigit = -1;
// Most streams increase in size when decoded, but AsciiHex streams shrink // Most streams increase in size when decoded, but AsciiHex streams shrink
// by 50%. // by 50%.
if (maybeLength) { if (maybeLength) {
maybeLength = 0.5 * 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); readBlock() {
AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
const UPSTREAM_BLOCK_SIZE = 8000; const UPSTREAM_BLOCK_SIZE = 8000;
const bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE); const bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
if (!bytes.length) { if (!bytes.length) {
@ -46,8 +43,7 @@ const AsciiHexStream = (function AsciiHexStreamClosure() {
let bufferLength = this.bufferLength; let bufferLength = this.bufferLength;
let firstDigit = this.firstDigit; let firstDigit = this.firstDigit;
for (let i = 0, ii = bytes.length; i < ii; i++) { for (const ch of bytes) {
const ch = bytes[i];
let digit; let digit;
if (ch >= /* '0' = */ 0x30 && ch <= /* '9' = */ 0x39) { if (ch >= /* '0' = */ 0x30 && ch <= /* '9' = */ 0x39) {
digit = ch & 0x0f; digit = ch & 0x0f;
@ -77,9 +73,7 @@ const AsciiHexStream = (function AsciiHexStreamClosure() {
} }
this.firstDigit = firstDigit; this.firstDigit = firstDigit;
this.bufferLength = bufferLength; this.bufferLength = bufferLength;
}; }
}
return AsciiHexStream;
})();
export { AsciiHexStream }; export { AsciiHexStream };