refactor(streams): prepare for noUncheckedIndexedAccess (#4377)

This commit is contained in:
Gabriele Belluardo 2024-02-24 21:22:50 +01:00 committed by GitHub
parent 58cb4ba9f3
commit 271a100e8f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 9 additions and 9 deletions

View File

@ -20,7 +20,7 @@ export function createLPS(pat: Uint8Array): Uint8Array {
lps[i] = 0;
i++;
} else {
prefixEnd = lps[prefixEnd - 1];
prefixEnd = lps[prefixEnd - 1]!;
}
}
return lps;

View File

@ -116,7 +116,7 @@ export class DelimiterStream extends TransformStream<Uint8Array, Uint8Array> {
// they are (with concatenation).
if (bufs.length === 1) {
// Concat not needed when a single buffer is passed.
controller.enqueue(bufs[0]);
controller.enqueue(bufs[0]!);
} else {
controller.enqueue(concat(bufs));
}
@ -134,7 +134,7 @@ export class DelimiterStream extends TransformStream<Uint8Array, Uint8Array> {
} else if (delimitedChunkEnd < 0 && bufs.length > 0) {
// Our chunk started by finishing a partial delimiter match.
const lastIndex = bufs.length - 1;
const last = bufs[lastIndex];
const last = bufs[lastIndex]!;
const lastSliceIndex = last.byteLength + delimitedChunkEnd;
const lastSliced = last.subarray(0, lastSliceIndex);
if (lastIndex === 0) {
@ -173,7 +173,7 @@ export class DelimiterStream extends TransformStream<Uint8Array, Uint8Array> {
// but now got a new 'A', then we'll drop down to having matched
// just 'A'. The while loop will turn around again and we'll rematch
// to 'AA' and proceed onwards to try and match on 'B' again.
matchIndex = lps[matchIndex - 1];
matchIndex = lps[matchIndex - 1]!;
}
}
// Save match index.
@ -231,7 +231,7 @@ export class DelimiterStream extends TransformStream<Uint8Array, Uint8Array> {
// they are (with concatenation).
if (bufs.length === 1) {
// Concat not needed when a single buffer is passed.
controller.enqueue(bufs[0]);
controller.enqueue(bufs[0]!);
} else {
controller.enqueue(concat(bufs));
}
@ -275,7 +275,7 @@ export class DelimiterStream extends TransformStream<Uint8Array, Uint8Array> {
if (length === 0) {
controller.enqueue(new Uint8Array());
} else if (length === 1) {
controller.enqueue(bufs[0]);
controller.enqueue(bufs[0]!);
} else {
controller.enqueue(concat(bufs));
}

View File

@ -40,9 +40,9 @@ export function mergeReadableStreams<T>(
}
controller.enqueue(data);
}
resolvePromises[index].resolve();
resolvePromises[index]!.resolve();
} catch (error) {
resolvePromises[index].reject(error);
resolvePromises[index]!.reject(error);
}
})();
}

View File

@ -73,7 +73,7 @@ export class TextDelimiterStream extends TransformStream<string, string> {
this.#inspectIndex++;
localIndex++;
} else {
this.#matchIndex = this.#delimLPS[this.#matchIndex - 1];
this.#matchIndex = this.#delimLPS[this.#matchIndex - 1]!;
}
}
}