mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Avoid wasting time preparing the payload if operation is a delete.
This commit is contained in:
parent
995268c5df
commit
22b32b1684
@ -29,6 +29,13 @@ module.exports = function(RED) {
|
|||||||
if (filename === "") {
|
if (filename === "") {
|
||||||
node.warn('No filename specified');
|
node.warn('No filename specified');
|
||||||
} else if (typeof msg.payload != "undefined") {
|
} else if (typeof msg.payload != "undefined") {
|
||||||
|
if (msg.hasOwnProperty('delete')) {
|
||||||
|
fs.unlink(filename, function (err) {
|
||||||
|
if (err) { node.warn('Failed to delete file : '+err); }
|
||||||
|
//console.log('Deleted file",filename);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
var data = msg.payload;
|
var data = msg.payload;
|
||||||
if (typeof data == "object") {
|
if (typeof data == "object") {
|
||||||
if (!Buffer.isBuffer(data)) {
|
if (!Buffer.isBuffer(data)) {
|
||||||
@ -37,13 +44,6 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
if (typeof data == "boolean") { data = data.toString(); }
|
if (typeof data == "boolean") { data = data.toString(); }
|
||||||
if ((this.appendNewline)&&(!Buffer.isBuffer(data))) { data += "\n"; }
|
if ((this.appendNewline)&&(!Buffer.isBuffer(data))) { data += "\n"; }
|
||||||
if (msg.hasOwnProperty('delete')) {
|
|
||||||
fs.unlink(filename, function (err) {
|
|
||||||
if (err) { node.warn('Failed to delete file : '+err); }
|
|
||||||
//console.log('Deleted file",filename);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (this.overwriteFile) {
|
if (this.overwriteFile) {
|
||||||
fs.writeFile(filename, data, function (err) {
|
fs.writeFile(filename, data, function (err) {
|
||||||
if (err) { node.warn('Failed to write to file : '+err); }
|
if (err) { node.warn('Failed to write to file : '+err); }
|
||||||
|
Loading…
Reference in New Issue
Block a user