Compose web streams together
npm install s-composeCompose web streams together
``bash`
npm install s-compose
`js
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");
},
})
);
`
`js
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);
},
})
);
`
ts
function sCompose(...streams: TransformStream): TransformStream
``ts
function sCompose(...streams: TransformStream, sink: WritableStream): WritableStream
``ts
function sCompose(source: ReadableStream, ...streams: TransformStream): ReadableStream
``