mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Use correct Buffer.from method rather than constructor
exec, tcp, ump and file nodes
This commit is contained in:
parent
4dd2d3ac7d
commit
d99432bff1
@ -91,7 +91,7 @@ module.exports = function(RED) {
|
|||||||
child.stderr.on('data', function (data) {
|
child.stderr.on('data', function (data) {
|
||||||
if (node.activeProcesses.hasOwnProperty(child.pid) && node.activeProcesses[child.pid] !== null) {
|
if (node.activeProcesses.hasOwnProperty(child.pid) && node.activeProcesses[child.pid] !== null) {
|
||||||
if (isUtf8(data)) { msg.payload = data.toString(); }
|
if (isUtf8(data)) { msg.payload = data.toString(); }
|
||||||
else { msg.payload = new Buffer.from(data); }
|
else { msg.payload = Buffer.from(data); }
|
||||||
node.send([null,RED.util.cloneMessage(msg),null]);
|
node.send([null,RED.util.cloneMessage(msg),null]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -126,7 +126,7 @@ module.exports = function(RED) {
|
|||||||
/* istanbul ignore else */
|
/* istanbul ignore else */
|
||||||
if (RED.settings.verbose) { node.log(cl); }
|
if (RED.settings.verbose) { node.log(cl); }
|
||||||
child = exec(cl, {encoding: 'binary', maxBuffer:10000000}, function (error, stdout, stderr) {
|
child = exec(cl, {encoding: 'binary', maxBuffer:10000000}, function (error, stdout, stderr) {
|
||||||
msg.payload = new Buffer.from(stdout,"binary");
|
msg.payload = Buffer.from(stdout,"binary");
|
||||||
if (isUtf8(msg.payload)) { msg.payload = msg.payload.toString(); }
|
if (isUtf8(msg.payload)) { msg.payload = msg.payload.toString(); }
|
||||||
var msg2 = null;
|
var msg2 = null;
|
||||||
if (stderr) {
|
if (stderr) {
|
||||||
|
@ -47,7 +47,7 @@ module.exports = function(RED) {
|
|||||||
node.status({fill:"grey",shape:"dot",text:"common.status.connecting"});
|
node.status({fill:"grey",shape:"dot",text:"common.status.connecting"});
|
||||||
var id = (1+Math.random()*4294967295).toString(16);
|
var id = (1+Math.random()*4294967295).toString(16);
|
||||||
client = net.connect(node.port, node.host, function() {
|
client = net.connect(node.port, node.host, function() {
|
||||||
buffer = (node.datatype == 'buffer') ? new Buffer.alloc(0) : "";
|
buffer = (node.datatype == 'buffer') ? Buffer.alloc(0) : "";
|
||||||
node.connected = true;
|
node.connected = true;
|
||||||
node.log(RED._("tcpin.status.connected",{host:node.host,port:node.port}));
|
node.log(RED._("tcpin.status.connected",{host:node.host,port:node.port}));
|
||||||
node.status({fill:"green",shape:"dot",text:"common.status.connected"});
|
node.status({fill:"green",shape:"dot",text:"common.status.connected"});
|
||||||
@ -132,7 +132,7 @@ module.exports = function(RED) {
|
|||||||
count++;
|
count++;
|
||||||
node.status({text:RED._("tcpin.status.connections",{count:count})});
|
node.status({text:RED._("tcpin.status.connections",{count:count})});
|
||||||
|
|
||||||
var buffer = (node.datatype == 'buffer') ? new Buffer.alloc(0) : "";
|
var buffer = (node.datatype == 'buffer') ? Buffer.alloc(0) : "";
|
||||||
socket.on('data', function (data) {
|
socket.on('data', function (data) {
|
||||||
if (node.datatype != 'buffer') {
|
if (node.datatype != 'buffer') {
|
||||||
data = data.toString(node.datatype);
|
data = data.toString(node.datatype);
|
||||||
@ -269,9 +269,9 @@ module.exports = function(RED) {
|
|||||||
if (Buffer.isBuffer(msg.payload)) {
|
if (Buffer.isBuffer(msg.payload)) {
|
||||||
client.write(msg.payload);
|
client.write(msg.payload);
|
||||||
} else if (typeof msg.payload === "string" && node.base64) {
|
} else if (typeof msg.payload === "string" && node.base64) {
|
||||||
client.write(new Buffer.from(msg.payload,'base64'));
|
client.write(Buffer.from(msg.payload,'base64'));
|
||||||
} else {
|
} else {
|
||||||
client.write(new Buffer.from(""+msg.payload));
|
client.write(Buffer.from(""+msg.payload));
|
||||||
}
|
}
|
||||||
if (node.doend === true) {
|
if (node.doend === true) {
|
||||||
end = true;
|
end = true;
|
||||||
@ -296,9 +296,9 @@ module.exports = function(RED) {
|
|||||||
if (Buffer.isBuffer(msg.payload)) {
|
if (Buffer.isBuffer(msg.payload)) {
|
||||||
client.write(msg.payload);
|
client.write(msg.payload);
|
||||||
} else if (typeof msg.payload === "string" && node.base64) {
|
} else if (typeof msg.payload === "string" && node.base64) {
|
||||||
client.write(new Buffer.from(msg.payload,'base64'));
|
client.write(Buffer.from(msg.payload,'base64'));
|
||||||
} else {
|
} else {
|
||||||
client.write(new Buffer.from(""+msg.payload));
|
client.write(Buffer.from(""+msg.payload));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -307,9 +307,9 @@ module.exports = function(RED) {
|
|||||||
if (Buffer.isBuffer(msg.payload)) {
|
if (Buffer.isBuffer(msg.payload)) {
|
||||||
connectionPool[i].write(msg.payload);
|
connectionPool[i].write(msg.payload);
|
||||||
} else if (typeof msg.payload === "string" && node.base64) {
|
} else if (typeof msg.payload === "string" && node.base64) {
|
||||||
connectionPool[i].write(new Buffer.from(msg.payload,'base64'));
|
connectionPool[i].write(Buffer.from(msg.payload,'base64'));
|
||||||
} else {
|
} else {
|
||||||
connectionPool[i].write(new Buffer.from(""+msg.payload));
|
connectionPool[i].write(Buffer.from(""+msg.payload));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -346,9 +346,9 @@ module.exports = function(RED) {
|
|||||||
if (Buffer.isBuffer(msg.payload)) {
|
if (Buffer.isBuffer(msg.payload)) {
|
||||||
buffer = msg.payload;
|
buffer = msg.payload;
|
||||||
} else if (typeof msg.payload === "string" && node.base64) {
|
} else if (typeof msg.payload === "string" && node.base64) {
|
||||||
buffer = new Buffer.from(msg.payload,'base64');
|
buffer = Buffer.from(msg.payload,'base64');
|
||||||
} else {
|
} else {
|
||||||
buffer = new Buffer.from(""+msg.payload);
|
buffer = Buffer.from(""+msg.payload);
|
||||||
}
|
}
|
||||||
for (var i = 0; i < connectedSockets.length; i += 1) {
|
for (var i = 0; i < connectedSockets.length; i += 1) {
|
||||||
if (node.doend === true) { connectedSockets[i].end(buffer); }
|
if (node.doend === true) { connectedSockets[i].end(buffer); }
|
||||||
@ -431,10 +431,10 @@ module.exports = function(RED) {
|
|||||||
if (!clients[connection_id].connected) {
|
if (!clients[connection_id].connected) {
|
||||||
var buf;
|
var buf;
|
||||||
if (this.out == "count") {
|
if (this.out == "count") {
|
||||||
if (this.splitc === 0) { buf = new Buffer.alloc(1); }
|
if (this.splitc === 0) { buf = Buffer.alloc(1); }
|
||||||
else { buf = new Buffer.alloc(this.splitc); }
|
else { buf = Buffer.alloc(this.splitc); }
|
||||||
}
|
}
|
||||||
else { buf = new Buffer.alloc(65536); } // set it to 64k... hopefully big enough for most TCP packets.... but only hopefully
|
else { buf = Buffer.alloc(65536); } // set it to 64k... hopefully big enough for most TCP packets.... but only hopefully
|
||||||
|
|
||||||
clients[connection_id].client = net.Socket();
|
clients[connection_id].client = net.Socket();
|
||||||
if (socketTimeout !== null) { clients[connection_id].client.setTimeout(socketTimeout);}
|
if (socketTimeout !== null) { clients[connection_id].client.setTimeout(socketTimeout);}
|
||||||
@ -484,7 +484,7 @@ module.exports = function(RED) {
|
|||||||
clients[connection_id].timeout = setTimeout(function () {
|
clients[connection_id].timeout = setTimeout(function () {
|
||||||
if (clients[connection_id]) {
|
if (clients[connection_id]) {
|
||||||
clients[connection_id].timeout = null;
|
clients[connection_id].timeout = null;
|
||||||
clients[connection_id].msg.payload = new Buffer.alloc(i+1);
|
clients[connection_id].msg.payload = Buffer.alloc(i+1);
|
||||||
buf.copy(clients[connection_id].msg.payload,0,0,i+1);
|
buf.copy(clients[connection_id].msg.payload,0,0,i+1);
|
||||||
node.send(clients[connection_id].msg);
|
node.send(clients[connection_id].msg);
|
||||||
if (clients[connection_id].client) {
|
if (clients[connection_id].client) {
|
||||||
@ -505,7 +505,7 @@ module.exports = function(RED) {
|
|||||||
i += 1;
|
i += 1;
|
||||||
if ( i >= node.splitc) {
|
if ( i >= node.splitc) {
|
||||||
if (clients[connection_id]) {
|
if (clients[connection_id]) {
|
||||||
clients[connection_id].msg.payload = new Buffer.alloc(i);
|
clients[connection_id].msg.payload = Buffer.alloc(i);
|
||||||
buf.copy(clients[connection_id].msg.payload,0,0,i);
|
buf.copy(clients[connection_id].msg.payload,0,0,i);
|
||||||
node.send(clients[connection_id].msg);
|
node.send(clients[connection_id].msg);
|
||||||
if (clients[connection_id].client) {
|
if (clients[connection_id].client) {
|
||||||
@ -523,7 +523,7 @@ module.exports = function(RED) {
|
|||||||
i += 1;
|
i += 1;
|
||||||
if (data[j] == node.splitc) {
|
if (data[j] == node.splitc) {
|
||||||
if (clients[connection_id]) {
|
if (clients[connection_id]) {
|
||||||
clients[connection_id].msg.payload = new Buffer.alloc(i);
|
clients[connection_id].msg.payload = Buffer.alloc(i);
|
||||||
buf.copy(clients[connection_id].msg.payload,0,0,i);
|
buf.copy(clients[connection_id].msg.payload,0,0,i);
|
||||||
node.send(clients[connection_id].msg);
|
node.send(clients[connection_id].msg);
|
||||||
if (clients[connection_id].client) {
|
if (clients[connection_id].client) {
|
||||||
|
@ -181,11 +181,11 @@ module.exports = function(RED) {
|
|||||||
} else {
|
} else {
|
||||||
var message;
|
var message;
|
||||||
if (node.base64) {
|
if (node.base64) {
|
||||||
message = new Buffer.from(msg.payload, 'base64');
|
message = Buffer.from(msg.payload, 'base64');
|
||||||
} else if (msg.payload instanceof Buffer) {
|
} else if (msg.payload instanceof Buffer) {
|
||||||
message = msg.payload;
|
message = msg.payload;
|
||||||
} else {
|
} else {
|
||||||
message = new Buffer.from(""+msg.payload);
|
message = Buffer.from(""+msg.payload);
|
||||||
}
|
}
|
||||||
sock.send(message, 0, message.length, por, add, function(err, bytes) {
|
sock.send(message, 0, message.length, por, add, function(err, bytes) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
@ -55,7 +55,7 @@ module.exports = function(RED) {
|
|||||||
if (typeof data === "boolean") { data = data.toString(); }
|
if (typeof data === "boolean") { data = data.toString(); }
|
||||||
if (typeof data === "number") { data = data.toString(); }
|
if (typeof data === "number") { data = data.toString(); }
|
||||||
if ((this.appendNewline) && (!Buffer.isBuffer(data))) { data += os.EOL; }
|
if ((this.appendNewline) && (!Buffer.isBuffer(data))) { data += os.EOL; }
|
||||||
node.data.push(new Buffer.from(data));
|
node.data.push(Buffer.from(data));
|
||||||
|
|
||||||
while (node.data.length > 0) {
|
while (node.data.length > 0) {
|
||||||
if (this.overwriteFile === "true") {
|
if (this.overwriteFile === "true") {
|
||||||
@ -104,7 +104,7 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
msg.filename = filename;
|
msg.filename = filename;
|
||||||
var lines = new Buffer.from([]);
|
var lines = Buffer.from([]);
|
||||||
var spare = "";
|
var spare = "";
|
||||||
var count = 0;
|
var count = 0;
|
||||||
var type = "buffer";
|
var type = "buffer";
|
||||||
|
Loading…
Reference in New Issue
Block a user