mirror of
				https://github.com/node-red/node-red.git
				synced 2025-03-01 10:36:34 +00:00 
			
		
		
		
	
				
					committed by
					
						 Nick O'Leary
						Nick O'Leary
					
				
			
			
				
	
			
			
			
						parent
						
							946def022f
						
					
				
				
					commit
					281e9d1357
				
			| @@ -117,7 +117,9 @@ module.exports = function(RED) { | ||||
|                 } | ||||
|                 if (typeof data === "boolean") { data = data.toString(); } | ||||
|                 if (typeof data === "number") { data = data.toString(); } | ||||
|                 if ((node.appendNewline) && (!Buffer.isBuffer(data))) { data += os.EOL; } | ||||
|                 var aflg = true; | ||||
|                 if (msg.hasOwnProperty("parts") && msg.parts.type === "string" && (msg.parts.count === msg.parts.index + 1)) { aflg = false; } | ||||
|                 if ((node.appendNewline) && (!Buffer.isBuffer(data)) && aflg) { data += os.EOL; } | ||||
|                 var buf; | ||||
|                 if (node.encoding === "setbymsg") { | ||||
|                     buf = encode(data, msg.encoding || "none"); | ||||
| @@ -314,7 +316,6 @@ module.exports = function(RED) { | ||||
|             }); | ||||
|             filename = filename || ""; | ||||
|             var fullFilename = filename; | ||||
|             var filePath = ""; | ||||
|             if (filename && RED.settings.fileWorkingDirectory && !path.isAbsolute(filename)) { | ||||
|                 fullFilename = path.resolve(path.join(RED.settings.fileWorkingDirectory,filename)); | ||||
|             } | ||||
|   | ||||
| @@ -194,6 +194,55 @@ describe('file Nodes', function() { | ||||
|             }); | ||||
|         }); | ||||
|  | ||||
|         it('should append to a file and add newline, except last line of multipart input', function(done) { | ||||
|             var flow = [{id:"fileNode1", type:"file", name: "fileNode", "filename":fileToTest, "appendNewline":true, "overwriteFile":false, wires: [["helperNode1"]]}, | ||||
|                         {id:"helperNode1", type:"helper"}]; | ||||
|             try { | ||||
|                 fs.unlinkSync(fileToTest); | ||||
|             } catch(err) { | ||||
|             } | ||||
|             helper.load(fileNode, flow, function() { | ||||
|                 var n1 = helper.getNode("fileNode1"); | ||||
|                 var n2 = helper.getNode("helperNode1"); | ||||
|                 var count = 0; | ||||
|                 //var data = ["Line1", "Line2"]; | ||||
|  | ||||
|                 n2.on("input", function (msg) { | ||||
|                     try { | ||||
|                         msg.should.have.property("payload"); | ||||
|                         //data.should.containDeep([msg.payload]); | ||||
|                         if (count === 3) { | ||||
|                             var f = fs.readFileSync(fileToTest).toString(); | ||||
|                             if (os.type() !== "Windows_NT") { | ||||
|                                 f.should.have.length(23); | ||||
|                                 f.should.equal("Line1\nLine2\nLine3\nLine4"); | ||||
|                             } | ||||
|                             else { | ||||
|                                 f.should.have.length(23); | ||||
|                                 f.should.equal("Line1\r\nLine2\r\nLine3\r\nLine4"); | ||||
|                             } | ||||
|                             done(); | ||||
|                         } | ||||
|                         count++; | ||||
|                     } | ||||
|                     catch (e) { | ||||
|                         done(e); | ||||
|                     } | ||||
|                 }); | ||||
|  | ||||
|                 n1.receive({payload:"Line1",parts:{index:0,type:"string"}});    // string | ||||
|                 setTimeout(function() { | ||||
|                     n1.receive({payload:"Line2",parts:{index:1,type:"string"}});    // string | ||||
|                 },30); | ||||
|                 setTimeout(function() { | ||||
|                     n1.receive({payload:"Line3",parts:{index:2,type:"string"}});    // string | ||||
|                 },60); | ||||
|                 setTimeout(function() { | ||||
|                     n1.receive({payload:"Line4",parts:{index:3,type:"string",count:4}});    // string | ||||
|                 },90); | ||||
|             }); | ||||
|         }); | ||||
|  | ||||
|         it('should append to a file after it has been deleted ', function(done) { | ||||
|             var flow = [{id:"fileNode1", type:"file", name: "fileNode", "filename":fileToTest, "appendNewline":false, "overwriteFile":false, wires: [["helperNode1"]]}, | ||||
|                         {id:"helperNode1", type:"helper"}]; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user