Socket
Socket
Sign inDemoInstall

newline-stream

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

newline-stream

Read and process a stream delimited by newlines


Version published
Maintainers
1
Created
Source

NewLine Stream

Different solutions to handling and piping delimited strings

npm install newline-stream

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);
  });

The caveat on this method is that onFinish can only be called ONE time per event. If there is more than one event listener, onFinish should be ignored by all but one.

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

Keywords

FAQs

Package last updated on 17 Jan 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc