PERF : make single buffer / string file reading faster

This commit is contained in:
Franck 2024-12-05 12:24:02 +01:00
parent 9bd7131914
commit bfd98aaf22

View File

@ -339,7 +339,7 @@ module.exports = function(RED) {
} }
else { else {
msg.filename = filename; msg.filename = filename;
var lines = Buffer.from([]); const bufferArray = [];
var spare = ""; var spare = "";
var count = 0; var count = 0;
var type = "buffer"; var type = "buffer";
@ -397,7 +397,7 @@ module.exports = function(RED) {
} }
} }
else { else {
lines = Buffer.concat([lines,chunk]); bufferArray.push(chunk);
} }
} }
}) })
@ -413,10 +413,11 @@ module.exports = function(RED) {
}) })
.on('end', function() { .on('end', function() {
if (node.chunk === false) { if (node.chunk === false) {
const buffer = Buffer.concat(bufferArray);
if (node.format === "utf8") { if (node.format === "utf8") {
msg.payload = decode(lines, node.encoding); msg.payload = decode(buffer, node.encoding);
} }
else { msg.payload = lines; } else { msg.payload = buffer; }
nodeSend(msg); nodeSend(msg);
} }
else if (node.format === "lines") { else if (node.format === "lines") {