UNPKG

@sap/generator-cap-project

Version:

Creates a new SAP Cloud Application Programming Model project.

22 lines (21 loc) 652 B
import { isFunction } from "./isFunction.js"; const isAsyncIterable = (value) => (isFunction(value[Symbol.asyncIterator])); async function* readStream(readable) { const reader = readable.getReader(); while (true) { const { done, value } = await reader.read(); if (done) { break; } yield value; } } export const getStreamIterator = (source) => { if (isAsyncIterable(source)) { return source; } if (isFunction(source.getReader)) { return readStream(source); } throw new TypeError("Unsupported data source: Expected either ReadableStream or async iterable."); };