1.0.1 • Published 6 months ago

s-compose v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

s-compose

Compose web streams together

Installation

npm install s-compose

Usage

Compose multiple TransformStreams into a single TransformStream

import sCompose from "s-compose";

// transform a string by appending "a" and then "b"
const transform = sCompose(
  new TransformStream({
    transform(chunk, controller) {
      controller.enqueue(chunk + "a");
    },
  }),
  new TransformStream({
    transform(chunk, controller) {
      controller.enqueue(chunk + "b");
    },
  })
);

Prepend a TransformStream to a WritableStream

import sCompose from "s-compose";
import sBatch from "s-batch";

// create a writable stream that batches up items and then uploads them to an API in bulk
const writable = sCompose(
  sBatch(100),
  new WritableStream({
    async write(chunks) {
      await api.bulkUpload(chunks);
    },
  })
);

API

function sCompose(...streams: TransformStream): TransformStream
function sCompose(...streams: TransformStream, sink: WritableStream): WritableStream
function sCompose(source: ReadableStream, ...streams: TransformStream): ReadableStream
1.0.1

6 months ago

1.0.0

6 months ago