mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Force file node to write "binary" - so as not to expand binary like chars
into utf encoding. Helps with writing strings that happen to be binary encoded rather than buffers.
This commit is contained in:
parent
d3956f9816
commit
4f496c37be
@ -35,21 +35,23 @@ module.exports = function(RED) {
|
||||
});
|
||||
} else if (typeof msg.payload != "undefined") {
|
||||
var data = msg.payload;
|
||||
if (typeof data == "object") {
|
||||
if (typeof data === "object") {
|
||||
if (!Buffer.isBuffer(data)) {
|
||||
data = JSON.stringify(data);
|
||||
}
|
||||
}
|
||||
if (typeof data == "boolean") { data = data.toString(); }
|
||||
if (typeof data === "boolean") { data = data.toString(); }
|
||||
if ((this.appendNewline)&&(!Buffer.isBuffer(data))) { data += "\n"; }
|
||||
if (this.overwriteFile) {
|
||||
fs.writeFile(filename, data, function (err) {
|
||||
// using "binary" not {encoding:"binary"} to be 0.8 compatible for a while
|
||||
fs.writeFile(filename, data, "binary", function (err) {
|
||||
if (err) { node.warn('Failed to write to file : '+err); }
|
||||
//console.log('Message written to file',filename);
|
||||
});
|
||||
}
|
||||
else {
|
||||
fs.appendFile(filename, data, function (err) {
|
||||
// using "binary" not {encoding:"binary"} to be 0.8 compatible for a while
|
||||
fs.appendFile(filename, data, "binary", function (err) {
|
||||
if (err) { node.warn('Failed to append to file : '+err); }
|
||||
//console.log('Message appended to file',filename);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user