# match-stream

> Match a pattern within a stream

Latest version **0.0.2** (published 2013-04-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install match-stream
pnpm add match-stream
yarn add match-stream
bun add match-stream
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.2 |
| Published | 2013-04-04 |
| First published | 2013-03-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 11 |
| Author | Evan Oxfeld |
| Maintainers | evanoxfeld |
| Keywords | match, stream, split |

## Links

- npm: https://www.npmjs.com/package/match-stream
- Repository: https://github.com/EvanOxfeld/match-stream
- npm.io page: https://npm.io/package/match-stream

## Dependencies (2)

- [buffers](https://npm.io/package/buffers.md) ~0.1.1
- [readable-stream](https://npm.io/package/readable-stream.md) ~1.0.0

## Alternatives

- [byte-size](https://npm.io/package/byte-size.md) — 2.1M weekly downloads
- [speed-limiter](https://npm.io/package/speed-limiter.md) — 16.0K weekly downloads
- [@powersync/node](https://npm.io/package/@powersync/node.md) — 10.9K weekly downloads
- [@ledgerhq/coin-cardano](https://npm.io/package/@ledgerhq/coin-cardano.md) — 1.0K weekly downloads
- [@jayesol/jayeson.lib.streamfinder](https://npm.io/package/@jayesol/jayeson.lib.streamfinder.md) — 1.0K weekly downloads

## Recent versions

- 0.0.2 (latest) — 2013-04-04
- 0.0.1 — 2013-03-10
- 0.0.0 — 2013-03-10

## README

match-stream [![Build Status](https://travis-ci.org/EvanOxfeld/match-stream.png)](https://travis-ci.org/EvanOxfeld/match-stream)
============

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

## Installation

```bash
$ npm install match-stream
```

## Quick Examples

### End stream on match

```javascript
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

```javascript
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.

---
_Source: https://npm.io/package/match-stream · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
