mirror of
				https://github.com/node-red/node-red.git
				synced 2025-03-01 10:36:34 +00:00 
			
		
		
		
	File node - don't hose status web socket on multiple file writes
and add close behaviour to info
This commit is contained in:
		@@ -40,6 +40,8 @@
 | 
				
			|||||||
    <h3>Details</h3>
 | 
					    <h3>Details</h3>
 | 
				
			||||||
    <p>Each message payload will be added to the end of the file, optionally appending
 | 
					    <p>Each message payload will be added to the end of the file, optionally appending
 | 
				
			||||||
    a newline (\n) character between each one.</p>
 | 
					    a newline (\n) character between each one.</p>
 | 
				
			||||||
 | 
					    <p>If <code>msg.filename</code> is used the file will be closed after every write. 
 | 
				
			||||||
 | 
					    For best performance use a fixed filename.</p>
 | 
				
			||||||
    <p>It can be configured to overwrite the entire file rather than append. For example,
 | 
					    <p>It can be configured to overwrite the entire file rather than append. For example,
 | 
				
			||||||
    when writing binary data to a file, such as an image, this option should be used
 | 
					    when writing binary data to a file, such as an image, this option should be used
 | 
				
			||||||
    and the option to append a newline should be disabled.</p>
 | 
					    and the option to append a newline should be disabled.</p>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -32,7 +32,13 @@ module.exports = function(RED) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        this.on("input",function(msg) {
 | 
					        this.on("input",function(msg) {
 | 
				
			||||||
            var filename = node.filename || msg.filename || "";
 | 
					            var filename = node.filename || msg.filename || "";
 | 
				
			||||||
            if (!node.filename) { node.status({fill:"grey",shape:"dot",text:filename}); }
 | 
					            if ((!node.filename) && (!node.tout)) {
 | 
				
			||||||
 | 
					                node.tout = setTimeout(function() {
 | 
				
			||||||
 | 
					                    node.status({fill:"grey",shape:"dot",text:filename});
 | 
				
			||||||
 | 
					                    clearTimeout(node.tout);
 | 
				
			||||||
 | 
					                    node.tout = null;
 | 
				
			||||||
 | 
					                },333);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
            if (filename === "") { node.warn(RED._("file.errors.nofilename")); }
 | 
					            if (filename === "") { node.warn(RED._("file.errors.nofilename")); }
 | 
				
			||||||
            else if (node.overwriteFile === "delete") {
 | 
					            else if (node.overwriteFile === "delete") {
 | 
				
			||||||
                fs.unlink(filename, function (err) {
 | 
					                fs.unlink(filename, function (err) {
 | 
				
			||||||
@@ -80,6 +86,7 @@ module.exports = function(RED) {
 | 
				
			|||||||
        });
 | 
					        });
 | 
				
			||||||
        this.on('close', function() {
 | 
					        this.on('close', function() {
 | 
				
			||||||
            if (node.wstream) { node.wstream.end(); }
 | 
					            if (node.wstream) { node.wstream.end(); }
 | 
				
			||||||
 | 
					            if (node.tout) { clearTimeout(node.tout); }
 | 
				
			||||||
            node.status({});
 | 
					            node.status({});
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user