Helpers for dealing with various forms of binary & object streams, using `AsyncIterator` as the canonical format.
npm install @rollingversions/git-streamsHelpers for dealing with various forms of binary & object streams, using AsyncIterator as the canonical format.
``ts`
function streamToAsyncIterator(
readable: NodeJS.ReadableStream | ReadableStream
): AsyncIterableIterator
Convert a binary NodeJS.ReadableStream or a browser ReadableStream into an AsyncIterableIterator
`ts`
function asyncIteratorToNodeStream(
iterator: AsyncIterableIterator
options?: {
highWaterMarkBytes?: number;
},
): NodeJS.ReadableStream;
Convert a AsyncIterableIterator into a binary NodeJS.ReadableStream
`ts`
function asyncIteratorToBrowserStream(
iterator: AsyncIterableIterator
options?: {highWaterMarkBytes?: number},
): ReadableStream
Convert a AsyncIterableIterator into a binary ReadableStream
`ts`
function asyncIteratorToStream(
iterator: AsyncIterableIterator
options?: {highWaterMarkBytes?: number},
): ReadableStream
If ReadableStream exists (i.e. in the browser), call asyncIteratorToBrowserStream, otherwise call asyncIteratorToNodeStream.
`ts`
function asyncIteratorToBuffer(
iterator: AsyncIterableIterator
): Promise
Gather all the data from an AsyncIterableIterator into a single concatenated Uint8Array.
`ts`
function asyncIteratorToArray
iterator: AsyncIterableIterator
): Promise
Collect all the values in an AsyncIterableIterator of objects into an array.
`ts`
function mergeAsyncIterator
...iterators: AsyncIterableIterator
): AsyncIterableIterator
Take a list of AsyncIterableIterator and merge them into a single one that returns the union of all values, interleaved in whatever order they are returned.
`ts`
function splitAsyncIterator
iterator: AsyncIterableIterator
...mappers: {
[key in keyof TOutput]: (v: TInput) => undefined | TOutput[key];
}
): {
[key in keyof TOutput]: AsyncIterableIterator
};
Take an AsyncIterableIterator and split the values into multiple separate streams according to a filtering/mapping function. N.B. you must consume values from all returned AsyncIterableIterator`s otherwise the others will stall.