Last active
April 9, 2020 20:57
-
-
Save nikmd23/3439f031b88519f77dcccf1e25f3b270 to your computer and use it in GitHub Desktop.
Basic Implementation of a Transform (Pass-through) Stream
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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