mirror of
https://github.com/siemens-mobile-hacks/node-serialport-bindings-cpp.git
synced 2026-11-26 02:47:17 +00:00
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.
24 lines
605 B
JavaScript
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;
|