Skip to content

Instantly share code, notes, and snippets.

@nikmd23
Last active April 9, 2020 20:57
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save nikmd23/3439f031b88519f77dcccf1e25f3b270 to your computer and use it in GitHub Desktop.
Basic Implementation of a Transform (Pass-through) Stream
function TransformStream() {
var readableController,
writableController,
readable = new ReadableStream({
start(controller) {
readableController = controller;
},
cancel(reason) {
writableController.error(reason);
}
}),
writable = new WritableStream({
start(controller) {
writableController = controller;
},
write(chunk) {
readableController.enqueue(chunk);
},
close() {
readableController.close();
},
abort(reason) {
readableController.error(reason);
}
});
return {
readable: readable,
readableController: readableController,
writable: writable,
writableController: writableController
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment