Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

match-stream

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

match-stream

Match a pattern within a stream

  • 0.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

match-stream Build Status

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

Installation

$ npm install match-stream

Quick Examples

End stream on match

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); //signal end of data
});

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 '

Split stream

var MatchStream = require('match-stream');
var fs = require('fs');

var line = "";
var loremLines = [];
var ms = new MatchStream({ pattern: '.', consume: true}, function (buf, matched, extra) {
  line += buf.toString();
  if (matched) {
    loremLines.push(line.trim());
    line = "";
  }
});

fs.createReadStream('lorem.txt')
  .pipe(ms)
  .once('finish', function() {
    console.log(loremLines);
  });

License

MIT

Acknowledgements

Special thanks to @wanderview for assisting with the API.

Keywords

FAQs

Package last updated on 04 Apr 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc