* Write tree values * @param blTree Tree to write
(blTree: Tree)
| 389 | * @param blTree Tree to write |
| 390 | */ |
| 391 | public writeTree(blTree: Tree) { |
| 392 | let maxCount: number; // max repeat count |
| 393 | let minCount: number; // min repeat count |
| 394 | let count: number; // repeat count of the current code |
| 395 | let curlen = -1; // length of current code |
| 396 | |
| 397 | let i = 0; |
| 398 | while (i < this.numCodes) { |
| 399 | count = 1; |
| 400 | const nextlen = this.length![i]; |
| 401 | if (nextlen === 0) { |
| 402 | maxCount = 138; |
| 403 | minCount = 3; |
| 404 | } else { |
| 405 | maxCount = 6; |
| 406 | minCount = 3; |
| 407 | if (curlen !== nextlen) { |
| 408 | blTree.writeSymbol(nextlen); |
| 409 | count = 0; |
| 410 | } |
| 411 | } |
| 412 | curlen = nextlen; |
| 413 | i++; |
| 414 | |
| 415 | while (i < this.numCodes && curlen === this.length![i]) { |
| 416 | i++; |
| 417 | if (++count >= maxCount) { |
| 418 | break; |
| 419 | } |
| 420 | } |
| 421 | |
| 422 | if (count < minCount) { |
| 423 | while (count-- > 0) { |
| 424 | blTree.writeSymbol(curlen); |
| 425 | } |
| 426 | } else if (curlen !== 0) { |
| 427 | blTree.writeSymbol(Tree._repeat3To6); |
| 428 | this._huffman.pending.writeBits(count - 3, 2); |
| 429 | } else if (count <= 10) { |
| 430 | blTree.writeSymbol(Tree._repeat3To10); |
| 431 | this._huffman.pending.writeBits(count - 3, 3); |
| 432 | } else { |
| 433 | blTree.writeSymbol(Tree._repeat11To138); |
| 434 | this._huffman.pending.writeBits(count - 11, 7); |
| 435 | } |
| 436 | } |
| 437 | } |
| 438 | |
| 439 | public writeSymbol(code: number) { |
| 440 | this._huffman.pending.writeBits(this._codes![code] & 0xffff, this.length![code]); |
no test coverage detected