Skip to content

Instantly share code, notes, and snippets.

@neovov
Created February 13, 2017 17:13
Show Gist options
  • Save neovov/2abd0bcfaebc153248afa932dd86e4dd to your computer and use it in GitHub Desktop.
Save neovov/2abd0bcfaebc153248afa932dd86e4dd to your computer and use it in GitHub Desktop.
TransformStream
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