(flush: boolean, finish: boolean)
| 196 | } |
| 197 | |
| 198 | private _deflateSlow(flush: boolean, finish: boolean): boolean { |
| 199 | if (this._lookahead < DeflaterConstants.minLookahead && !flush) { |
| 200 | return false; |
| 201 | } |
| 202 | |
| 203 | while (this._lookahead >= DeflaterConstants.minLookahead || flush) { |
| 204 | if (this._lookahead === 0) { |
| 205 | if (this._prevAvailable) { |
| 206 | this._huffman.tallyLit(this._window[this._strstart - 1] & 0xff); |
| 207 | } |
| 208 | this._prevAvailable = false; |
| 209 | |
| 210 | // We are flushing everything |
| 211 | this._huffman.flushBlock(this._window, this._blockStart, this._strstart - this._blockStart, finish); |
| 212 | this._blockStart = this._strstart; |
| 213 | return false; |
| 214 | } |
| 215 | |
| 216 | if (this._strstart >= 2 * DeflaterConstants.wsize - DeflaterConstants.minLookahead) { |
| 217 | /* slide window, as FindLongestMatch needs this. |
| 218 | * This should only happen when flushing and the window |
| 219 | * is almost full. |
| 220 | */ |
| 221 | this._slideWindow(); |
| 222 | } |
| 223 | |
| 224 | const prevMatch = this._matchStart; |
| 225 | let prevLen = this._matchLen; |
| 226 | if (this._lookahead >= DeflaterConstants.minMatch) { |
| 227 | const hashHead = this._insertString(); |
| 228 | |
| 229 | if ( |
| 230 | hashHead !== 0 && |
| 231 | this._strstart - hashHead <= DeflaterConstants.maxDist && |
| 232 | this._findLongestMatch(hashHead) |
| 233 | ) { |
| 234 | // longestMatch sets matchStart and matchLen |
| 235 | |
| 236 | // Discard match if too small and too far away |
| 237 | if ( |
| 238 | this._matchLen === DeflaterConstants.minMatch && |
| 239 | this._strstart - this._matchStart > DeflaterEngine._tooFar |
| 240 | ) { |
| 241 | this._matchLen = DeflaterConstants.minMatch - 1; |
| 242 | } |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | // previous match was better |
| 247 | if (prevLen >= DeflaterConstants.minMatch && this._matchLen <= prevLen) { |
| 248 | this._huffman.tallyDist(this._strstart - 1 - prevMatch, prevLen); |
| 249 | prevLen -= 2; |
| 250 | do { |
| 251 | this._strstart++; |
| 252 | this._lookahead--; |
| 253 | if (this._lookahead >= DeflaterConstants.minMatch) { |
| 254 | this._insertString(); |
| 255 | } |
no test coverage detected