Socket
Socket
Sign inDemoInstall

delimiterstream

Package Overview
Dependencies
1
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    delimiterstream

Get delimiter-separated chunks of data from a Readable Stream.


Version published
Weekly downloads
19
increased by1800%
Maintainers
1
Install size
47.8 kB
Created
Weekly downloads
 

Changelog

Source

0.3.0 ###

  • Deprecated 0.2.x usage
  • New wrap method

Readme

Source

DelimiterStream

Get delimiter-separated (e.g. new line) chunks of data from a Readable Stream, Websocket or other data source.

Methods

DelimiterStream.wrap(options, callback [, context, args...])

DelimiterStream.wrap(callback [, context, args...])

Returns a function that calls callback with a chunk of data as they are received. If options are passed then you can customize the delimiter and dataLimit. Delimiter defaults to \n.

The chunks will NOT include the delimiter.

Coming from v0.2.x?

v0.3.x is 100% backwards compatible with v0.2.x methods, but they are deprecated. They will be removed in v0.4.x.

Example

Primary use case is with a server endpoint that accepts new-line-delimited data:

var net = require('net'),
    DelimiterStream = require('delimiterstream'),
    server = net.createServer();
function onSocketLine(line) {
    //line will be a buffer
    console.log('Received line from', this.remoteAddress, line.toString());
}
server.on('connection', function(socket) {
    socket.on('data', DelimiterStream.wrap(onSocketLine, socket));
});
server.listen(9999);

It also works with files:

var fs = require('fs'),
    DelimiterStream = require('delimiterstream');
fs.readFile('example.csv', DelimiterStream.wrap(function(line) {
    //line will be a Buffer
    console.log(line.toString());
});

By James Hartig

Keywords

FAQs

Last updated on 10 Jun 2015

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc