* Flushes the pending buffer into the given output array. If the * output array is to small, only a partial flush is done. * @param output The output array. * @param offset The offset into output array. * @param length The maximum number of bytes to store. * @returns The nu
(output: Uint8Array, offset: number, length: number)
| 98 | * @returns The number of bytes flushed. |
| 99 | */ |
| 100 | public flush(output: Uint8Array, offset: number, length: number) { |
| 101 | if (this.bitCount >= 8) { |
| 102 | this._buffer[this._end++] = this._bits & 0xff; |
| 103 | this._bits >>= 8; |
| 104 | this.bitCount -= 8; |
| 105 | } |
| 106 | |
| 107 | if (length > this._end - this._start) { |
| 108 | length = this._end - this._start; |
| 109 | output.set(this._buffer.subarray(this._start, this._start + length), offset); |
| 110 | this._start = 0; |
| 111 | this._end = 0; |
| 112 | } else { |
| 113 | output.set(this._buffer.subarray(this._start, this._start + length), offset); |
| 114 | this._start += length; |
| 115 | } |
| 116 | return length; |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * Write bits to internal buffer |