update "core" extra nodes to use newer Buffer syntax

This commit is contained in:
Dave Conway-Jones 2017-06-24 13:53:22 +01:00
parent a64d758e18
commit 6c3c16f210
No known key found for this signature in database
GPG Key ID: 81B04231572A9A2D
7 changed files with 23 additions and 23 deletions

View File

@ -52,7 +52,7 @@ module.exports = function(RED) {
payload += node.addCh;
}
else if (node.addCh !== "") {
payload = Buffer.concat([payload,new Buffer(node.addCh)]);
payload = Buffer.concat([payload,new Buffer.from(node.addCh)]);
}
node.port.write(payload,function(err,res) {
if (err) {
@ -94,8 +94,8 @@ module.exports = function(RED) {
var node = this;
node.tout = null;
var buf;
if (node.serialConfig.out != "count") { buf = new Buffer(bufMaxSize); }
else { buf = new Buffer(Number(node.serialConfig.newline)); }
if (node.serialConfig.out != "count") { buf = new Buffer.alloc(bufMaxSize); }
else { buf = new Buffer.alloc(Number(node.serialConfig.newline)); }
var i = 0;
node.status({fill:"grey",shape:"dot",text:"node-red:common.status.not-connected"});
node.port = serialPool.get(this.serialConfig.serialport,
@ -108,17 +108,17 @@ module.exports = function(RED) {
var splitc;
if (node.serialConfig.newline.substr(0,2) == "0x") {
splitc = new Buffer([parseInt(node.serialConfig.newline)]);
splitc = new Buffer.from([parseInt(node.serialConfig.newline)]);
}
else {
splitc = new Buffer(node.serialConfig.newline.replace("\\n","\n").replace("\\r","\r").replace("\\t","\t").replace("\\e","\e").replace("\\f","\f").replace("\\0","\0")); // jshint ignore:line
splitc = new Buffer.from(node.serialConfig.newline.replace("\\n","\n").replace("\\r","\r").replace("\\t","\t").replace("\\e","\e").replace("\\f","\f").replace("\\0","\0")); // jshint ignore:line
}
this.port.on('data', function(msg) {
// single char buffer
if ((node.serialConfig.newline === 0)||(node.serialConfig.newline === "")) {
if (node.serialConfig.bin !== "bin") { node.send({"payload": String.fromCharCode(msg)}); }
else { node.send({"payload": new Buffer([msg])}); }
else { node.send({"payload": new Buffer.from([msg])}); }
}
else {
// do the timer thing
@ -130,7 +130,7 @@ module.exports = function(RED) {
else {
node.tout = setTimeout(function () {
node.tout = null;
var m = new Buffer(i+1);
var m = new Buffer.alloc(i+1);
buf.copy(m,0,0,i+1);
if (node.serialConfig.bin !== "bin") { m = m.toString(); }
node.send({"payload": m});
@ -145,7 +145,7 @@ module.exports = function(RED) {
buf[i] = msg;
i += 1;
if ( i >= parseInt(node.serialConfig.newline)) {
var m = new Buffer(i);
var m = new Buffer.alloc(i);
buf.copy(m,0,0,i);
if (node.serialConfig.bin !== "bin") { m = m.toString(); }
node.send({"payload":m});
@ -158,7 +158,7 @@ module.exports = function(RED) {
buf[i] = msg;
i += 1;
if ((msg === splitc[0]) || (i === bufMaxSize)) {
var n = new Buffer(i);
var n = new Buffer.alloc(i);
buf.copy(n,0,0,i);
if (node.serialConfig.bin !== "bin") { n = n.toString(); }
node.send({"payload":n});

View File

@ -1,6 +1,6 @@
{
"name" : "node-red-node-serialport",
"version" : "0.4.2",
"version" : "0.4.3",
"description" : "Node-RED nodes to talk to serial ports",
"dependencies" : {
"serialport" : "~4.0.7"

View File

@ -16,12 +16,12 @@ module.exports = function(RED) {
// Take base64 string and make into binary buffer
var regexp = new RegExp('^[A-Za-z0-9+\/=]*$');
if ( regexp.test(msg.payload) && (msg.payload.length % 4 === 0) ) {
msg.payload = new Buffer(msg.payload,'base64');
msg.payload = new Buffer.from(msg.payload,'base64');
node.send(msg);
}
else {
//node.log("Not a Base64 string - maybe we should encode it...");
msg.payload = (new Buffer(msg.payload,"binary")).toString('base64');
msg.payload = (new Buffer.from(msg.payload,"binary")).toString('base64');
node.send(msg);
}
}

View File

@ -23,5 +23,5 @@ If the input is a Base64 string it converts it back to a binary buffer.
Sample Flow
-----------
<pre><code>[{"id":"d2ccae00.2d335","type":"inject","name":"","topic":"","payload":"","payloadType":"none","repeat":"","crontab":"","once":false,"x":136,"y":99,"z":"385bdf8b.c7a42","wires":[["e03cae10.1fc35"]]},{"id":"b778ef09.48871","type":"base64","name":"","x":411.5,"y":160,"z":"385bdf8b.c7a42","wires":[["6295d1b1.9d6a3","46b597ba.b94a68"]]},{"id":"6295d1b1.9d6a3","type":"debug","name":"","active":true,"console":"false","complete":"false","x":610,"y":160,"z":"385bdf8b.c7a42","wires":[]},{"id":"ead9e7c9.152618","type":"debug","name":"","active":true,"console":"false","complete":"false","x":610,"y":240,"z":"385bdf8b.c7a42","wires":[]},{"id":"46b597ba.b94a68","type":"base64","name":"","x":411.5,"y":240,"z":"385bdf8b.c7a42","wires":[["ead9e7c9.152618"]]},{"id":"1c9124e9.e36edb","type":"inject","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":1775,"y":113,"z":"385bdf8b.c7a42","wires":[[]]},{"id":"48a892ea.b7576c","type":"debug","name":"","active":true,"console":"false","complete":"false","x":2171,"y":210,"z":"385bdf8b.c7a42","wires":[]},{"id":"e03cae10.1fc35","type":"function","name":"","func":"msg.payload = new Buffer(\"12345\");\nreturn msg;","outputs":1,"x":250,"y":160,"z":"385bdf8b.c7a42","wires":[["b778ef09.48871"]]}]
<pre><code>[{"id":"d2ccae00.2d335","type":"inject","name":"","topic":"","payload":"","payloadType":"none","repeat":"","crontab":"","once":false,"x":136,"y":99,"z":"385bdf8b.c7a42","wires":[["e03cae10.1fc35"]]},{"id":"b778ef09.48871","type":"base64","name":"","x":411.5,"y":160,"z":"385bdf8b.c7a42","wires":[["6295d1b1.9d6a3","46b597ba.b94a68"]]},{"id":"6295d1b1.9d6a3","type":"debug","name":"","active":true,"console":"false","complete":"false","x":610,"y":160,"z":"385bdf8b.c7a42","wires":[]},{"id":"ead9e7c9.152618","type":"debug","name":"","active":true,"console":"false","complete":"false","x":610,"y":240,"z":"385bdf8b.c7a42","wires":[]},{"id":"46b597ba.b94a68","type":"base64","name":"","x":411.5,"y":240,"z":"385bdf8b.c7a42","wires":[["ead9e7c9.152618"]]},{"id":"1c9124e9.e36edb","type":"inject","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":1775,"y":113,"z":"385bdf8b.c7a42","wires":[[]]},{"id":"48a892ea.b7576c","type":"debug","name":"","active":true,"console":"false","complete":"false","x":2171,"y":210,"z":"385bdf8b.c7a42","wires":[]},{"id":"e03cae10.1fc35","type":"function","name":"","func":"msg.payload = new Buffer.from(\"12345\");\nreturn msg;","outputs":1,"x":250,"y":160,"z":"385bdf8b.c7a42","wires":[["b778ef09.48871"]]}]
</code></pre>

View File

@ -1,6 +1,6 @@
{
"name" : "node-red-node-base64",
"version" : "0.0.4",
"version" : "0.0.5",
"description" : "A Node-RED node to pack and unpack objects to base64 format",
"dependencies" : {
},

View File

@ -35,7 +35,7 @@ describe('base64 node', function() {
msg.should.have.a.property("payload","QUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVo=");
done();
});
n1.emit("input", {payload: Buffer("ABCDEFGHIJKLMNOPQRSTUVWXYZ")});
n1.emit("input", {payload: Buffer.from("ABCDEFGHIJKLMNOPQRSTUVWXYZ")});
});
});

View File

@ -53,7 +53,7 @@ describe('exif node', function() {
done();
});
exifNode1.receive({payload:new Buffer("hello")});
exifNode1.receive({payload:new Buffer.from("hello")});
});
});
@ -90,7 +90,7 @@ describe('exif node', function() {
done();
});
exifNode1.receive({payload:new Buffer("hello")});
exifNode1.receive({payload:new Buffer.from("hello")});
});
});
@ -125,7 +125,7 @@ describe('exif node', function() {
done();
},150);
exifNode1.receive({payload:new Buffer("hello")});
exifNode1.receive({payload:new Buffer.from("hello")});
});
});
@ -133,7 +133,7 @@ describe('exif node', function() {
var exif = require('exif');
var ExifImage = exif.ExifImage;
// this time just use a buffer that isn't an jpeg image
var data = new Buffer("hello");
var data = new Buffer.from("hello");
var eD;
var flow = [{id:"exifNode1", type:"exif", wires:[["helperNode1"]]},
{id:"helperNode1", type:"helper"}];
@ -185,7 +185,7 @@ describe('exif node', function() {
it('should report if no payload', function(done) {
var exif = require('exif');
var ExifImage = exif.ExifImage;
var data = new Buffer("hello");
var data = new Buffer.from("hello");
var eD;
var flow = [{id:"exifNode1", type:"exif", wires:[["helperNode1"]]},
{id:"helperNode1", type:"helper"}];
@ -211,7 +211,7 @@ describe('exif node', function() {
it('should report if bad latitude', function(done) {
var exif = require('exif');
var ExifImage = exif.ExifImage;
var data = new Buffer("hello");
var data = new Buffer.from("hello");
var eD;
var flow = [{id:"exifNode1", type:"exif", wires:[["helperNode1"]]},
{id:"helperNode1", type:"helper"}];
@ -251,7 +251,7 @@ describe('exif node', function() {
it('should report if bad longitude', function(done) {
var exif = require('exif');
var ExifImage = exif.ExifImage;
var data = new Buffer("hello");
var data = new Buffer.from("hello");
var eD;
var flow = [{id:"exifNode1", type:"exif", wires:[["helperNode1"]]},
{id:"helperNode1", type:"helper"}];
@ -291,7 +291,7 @@ describe('exif node', function() {
it('should report if unsure about location', function(done) {
var exif = require('exif');
var ExifImage = exif.ExifImage;
var data = new Buffer("hello");
var data = new Buffer.from("hello");
var eD;
var flow = [{id:"exifNode1", type:"exif", wires:[["helperNode1"]]},
{id:"helperNode1", type:"helper"}];