From 22b32b1684f14fa2887ea360d6b21ed525455d47 Mon Sep 17 00:00:00 2001 From: Mark Hindess Date: Mon, 8 Sep 2014 19:53:03 +0100 Subject: [PATCH] Avoid wasting time preparing the payload if operation is a delete. --- nodes/core/storage/50-file.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/nodes/core/storage/50-file.js b/nodes/core/storage/50-file.js index 54b51ad4a..6f341226d 100644 --- a/nodes/core/storage/50-file.js +++ b/nodes/core/storage/50-file.js @@ -29,14 +29,6 @@ module.exports = function(RED) { if (filename === "") { node.warn('No filename specified'); } else if (typeof msg.payload != "undefined") { - var data = msg.payload; - if (typeof data == "object") { - if (!Buffer.isBuffer(data)) { - data = JSON.stringify(data); - } - } - if (typeof data == "boolean") { data = data.toString(); } - 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); } @@ -44,6 +36,14 @@ module.exports = function(RED) { }); } else { + var data = msg.payload; + if (typeof data == "object") { + if (!Buffer.isBuffer(data)) { + data = JSON.stringify(data); + } + } + if (typeof data == "boolean") { data = data.toString(); } + if ((this.appendNewline)&&(!Buffer.isBuffer(data))) { data += "\n"; } if (this.overwriteFile) { fs.writeFile(filename, data, function (err) { if (err) { node.warn('Failed to write to file : '+err); }