From 78edf89e52b36a384bb6cad62bb38da4a8121d71 Mon Sep 17 00:00:00 2001 From: Dave C-J Date: Tue, 29 Jul 2014 08:57:12 +0100 Subject: [PATCH] Allow File node to write out buffers of binary data --- nodes/core/storage/50-file.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/nodes/core/storage/50-file.js b/nodes/core/storage/50-file.js index 8092c10c4..54b51ad4a 100644 --- a/nodes/core/storage/50-file.js +++ b/nodes/core/storage/50-file.js @@ -30,9 +30,13 @@ module.exports = function(RED) { node.warn('No filename specified'); } else if (typeof msg.payload != "undefined") { var data = msg.payload; - if (typeof data == "object") { data = JSON.stringify(data); } + if (typeof data == "object") { + if (!Buffer.isBuffer(data)) { + data = JSON.stringify(data); + } + } if (typeof data == "boolean") { data = data.toString(); } - if (this.appendNewline) { 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); }