0.2.3 • Published 10 years ago

sentinal-stream v0.2.3

Weekly downloads
3
License
-
Repository
github
Last release
10 years ago

Sentinal-Stream

A transform stream that finds a sentinal value in a data stream, and then emits it as a seperate data event.

Application

Any time you want to take a particular action if a certain value appears in a stream, e.g. splitting a stream, stopping a stream early, etc.

API

sentinal = new Sentinal(sep) returns a transform stream. sep is a buffered string. It will be stored on sentinal.seperator.

Example

var Sentinal = require('sentinal-stream')
  , through = require('through') // npm.im/through
  , from = require('from') // npm.im/from
  , sentence = ''

var periods = new Sentinal(new Buffer('|||'))

var source = from([
    '||| is the delimiter.'
  , ' Sometimes it fits|||'
  , 'Sometimes it might take'
  , 'more than one line|||'
  , 'Look||| two per chunk|||'
  , '||| or ||| even ||| three!'
  , 'And sometimes only part ||'
  , '| Of the separator fits.'
])

var gather_wipe = through(function(data) {
  if(data === periods.seperator) {
    sentence && console.log(sentence + '.')
    sentence = ''
    return
  }
  sentence += data 
})

source
  .pipe(periods)
  .pipe(gather_wipe) 

Yields:

is the delimiter. Sometimes it fits.
Sometimes it might take more than one line.
Look. two per chunk.
or even three! And sometimes only part .
 Of the seperator fits.
0.2.3

10 years ago

0.2.2

11 years ago

0.2.1

11 years ago

0.2.0

11 years ago

0.1.2

11 years ago

0.1.1

11 years ago

0.1.0

11 years ago