until-stream
A PassThrough stream that stops piping when a pattern is reached
Last updated 14 years ago by evanoxfeld .
MIT · Repository · Original npm · Tarball · package.json
$ npm install until-stream 
SYNC missed versions from official npm registry.

until-stream Build Status

Ever wanted to pause a stream when a certain String or a binary signature is reached? Until-Stream is the answer. Pipe Until-Stream and automatically stop when your pattern is reached or call read() until the returned data matches your pattern.

Stability - API is somewhat unstable
read() and pipe() are implemented with some limitations. For example, Until-Stream supports piping to only a single destination stream.

Installation

$ npm install until-stream

Quick Examples

Pipe

var UntilStream = require('until-stream');
var streamBuffers = require("stream-buffers");

var us = new UntilStream({ pattern: 'World'});

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

sourceStream.pipe(us).pipe(writableStream);

writableStream.once('close', function () {
  //writeableStream contains all data before the pattern occurs
  var str = writableStream.getContentsAsString('utf8'); // 'Hello '
  //Now the next call to read() returns the pattern
  var data = us.read(); // 'World'
});

Read

var UntilStream = require('until-stream');
var streamBuffers = require("stream-buffers");

var us = new UntilStream({ pattern: 'jumps'});

var sourceStream = new streamBuffers.ReadableStreamBuffer({ chunkSize: 8 });
sourceStream.put("The quick brown fox jumps over the lazy dog");

sourceStream.pipe(us);

us.on('readable', function() {
  if (us.read() === 'jumps') {
    console.log('Pattern reached!');
  }
});

License

MIT

Current Tags

  • 0.2.2                                ...           latest (14 years ago)

6 Versions

  • 0.2.2                                ...           14 years ago
  • 0.2.1                                ...           14 years ago
  • 0.2.0                                ...           14 years ago
  • 0.1.1                                ...           14 years ago
  • 0.1.0                                ...           14 years ago
  • 0.0.0                                ...           14 years ago
Maintainers (1)
Downloads
Total 14
Today 0
This Week 0
This Month 7
Last Day 0
Last Week 0
Last Month 1
Dependencies (3)
Dev Dependencies (2)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE