Merge pull request #4980 from braincube-io/feat/fadoli/MakeFileReadFast

Performance : make reading single buffer / string file faster by not re-allocating and handling huge buffers
This commit is contained in:
Nick O'Leary 2024-12-05 16:17:52 +00:00 committed by GitHub
commit f6e565ba04
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

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