Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
cool
Browse files Browse the repository at this point in the history
  • Loading branch information
KATT committed Oct 26, 2023
1 parent 94751a1 commit 4b0fe67
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/async/iterableUtils.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import { assert } from "../internals/assert.js";
import { WebReadableStreamEsque } from "../internals/esque.js";
import {
NodeJSReadableStreamEsque,
WebReadableStreamEsque,
} from "../internals/esque.js";

export async function* readableStreamToAsyncIterable<T>(
stream: NodeJS.ReadableStream | ReadableStream<T> | WebReadableStreamEsque,
stream:
| NodeJSReadableStreamEsque
| ReadableStream<T>
| WebReadableStreamEsque,
): AsyncIterable<T> {
if (!("getReader" in stream)) {
if (Symbol.asyncIterator in stream) {
// NodeJS.ReadableStream
for await (const chunk of stream) {
yield chunk as T;
Expand Down
7 changes: 7 additions & 0 deletions src/internals/esque.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,10 @@ export interface TextDecoderEsque {
export interface WebReadableStreamEsque {
getReader: () => ReadableStreamDefaultReader<Uint8Array>;
}

/**
* @see NodeJS.ReadableStream from @types/node
*/
export interface NodeJSReadableStreamEsque {
[Symbol.asyncIterator]: () => AsyncIterableIterator<Buffer | string>;
}

0 comments on commit 4b0fe67

Please sign in to comment.