0.0.1 • Published 11 years ago

newline-stream v0.0.1

Weekly downloads
46
License
-
Repository
github
Last release
11 years ago

NewLine Stream

Different solutions to handling and piping delimited strings

Simple example of a json stream parser

  var NLStream = require('newline-stream');
  var stream = new NLStream(inputStream);
  stream.on('line', function (line) {
    var obj = JSON.parse(line);  
    console.log(obj);
  });

Using "pipe"

  var NLStream = require('newline-stream');
  var stream   = new NLStream(request);

  stream.pipe(response, function (line) {
    var out = JSON.parse(line).output;
    return JSON.stringify(out);
  });

Enabling pause/drain/resume

  var NLStream = require('newline-stream');
  var stream   = new NLStream(request, { pause: true });
  stream.on('line', function (line, onFinish) {
    asyncAction(line, onFinish);
  });

Instantiator

  var NLStream = require('newline-stream'); 
  var stream   = new NLStream(inputStream, options);

Options

  • separator (string or regexp) - string or regular expression that represents a new line
  • pause (boolean) - if true, pause is called automatically until onFinish is called
0.0.1

11 years ago

0.0.0

11 years ago