Skip to content

Instantly share code, notes, and snippets.

@jakearchibald jakearchibald/parse-json.js Secret
Last active Nov 29, 2017

What would you like to do?
export default function parseJSON() {
return new TransformStream({
transform(chunk, controller) {
export default function splitStream(splitOn) {
let buffer = '';
return new TransformStream({
transform(chunk, controller) {
buffer += chunk;
const parts = buffer.split(splitOn);
parts.slice(0, -1).forEach(part => controller.enqueue(part));
buffer = parts[parts.length - 1];
flush(controller) {
if (buffer) controller.enqueue(buffer);

This comment has been minimized.

Copy link

jfbrennan commented Nov 16, 2017

return new TransformStream() <-- you're instantiating one of these I can't find anything on the web about those... People write about streams, but I can't find any other examples of TransformStream or their current support.

Was reading this and came here to learn. Can you explain more?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.