Match a pattern within a stream
Supply a function to handle pattern matches within a NodeJS stream.
$ npm install match-stream
var MatchStream = require'match-stream';var streamBuffers = require"stream-buffers";var ms = pattern: 'World'if !matchedreturn thispushbuf;thispushbuf;return thispushnull; //end the stream;var sourceStream = ;sourceStreamput"Hello World";var writableStream = ;sourceStreampipemspipewritableStreamonce'close'var str = writableStreamgetContentsAsString'utf8';console.log'Piped data before pattern occurs:' "'" + str + "'";sourceStreamdestroy;;//Output//Piped data before pattern occurs: 'Hello '
Special thanks to @wanderview for assisting with the API.