New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to keep the original stream data unchanged? #108

Closed
ahrtr opened this Issue Apr 10, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@ahrtr

ahrtr commented Apr 10, 2018

I am using event-stream to process a http request payload. The payload is a JSON stream (new line separated JSON), and I want to extract all the interested fields. The code is something like below,

import JSONStream from 'JSONStream';
import eventStream from 'event-stream';

async function processPayload(request) {
    const payload = request.payload;
    let indexArray = [];
    await eventStream.pipeline(
        payload, 
        JSONStream.parse(['test']),
        eventStream.mapSync(function(data){
            indexArray.push(data);
        })
    );
    return indexArray;
}

Basically the above code works well. But the issue is that it modifies the original payload, so the following operation which depends on the payload as well fails. How can I keep the original data being unchanged? Thanks!

@right9ctrl

This comment has been minimized.

Collaborator

right9ctrl commented Sep 6, 2018

@ahrtr Can you pipe the request payload into two streams? See #12

@right9ctrl right9ctrl closed this Sep 16, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment