Allow File node to write out buffers of binary data

This commit is contained in:
Dave C-J 2014-07-29 08:57:12 +01:00
parent 00a9542edf
commit 78edf89e52
1 changed files with 6 additions and 2 deletions

View File

@ -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); }