Created
February 13, 2017 17:13
-
-
Save neovov/2abd0bcfaebc153248afa932dd86e4dd to your computer and use it in GitHub Desktop.
TransformStream
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
const source = new ReadableStream({…}); // As seen above | |
const destination = new WritableStream({…}); // As seen above | |
const transformer = new TransformStream({ | |
transform(chunk, controller) { | |
// Simply increment each bytes | |
const transformed = chunk.map(value => Math.min(value + 1, 255)); | |
// Enqueue the transformed data | |
controller.enqueue(transformed); | |
} | |
}); | |
source | |
.pipeThrough(transformer); | |
.pipeTo(destination); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment