Download src/lib/utils/streamToAsyncIterable.ts from WOosts/chat-ui: direct link, hf CLI and curl.
- Browser
- Download file 439 Bytes
-
https://huggingface.co/spaces/WOosts/chat-ui/resolve/main/src/lib/utils/streamToAsyncIterable.ts
- Command line
-
hf download hf://spaces/WOosts/chat-ui/src/lib/utils/streamToAsyncIterable.ts
-
curl -L -o streamToAsyncIterable.ts https://huggingface.co/spaces/WOosts/chat-ui/resolve/main/src/lib/utils/streamToAsyncIterable.ts
439 Bytes
| // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of#iterating_over_async_generators | |
| export async function* streamToAsyncIterable( | |
| stream: ReadableStream<Uint8Array> | |
| ): AsyncIterableIterator<Uint8Array> { | |
| const reader = stream.getReader(); | |
| try { | |
| while (true) { | |
| const { done, value } = await reader.read(); | |
| if (done) return; | |
| yield value; | |
| } | |
| } finally { | |
| reader.releaseLock(); | |
| } | |
| } | |