node-serialport-bindings-cpp/lib/parser-read-line.js
Francis Gulotta d2bb973382
Transform parsers into streams
Parsers are now transform streams! I'm not 100% convinced this is easier to use but it is more clear about the mechanics. I think that might make it worthwhile. It also opens up a clear example to how to make your own parser.
2016-09-08 19:18:36 -04:00

24 lines
605 B
JavaScript

'use strict';
var DelimiterParser = require('./parser-delimiter');
var inherits = require('inherits');
function ReadLineParser(options) {
if (!(this instanceof ReadLineParser)) {
return new ReadLineParser(options);
}
options = options || {};
if (options.delimiter === undefined) {
options.delimiter = new Buffer('\n', 'utf8');
}
DelimiterParser.call(this, options);
var encoding = options.encoding || 'utf8';
this.delimiter = new Buffer(options.delimiter, encoding);
this.setEncoding(encoding);
}
inherits(ReadLineParser, DelimiterParser);
module.exports = ReadLineParser;