Skip to content
Evented stream line reader for node.js
Branch: master
Clone or download
Latest commit 877df8a Feb 10, 2016
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib Fix end emitted before last line Feb 9, 2016
test
.gitignore
.travis.yml
LICENSE Release v0.0.1 Oct 11, 2010
README.markdown some readme fixes Feb 4, 2013
package.json v0.3.0 Feb 10, 2016

README.markdown

build status Carrier helps you implement new-line terminated protocols over node.js.

The client can send you chunks of lines and carrier will only notify you on each completed line.

Install

$ npm install carrier

Usage

var net     = require('net'),
    carrier = require('carrier');

var server = net.createServer(function(conn) {
  carrier.carry(conn, function(line) {
    console.log('got one line: ' + line);
  });
});
server.listen(4001);

Or, you can also listen to the "line" event on the returned object of carrier.carry() like this:

var net     = require('net'),
    carrier = require('carrier');

var server = net.createServer(function(conn) {
  var my_carrier = carrier.carry(conn);
  my_carrier.on('line',  function(line) {
    console.log('got one line: ' + line);
  });
});
server.listen(4001);

carrier.carry accepts the following options:

  carrier.carry(reader, listener, encoding, separator)
  • reader: the stream reader
  • listener: a "line" event listener function
  • encoding: what encoding to assume. Default: "utf8"
  • separator: what line separator to use. Default: /\r?\n/

All are optional except for the first.

You can’t perform that action at this time.