mirror of
https://github.com/siemens-mobile-hacks/node-serialport-bindings-cpp.git
synced 2026-11-26 02:47:17 +00:00
Merge pull request #190 from fhemberger/patch-1
Cleanup of PR #129: Add a encoding parameter for readline
This commit is contained in:
commit
28243c366e
1 changed files with 5 additions and 2 deletions
|
|
@ -22,13 +22,16 @@ var parsers = {
|
|||
raw: function (emitter, buffer) {
|
||||
emitter.emit("data", buffer);
|
||||
},
|
||||
readline: function (delimiter) {
|
||||
//encoding: ascii utf8 utf16le ucs2 base64 binary hex
|
||||
//More: http://nodejs.org/api/buffer.html#buffer_buffer
|
||||
readline: function (delimiter, encoding) {
|
||||
if (typeof delimiter === "undefined" || delimiter === null) { delimiter = "\r"; }
|
||||
if (typeof encoding === "undefined" || encoding === null) { encoding = "utf8"; }
|
||||
// Delimiter buffer saved in closure
|
||||
var data = "";
|
||||
return function (emitter, buffer) {
|
||||
// Collect data
|
||||
data += buffer.toString();
|
||||
data += buffer.toString(encoding);
|
||||
// Split collected data by delimiter
|
||||
var parts = data.split(delimiter)
|
||||
data = parts.pop();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue