UNPKG

sflow

Version:

sflow is a powerful and highly-extensible library designed for processing and manipulating streams of data effortlessly. Inspired by the functional programming paradigm, it provides a rich set of utilities for transforming streams, including chunking, fil

16 lines (14 loc) 548 B
import { throughs } from "./throughs"; /** pipe upstream through a PortalStream, aka. TransformStream<T, T> */ export const portals: { <T>(stream?: TransformStream<T, T>): TransformStream<T, T>; <T>( fn: (s: ReadableStream<T>) => ReadableStream<T> ): TransformStream<T, T>; } = (arg: any) => { if (!arg) return new TransformStream(); if (typeof arg !== "function") return throughs((s) => s.pipeThrough(arg)); const fn = arg; const { writable, readable } = new TransformStream(); return { writable, readable: fn(readable) }; };