MCPcopy Create free account
hub / github.com/CoderLine/alphaTab / Inflate

Class Inflate

packages/alphatab/src/zip/Inflate.ts:93–407  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

91 * @internal
92 */
93export class Inflate {
94 private static _lenExtraBitsTbl: number[] = [
95 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, -1, -1
96 ];
97 private static _lenBaseValTbl: number[] = [
98 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227,
99 258
100 ];
101 private static _distExtraBitsTbl: number[] = [
102 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, -1, -1
103 ];
104 private static _distBaseValTbl: number[] = [
105 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097,
106 6145, 8193, 12289, 16385, 24577
107 ];
108 private static _codeLengthsPos: number[] = [16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15];
109
110 private static _fixedHuffman: Huffman = Inflate._buildFixedHuffman();
111
112 private static _buildFixedHuffman(): Huffman {
113 const a: number[] = [];
114 for (let n: number = 0; n < 288; n++) {
115 a.push(n <= 143 ? 8 : n <= 255 ? 9 : n <= 279 ? 7 : 8);
116 }
117 return HuffTools.make(a, 0, 288, 10);
118 }
119
120 private _nbits: number = 0;
121 private _bits: number = 0;
122 private _state: InflateState = InflateState.Block;
123 private _isFinal: boolean = false;
124 private _huffman: Huffman = Inflate._fixedHuffman;
125 private _huffdist: Huffman | null = null;
126 private _len: number = 0;
127 private _dist: number = 0;
128 private _needed: number = 0;
129 private _output: Uint8Array | null = null;
130 private _outpos: number = 0;
131 private _input: IReadable;
132 private _lengths: number[] = [];
133 private _window: InflateWindow = new InflateWindow();
134
135 public constructor(readable: IReadable) {
136 this._input = readable;
137 for (let i: number = 0; i < 19; i++) {
138 this._lengths.push(-1);
139 }
140 }
141
142 public readBytes(b: Uint8Array, pos: number, len: number): number {
143 this._needed = len;
144 this._outpos = pos;
145 this._output = b;
146 if (len > 0) {
147 while (this._inflateLoop()) {
148 // inflating...
149 }
150 }

Callers

nothing calls this directly

Calls 1

_buildFixedHuffmanMethod · 0.80

Tested by

no test coverage detected