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

Method deflate

packages/alphatab/src/zip/Deflater.ts:152–199  ·  view source on GitHub ↗

* Deflates the current input block to the given array. * @param output Buffer to store the compressed data. * @param offset Offset into the output array. * @param length The maximum number of bytes that may be stored. * @returns The number of compressed bytes added to the output,

(output: Uint8Array, offset: number, length: number)

Source from the content-addressed store, hash-verified

150 * needsInput() or finished() returns true or length is zero.
151 */
152 public deflate(output: Uint8Array, offset: number, length: number): number {
153 const origLength = length;
154
155 while (true) {
156 const count = this._pending.flush(output, offset, length);
157 offset += count;
158 length -= count;
159
160 if (length === 0 || this._state === Deflater._finishedState) {
161 break;
162 }
163
164 if (
165 !this._engine.deflate(
166 (this._state & Deflater._isFlushing) !== 0,
167 (this._state & Deflater.isFinishing) !== 0
168 )
169 ) {
170 switch (this._state) {
171 case Deflater._busyState:
172 // We need more input now
173 return origLength - length;
174
175 case Deflater._flushingState:
176 /* We have to supply some lookahead. 8 bit lookahead
177 * is needed by the zlib inflater, and we must fill
178 * the next byte, so that all bits are flushed.
179 */
180 let neededbits = 8 + (-this._pending.bitCount & 7);
181 while (neededbits > 0) {
182 /* write a static tree block consisting solely of
183 * an EOF:
184 */
185 this._pending.writeBits(2, 10);
186 neededbits -= 10;
187 }
188 this._state = Deflater._busyState;
189 break;
190
191 case Deflater._finishingState:
192 this._pending.alignToByte();
193 this._state = Deflater._finishedState;
194 break;
195 }
196 }
197 }
198 return origLength - length;
199 }
200
201 /**
202 * Finishes the deflater with the current input block. It is an error

Callers 1

_compressMethod · 0.45

Calls 3

flushMethod · 0.80
writeBitsMethod · 0.80
alignToByteMethod · 0.80

Tested by

no test coverage detected