package.dist-es.splitStream.js Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of util-stream Show documentation
Show all versions of util-stream Show documentation
[![NPM version](https://img.shields.io/npm/v/@smithy/util-stream/latest.svg)](https://www.npmjs.com/package/@smithy/util-stream) [![NPM downloads](https://img.shields.io/npm/dm/@smithy/util-stream.svg)](https://www.npmjs.com/package/@smithy/util-stream)
The newest version!
import { PassThrough } from "stream";
import { splitStream as splitWebStream } from "./splitStream.browser";
import { isReadableStream } from "./stream-type-check";
export async function splitStream(stream) {
if (isReadableStream(stream)) {
return splitWebStream(stream);
}
const stream1 = new PassThrough();
const stream2 = new PassThrough();
stream.pipe(stream1);
stream.pipe(stream2);
return [stream1, stream2];
}