()
| 152 | } |
| 153 | |
| 154 | private _inflateLoop(): boolean { |
| 155 | switch (this._state) { |
| 156 | case InflateState.Head: |
| 157 | const cmf: number = this._input.readByte(); |
| 158 | const cm: number = cmf & 15; |
| 159 | if (cm !== 8) { |
| 160 | throw new FormatError('Invalid data'); |
| 161 | } |
| 162 | const flg: number = this._input.readByte(); |
| 163 | // var fcheck = flg & 31; |
| 164 | const fdict: boolean = (flg & 32) !== 0; |
| 165 | // var flevel = flg >> 6; |
| 166 | if (((cmf << 8) + flg) % 31 !== 0) { |
| 167 | throw new FormatError('Invalid data'); |
| 168 | } |
| 169 | if (fdict) { |
| 170 | throw new FormatError('Unsupported dictionary'); |
| 171 | } |
| 172 | this._state = InflateState.Block; |
| 173 | return true; |
| 174 | case InflateState.Crc: |
| 175 | this._state = InflateState.Done; |
| 176 | return true; |
| 177 | case InflateState.Done: |
| 178 | // nothing |
| 179 | return false; |
| 180 | case InflateState.Block: |
| 181 | this._isFinal = this._getBit(); |
| 182 | switch (this._getBits(2)) { |
| 183 | case 0: |
| 184 | this._len = IOHelper.readUInt16LE(this._input); |
| 185 | const nlen: number = IOHelper.readUInt16LE(this._input); |
| 186 | if (nlen !== 0xffff - this._len) { |
| 187 | throw new FormatError('Invalid data'); |
| 188 | } |
| 189 | this._state = InflateState.Flat; |
| 190 | const r: boolean = this._inflateLoop(); |
| 191 | this._resetBits(); |
| 192 | return r; |
| 193 | case 1: |
| 194 | this._huffman = Inflate._fixedHuffman; |
| 195 | this._huffdist = null; |
| 196 | this._state = InflateState.CData; |
| 197 | return true; |
| 198 | case 2: |
| 199 | const hlit: number = this._getBits(5) + 257; |
| 200 | const hdist: number = this._getBits(5) + 1; |
| 201 | const hclen: number = this._getBits(4) + 4; |
| 202 | for (let i: number = 0; i < hclen; i++) { |
| 203 | this._lengths[Inflate._codeLengthsPos[i]] = this._getBits(3); |
| 204 | } |
| 205 | for (let i: number = hclen; i < 19; i++) { |
| 206 | this._lengths[Inflate._codeLengthsPos[i]] = 0; |
| 207 | } |
| 208 | this._huffman = HuffTools.make(this._lengths, 0, 19, 8); |
| 209 | const xlengths: number[] = []; |
| 210 | for (let i: number = 0; i < hlit + hdist; i++) { |
| 211 | xlengths.push(0); |
no test coverage detected