until-stream
Ever wanted to pause a stream when a certain String or a binary signature is reached? UntilStream is the answer. Pipe UntilStream and automatically stop when your pattern is reached or call read() until the returned data matches your pattern, without excessively buffering your stream's content in memory.
Stability - API is somewhat unstable |
---|
Installation
$ npm install
Quick Examples
Pipe
var UntilStream = ;var streamBuffers = ; var us = pattern: 'World'; var sourceStream = ;sourceStream;var writableStream = ; sourceStream; writableStream;
Read
var UntilStream = ;var streamBuffers = ; var us = pattern: 'jumps'; var sourceStream = chunkSize: 8 ;sourceStream; sourceStream; us;
API Index
UntilStream
UntilStream also includes stream.Readable and stream.Writable methods. See the node v0.9 Stream documentation for more.
API Documentation ## UntilStream ### new UntilStream([options])
Arguments
- options (optional)
- pattern - String or Buffer If provided, UntilStream will stop reads or pipes when reached
Synchronously consume data from UntilStream's internal buffer. If the specified pattern is detected within the current chunk, slice off the portion prior to the pattern. The next call to read() will return exactly the pattern. Otherwise return the current chunk.
Arguments
- size (optional) - Mininum number of bytes to read. If not specified return the entire content of the internal buffer or up to the pattern
Return
Buffer | null
Example
var us = pattern: '\n' ; us;var hello = us;console;us; //matches '\n' pattern!var world = us;console;
Pipe incoming data from UntilStream to the destination WriteStream. If the pattern is reached, leave the pattern on the internal buffer, disconnect the pipe, and call end() on the destination. Back-pressure is properly managed.
Arguments
- destination - The Stream to pipe data to
- options (optional)
- end Boolean Default=false
Return
Stream - the destination stream
Example
var us = pattern: '\n' ;var loremIpsumStream = fs;var outputStream = fs; loremIpsumStream;
Reconfigure the pattern option. It's unwise to call this method while piping to a destination stream.
Arguments
- options (optional)
- pattern - String or Buffer If provided, UntilStream will stop reads or pipes when reached
Example
var us = ; us;us;var hello = us;console;us; //matches '\n' pattern!var world = us;console;
License
MIT