mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Add output to File Out node and update icons
This commit is contained in:
parent
5ed3360c0b
commit
f7434b5ec8
BIN
editor/icons/file-in.png
Normal file
BIN
editor/icons/file-in.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 542 B |
BIN
editor/icons/file-out.png
Normal file
BIN
editor/icons/file-out.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 503 B |
@ -123,9 +123,8 @@
|
|||||||
},
|
},
|
||||||
color:"BurlyWood",
|
color:"BurlyWood",
|
||||||
inputs:1,
|
inputs:1,
|
||||||
outputs:0,
|
outputs:1,
|
||||||
icon: "file.png",
|
icon: "file-out.png",
|
||||||
align: "right",
|
|
||||||
label: function() {
|
label: function() {
|
||||||
if (this.overwriteFile === "delete") {
|
if (this.overwriteFile === "delete") {
|
||||||
return this.name||this._("file.label.deletelabel",{file:this.filename});
|
return this.name||this._("file.label.deletelabel",{file:this.filename});
|
||||||
@ -159,7 +158,7 @@
|
|||||||
outputLabels: function(i) {
|
outputLabels: function(i) {
|
||||||
return (this.format === "utf8") ? "UTF8 string" : "binary buffer";
|
return (this.format === "utf8") ? "UTF8 string" : "binary buffer";
|
||||||
},
|
},
|
||||||
icon: "file.png",
|
icon: "file-in.png",
|
||||||
label: function() {
|
label: function() {
|
||||||
return this.name||this.filename||this._("file.label.filelabel");
|
return this.name||this.filename||this._("file.label.filelabel");
|
||||||
},
|
},
|
||||||
|
@ -39,14 +39,20 @@ module.exports = function(RED) {
|
|||||||
node.tout = null;
|
node.tout = null;
|
||||||
},333);
|
},333);
|
||||||
}
|
}
|
||||||
if (filename === "") { node.warn(RED._("file.errors.nofilename")); }
|
if (filename === "") {
|
||||||
else if (node.overwriteFile === "delete") {
|
node.warn(RED._("file.errors.nofilename"));
|
||||||
|
} else if (node.overwriteFile === "delete") {
|
||||||
fs.unlink(filename, function (err) {
|
fs.unlink(filename, function (err) {
|
||||||
if (err) { node.error(RED._("file.errors.deletefail",{error:err.toString()}),msg); }
|
if (err) {
|
||||||
else if (RED.settings.verbose) { node.log(RED._("file.status.deletedfile",{file:filename})); }
|
node.error(RED._("file.errors.deletefail",{error:err.toString()}),msg);
|
||||||
});
|
} else {
|
||||||
|
if (RED.settings.verbose) {
|
||||||
|
node.log(RED._("file.status.deletedfile",{file:filename}));
|
||||||
}
|
}
|
||||||
else if (msg.hasOwnProperty("payload") && (typeof msg.payload !== "undefined")) {
|
node.send(msg);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else if (msg.hasOwnProperty("payload") && (typeof msg.payload !== "undefined")) {
|
||||||
var dir = path.dirname(filename);
|
var dir = path.dirname(filename);
|
||||||
if (node.createDir) {
|
if (node.createDir) {
|
||||||
try {
|
try {
|
||||||
@ -64,15 +70,21 @@ module.exports = function(RED) {
|
|||||||
if (typeof data === "boolean") { data = data.toString(); }
|
if (typeof data === "boolean") { data = data.toString(); }
|
||||||
if (typeof data === "number") { data = data.toString(); }
|
if (typeof data === "number") { data = data.toString(); }
|
||||||
if ((node.appendNewline) && (!Buffer.isBuffer(data))) { data += os.EOL; }
|
if ((node.appendNewline) && (!Buffer.isBuffer(data))) { data += os.EOL; }
|
||||||
node.data.push(Buffer.from(data));
|
node.data.push({msg:msg,data:Buffer.from(data)});
|
||||||
|
|
||||||
while (node.data.length > 0) {
|
while (node.data.length > 0) {
|
||||||
if (node.overwriteFile === "true") {
|
if (node.overwriteFile === "true") {
|
||||||
|
(function(packet) {
|
||||||
node.wstream = fs.createWriteStream(filename, { encoding:'binary', flags:'w', autoClose:true });
|
node.wstream = fs.createWriteStream(filename, { encoding:'binary', flags:'w', autoClose:true });
|
||||||
node.wstream.on("error", function(err) {
|
node.wstream.on("error", function(err) {
|
||||||
node.error(RED._("file.errors.writefail",{error:err.toString()}),msg);
|
node.error(RED._("file.errors.writefail",{error:err.toString()}),msg);
|
||||||
});
|
});
|
||||||
node.wstream.end(node.data.shift());
|
node.wstream.on("open", function() {
|
||||||
|
node.wstream.end(packet.data, function() {
|
||||||
|
node.send(packet.msg);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
})(node.data.shift());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Append mode
|
// Append mode
|
||||||
@ -115,10 +127,17 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
if (node.filename) {
|
if (node.filename) {
|
||||||
// Static filename - write and reuse the stream next time
|
// Static filename - write and reuse the stream next time
|
||||||
node.wstream.write(node.data.shift());
|
var packet = node.data.shift()
|
||||||
|
node.wstream.write(packet.data, function() {
|
||||||
|
node.send(packet.msg);
|
||||||
|
});
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Dynamic filename - write and close the stream
|
// Dynamic filename - write and close the stream
|
||||||
node.wstream.end(node.data.shift());
|
var packet = node.data.shift()
|
||||||
|
node.wstream.end(packet.data, function() {
|
||||||
|
node.send(packet.msg);
|
||||||
|
});
|
||||||
delete node.wstream;
|
delete node.wstream;
|
||||||
delete node.wstreamIno;
|
delete node.wstreamIno;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user