mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Add binary mode to tail node
This commit is contained in:
parent
ad10125303
commit
d3a98dd355
@ -194,7 +194,7 @@
|
|||||||
"h": "Hours"
|
"h": "Hours"
|
||||||
},
|
},
|
||||||
"extend": " extend delay if new message arrives",
|
"extend": " extend delay if new message arrives",
|
||||||
"tip": "The node can also be reset by sending a message with the <b>msg.reset</b> property set to any value.",
|
"tip": "The node can also be reset by sending a message with the <code>msg.reset</code> property set to any value.",
|
||||||
"label": {
|
"label": {
|
||||||
"trigger": "trigger",
|
"trigger": "trigger",
|
||||||
"trigger-block": "trigger & block",
|
"trigger-block": "trigger & block",
|
||||||
@ -405,7 +405,7 @@
|
|||||||
},
|
},
|
||||||
"tip": {
|
"tip": {
|
||||||
"in": "Tip: Make sure your firewall will allow the data in.",
|
"in": "Tip: Make sure your firewall will allow the data in.",
|
||||||
"out": "Tip: leave address and port blank if you want to set using <b>msg.ip</b> and <b>msg.port</b>.",
|
"out": "Tip: leave address and port blank if you want to set using <code>msg.ip</code> and <code>msg.port</code>.",
|
||||||
"port": "Ports already in use: "
|
"port": "Ports already in use: "
|
||||||
},
|
},
|
||||||
"status": {
|
"status": {
|
||||||
@ -637,8 +637,13 @@
|
|||||||
"tail": {
|
"tail": {
|
||||||
"label": {
|
"label": {
|
||||||
"filename": "Filename",
|
"filename": "Filename",
|
||||||
|
"type": "File type",
|
||||||
"splitlines": "Split lines on \\n?"
|
"splitlines": "Split lines on \\n?"
|
||||||
},
|
},
|
||||||
|
"action": {
|
||||||
|
"text": "Text - returns String",
|
||||||
|
"binary": "Binary - returns Buffer"
|
||||||
|
},
|
||||||
"errors": {
|
"errors": {
|
||||||
"windowsnotsupport": "Not currently supported on Windows."
|
"windowsnotsupport": "Not currently supported on Windows."
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<!--
|
<!--
|
||||||
Copyright 2013 IBM Corp.
|
Copyright 2013,2016 IBM Corp.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@ -15,11 +15,18 @@
|
|||||||
-->
|
-->
|
||||||
|
|
||||||
<script type="text/x-red" data-template-name="tail">
|
<script type="text/x-red" data-template-name="tail">
|
||||||
<div class="form-row node-input-filename">
|
<div class="form-row">
|
||||||
<label for="node-input-filename"><i class="fa fa-file"></i> <span data-i18n="tail.label.filename"></span></label>
|
<label for="node-input-filename"><i class="fa fa-file"></i> <span data-i18n="tail.label.filename"></span></label>
|
||||||
<input type="text" id="node-input-filename">
|
<input type="text" id="node-input-filename">
|
||||||
</div>
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
|
<label for="node-input-filetype"><i class="fa fa-file-text-o"></i> <span data-i18n="tail.label.type"></span></label>
|
||||||
|
<select type="text" id="node-input-filetype">
|
||||||
|
<option value="text" data-i18n="tail.action.text"></option>
|
||||||
|
<option value="binary" data-i18n="tail.action.binary"></option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="form-row" id="node-tail-split">
|
||||||
<label> </label>
|
<label> </label>
|
||||||
<input type="checkbox" id="node-input-split" placeholder="Name" style="display: inline-block; width: auto; vertical-align: top;">
|
<input type="checkbox" id="node-input-split" placeholder="Name" style="display: inline-block; width: auto; vertical-align: top;">
|
||||||
<label for="node-input-split" style="width: 70%;"><span data-i18n="tail.label.splitlines"></span></label>
|
<label for="node-input-split" style="width: 70%;"><span data-i18n="tail.label.splitlines"></span></label>
|
||||||
@ -28,12 +35,12 @@
|
|||||||
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
|
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
|
||||||
<input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name">
|
<input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name">
|
||||||
</div>
|
</div>
|
||||||
<!-- <div class="form-tips">WON'T work on Windows.</div> -->
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script type="text/x-red" data-help-name="tail">
|
<script type="text/x-red" data-help-name="tail">
|
||||||
<p>Tails (watches for things to be added) to the configured file. (Linux/Mac ONLY)</p>
|
<p>Tails (watches for things to be added) to the configured file. (Linux/Mac ONLY)</p>
|
||||||
<p>This won't work on Windows filesystems, as it relies on the <b>tail -F</b> command.</p>
|
<p>This will not work on Windows filesystems, as it relies on the <b>tail -F</b> command.</p>
|
||||||
|
<p>Text (UTF-8) files will be returned as strings. Binary files will be returned as a Buffer object.</p>
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
@ -41,6 +48,7 @@
|
|||||||
category: 'storage-input',
|
category: 'storage-input',
|
||||||
defaults: {
|
defaults: {
|
||||||
name: {value:""},
|
name: {value:""},
|
||||||
|
filetype: {value:"text"},
|
||||||
split: {value:false},
|
split: {value:false},
|
||||||
filename: {value:"",required:true}
|
filename: {value:"",required:true}
|
||||||
},
|
},
|
||||||
@ -53,6 +61,12 @@
|
|||||||
},
|
},
|
||||||
labelStyle: function() {
|
labelStyle: function() {
|
||||||
return this.name?"node_label_italic":"";
|
return this.name?"node_label_italic":"";
|
||||||
|
},
|
||||||
|
oneditprepare: function() {
|
||||||
|
$("#node-input-filetype").on("change",function() {
|
||||||
|
if (this.value === "text") { $("#node-tail-split").show(); }
|
||||||
|
else { $("#node-tail-split").hide(); }
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright 2013, 2014 IBM Corp.
|
* Copyright 2013,2016 IBM Corp.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -27,6 +27,7 @@ module.exports = function(RED) {
|
|||||||
RED.nodes.createNode(this,n);
|
RED.nodes.createNode(this,n);
|
||||||
|
|
||||||
this.filename = n.filename;
|
this.filename = n.filename;
|
||||||
|
this.filetype = n.filetype || "text";
|
||||||
this.split = n.split;
|
this.split = n.split;
|
||||||
var node = this;
|
var node = this;
|
||||||
|
|
||||||
@ -34,6 +35,8 @@ module.exports = function(RED) {
|
|||||||
// TODO: rewrite to use node-tail
|
// TODO: rewrite to use node-tail
|
||||||
var tail = spawn("tail", ["-F", "-n", "0", this.filename]);
|
var tail = spawn("tail", ["-F", "-n", "0", this.filename]);
|
||||||
tail.stdout.on("data", function (data) {
|
tail.stdout.on("data", function (data) {
|
||||||
|
var msg = { topic:node.filename };
|
||||||
|
if (this.filetype === "text") {
|
||||||
if (node.split) {
|
if (node.split) {
|
||||||
// TODO: allow customisation of the line break - as we do elsewhere
|
// TODO: allow customisation of the line break - as we do elsewhere
|
||||||
var strings = data.toString().split("\n");
|
var strings = data.toString().split("\n");
|
||||||
@ -48,10 +51,12 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var msg = {
|
msg.payload = data.toString();
|
||||||
topic:node.filename,
|
node.send(msg);
|
||||||
payload: data.toString()
|
}
|
||||||
};
|
}
|
||||||
|
else {
|
||||||
|
msg.payload = data;
|
||||||
node.send(msg);
|
node.send(msg);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user