dominictarr / JSONStream

rawStream.pipe(JSONStream.parse()).pipe(streamOfObjects)
Other
1.91k stars 165 forks source link

Is there a way to stop the stream? #146

Open Ninjaman494 opened 6 years ago

Ninjaman494 commented 6 years ago

Is there a way to stop parsing after you hit a certain value? For example:

 stream.on('data', function(data) {`
          if(data == 'someValue'){`
             stream.stop();
        }
    });

This would useful when you only need a certain value or you only need to check a specific number of entries.

dominictarr commented 6 years ago

no unfortunately node streams do not support that in a clean way. you could call source.destroy() but you'd have to call it on the real source, i.e. the file or the network connection.

dominictarr commented 6 years ago

this is why pull-streams have error propagation and abort: http://dominictarr.com/post/149248845122/pull-streams-pull-streams-are-a-very-simple