ts-ignore to fix type error
This commit is contained in:
parent
a8e5bbfd28
commit
60be949c23
1 changed files with 10 additions and 3 deletions
|
|
@ -1,10 +1,15 @@
|
|||
async function* toAsyncIterable(nodeReadable: NodeJS.ReadableStream): AsyncGenerator<Uint8Array> {
|
||||
async function* toAsyncIterable(
|
||||
nodeReadable: NodeJS.ReadableStream,
|
||||
): AsyncGenerator<Uint8Array> {
|
||||
for await (const chunk of nodeReadable) {
|
||||
// @ts-ignore
|
||||
yield chunk as Uint8Array;
|
||||
}
|
||||
}
|
||||
|
||||
export async function* streamResponse(response: Response): AsyncGenerator<string> {
|
||||
export async function* streamResponse(
|
||||
response: Response,
|
||||
): AsyncGenerator<string> {
|
||||
if (response.status !== 200) {
|
||||
throw new Error(await response.text());
|
||||
}
|
||||
|
|
@ -19,7 +24,9 @@ export async function* streamResponse(response: Response): AsyncGenerator<string
|
|||
if (nodeMajorVersion >= 20) {
|
||||
// Use the new API for Node 20 and above
|
||||
const stream = (ReadableStream as any).from(response.body);
|
||||
for await (const chunk of stream.pipeThrough(new TextDecoderStream("utf-8"))) {
|
||||
for await (const chunk of stream.pipeThrough(
|
||||
new TextDecoderStream("utf-8"),
|
||||
)) {
|
||||
yield chunk;
|
||||
}
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue