match-stream
Match a pattern within a stream
Last updated 13 years ago by evanoxfeld .
MIT · Repository · Original npm · Tarball · package.json
$ cnpm install match-stream 
SYNC missed versions from official npm registry.

match-stream Build Status

Supply a function to handle pattern matches within a NodeJS stream.

Installation

$ npm install match-stream

Quick Example

var MatchStream = require('match-stream');
var streamBuffers = require("stream-buffers");

var ms = new MatchStream({ pattern: 'World'}, function (buf, matched, extra) {
  if (!matched) {
    return this.push(buf);
  }
  this.push(buf);
  return this.push(null); //end the stream
});

var sourceStream = new streamBuffers.ReadableStreamBuffer();
sourceStream.put("Hello World");
var writableStream = new streamBuffers.WritableStreamBuffer();

sourceStream
  .pipe(ms)
  .pipe(writableStream)
  .once('close', function () {
    var str = writableStream.getContentsAsString('utf8');
    console.log('Piped data before pattern occurs:', "'" + str + "'");
    sourceStream.destroy();
  });

//Output
//Piped data before pattern occurs: 'Hello '

License

MIT

Acknowledgements

Special thanks to @wanderview for assisting with the API.

Current Tags

  • 0.0.2                                ...           latest (13 years ago)

3 Versions

  • 0.0.2                                ...           13 years ago
  • 0.0.1                                ...           13 years ago
  • 0.0.0                                ...           13 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (2)
Dev Dependencies (2)

Copyright 2013 - present © cnpmjs.org | Home |