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

This commit is contained in:
Jonas Jenwald 2021-04-27 13:53:36 +02:00
parent aa1deaf93c
commit 213e1c389c

View File

@ -22,7 +22,6 @@
import { DecodeStream } from "./stream.js"; import { DecodeStream } from "./stream.js";
import { FormatError } from "../shared/util.js"; import { FormatError } from "../shared/util.js";
const FlateStream = (function FlateStreamClosure() {
// prettier-ignore // prettier-ignore
const codeLenCodeMap = new Int32Array([ const codeLenCodeMap = new Int32Array([
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
@ -120,8 +119,10 @@ const FlateStream = (function FlateStreamClosure() {
0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000
]), 5]; ]), 5];
// eslint-disable-next-line no-shadow class FlateStream extends DecodeStream {
function FlateStream(str, maybeLength) { constructor(str, maybeLength) {
super(maybeLength);
this.str = str; this.str = str;
this.dict = str.dict; this.dict = str.dict;
@ -144,13 +145,9 @@ const FlateStream = (function FlateStreamClosure() {
this.codeSize = 0; this.codeSize = 0;
this.codeBuf = 0; this.codeBuf = 0;
DecodeStream.call(this, maybeLength);
} }
FlateStream.prototype = Object.create(DecodeStream.prototype); getBits(bits) {
FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
const str = this.str; const str = this.str;
let codeSize = this.codeSize; let codeSize = this.codeSize;
let codeBuf = this.codeBuf; let codeBuf = this.codeBuf;
@ -168,9 +165,9 @@ const FlateStream = (function FlateStreamClosure() {
this.codeSize = codeSize -= bits; this.codeSize = codeSize -= bits;
return b; return b;
}; }
FlateStream.prototype.getCode = function FlateStream_getCode(table) { getCode(table) {
const str = this.str; const str = this.str;
const codes = table[0]; const codes = table[0];
const maxLen = table[1]; const maxLen = table[1];
@ -196,11 +193,9 @@ const FlateStream = (function FlateStreamClosure() {
this.codeBuf = codeBuf >> codeLen; this.codeBuf = codeBuf >> codeLen;
this.codeSize = codeSize - codeLen; this.codeSize = codeSize - codeLen;
return codeVal; return codeVal;
}; }
FlateStream.prototype.generateHuffmanTable = function flateStreamGenerateHuffmanTable( generateHuffmanTable(lengths) {
lengths
) {
const n = lengths.length; const n = lengths.length;
// find max code length // find max code length
@ -240,9 +235,9 @@ const FlateStream = (function FlateStreamClosure() {
} }
return [codes, maxLen]; return [codes, maxLen];
}; }
FlateStream.prototype.readBlock = function FlateStream_readBlock() { readBlock() {
let buffer, len; let buffer, len;
const str = this.str; const str = this.str;
// read block header // read block header
@ -400,9 +395,7 @@ const FlateStream = (function FlateStreamClosure() {
buffer[pos] = buffer[pos - dist]; buffer[pos] = buffer[pos - dist];
} }
} }
}; }
}
return FlateStream;
})();
export { FlateStream }; export { FlateStream };