Convert src/core/flate_stream.js
to use standard classes
This commit is contained in:
parent
aa1deaf93c
commit
213e1c389c
@ -22,30 +22,29 @@
|
||||
import { DecodeStream } from "./stream.js";
|
||||
import { FormatError } from "../shared/util.js";
|
||||
|
||||
const FlateStream = (function FlateStreamClosure() {
|
||||
// prettier-ignore
|
||||
const codeLenCodeMap = new Int32Array([
|
||||
// prettier-ignore
|
||||
const codeLenCodeMap = new Int32Array([
|
||||
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
|
||||
]);
|
||||
]);
|
||||
|
||||
// prettier-ignore
|
||||
const lengthDecode = new Int32Array([
|
||||
// prettier-ignore
|
||||
const lengthDecode = new Int32Array([
|
||||
0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a,
|
||||
0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f,
|
||||
0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073,
|
||||
0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102
|
||||
]);
|
||||
]);
|
||||
|
||||
// prettier-ignore
|
||||
const distDecode = new Int32Array([
|
||||
// prettier-ignore
|
||||
const distDecode = new Int32Array([
|
||||
0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d,
|
||||
0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1,
|
||||
0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01,
|
||||
0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001
|
||||
]);
|
||||
]);
|
||||
|
||||
// prettier-ignore
|
||||
const fixedLitCodeTab = [new Int32Array([
|
||||
// prettier-ignore
|
||||
const fixedLitCodeTab = [new Int32Array([
|
||||
0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0,
|
||||
0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0,
|
||||
0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0,
|
||||
@ -110,18 +109,20 @@ const FlateStream = (function FlateStreamClosure() {
|
||||
0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef,
|
||||
0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df,
|
||||
0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff
|
||||
]), 9];
|
||||
]), 9];
|
||||
|
||||
// prettier-ignore
|
||||
const fixedDistCodeTab = [new Int32Array([
|
||||
// prettier-ignore
|
||||
const fixedDistCodeTab = [new Int32Array([
|
||||
0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c,
|
||||
0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000,
|
||||
0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d,
|
||||
0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000
|
||||
]), 5];
|
||||
]), 5];
|
||||
|
||||
class FlateStream extends DecodeStream {
|
||||
constructor(str, maybeLength) {
|
||||
super(maybeLength);
|
||||
|
||||
// eslint-disable-next-line no-shadow
|
||||
function FlateStream(str, maybeLength) {
|
||||
this.str = str;
|
||||
this.dict = str.dict;
|
||||
|
||||
@ -144,13 +145,9 @@ const FlateStream = (function FlateStreamClosure() {
|
||||
|
||||
this.codeSize = 0;
|
||||
this.codeBuf = 0;
|
||||
|
||||
DecodeStream.call(this, maybeLength);
|
||||
}
|
||||
|
||||
FlateStream.prototype = Object.create(DecodeStream.prototype);
|
||||
|
||||
FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
|
||||
getBits(bits) {
|
||||
const str = this.str;
|
||||
let codeSize = this.codeSize;
|
||||
let codeBuf = this.codeBuf;
|
||||
@ -168,9 +165,9 @@ const FlateStream = (function FlateStreamClosure() {
|
||||
this.codeSize = codeSize -= bits;
|
||||
|
||||
return b;
|
||||
};
|
||||
}
|
||||
|
||||
FlateStream.prototype.getCode = function FlateStream_getCode(table) {
|
||||
getCode(table) {
|
||||
const str = this.str;
|
||||
const codes = table[0];
|
||||
const maxLen = table[1];
|
||||
@ -196,11 +193,9 @@ const FlateStream = (function FlateStreamClosure() {
|
||||
this.codeBuf = codeBuf >> codeLen;
|
||||
this.codeSize = codeSize - codeLen;
|
||||
return codeVal;
|
||||
};
|
||||
}
|
||||
|
||||
FlateStream.prototype.generateHuffmanTable = function flateStreamGenerateHuffmanTable(
|
||||
lengths
|
||||
) {
|
||||
generateHuffmanTable(lengths) {
|
||||
const n = lengths.length;
|
||||
|
||||
// find max code length
|
||||
@ -240,9 +235,9 @@ const FlateStream = (function FlateStreamClosure() {
|
||||
}
|
||||
|
||||
return [codes, maxLen];
|
||||
};
|
||||
}
|
||||
|
||||
FlateStream.prototype.readBlock = function FlateStream_readBlock() {
|
||||
readBlock() {
|
||||
let buffer, len;
|
||||
const str = this.str;
|
||||
// read block header
|
||||
@ -400,9 +395,7 @@ const FlateStream = (function FlateStreamClosure() {
|
||||
buffer[pos] = buffer[pos - dist];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return FlateStream;
|
||||
})();
|
||||
}
|
||||
}
|
||||
|
||||
export { FlateStream };
|
||||
|
Loading…
Reference in New Issue
Block a user