diff --git a/nodes/core/storage/50-file.js b/nodes/core/storage/50-file.js index 5623b4de8..a0e49f6fc 100644 --- a/nodes/core/storage/50-file.js +++ b/nodes/core/storage/50-file.js @@ -189,14 +189,9 @@ module.exports = function(RED) { parts:{index:count, ch:ch, type:type, id:msg._msgid} } count += 1; - if ((chunk.length < hwm) && (bits[i+1].length === 0)) { - m.parts.count = count; - } node.send(m); } spare = bits[i]; - if (chunk.length !== hwm) { getout = false; } - //console.log("LEFT",bits[i].length,bits[i]); } if (node.format === "stream") { var m = { @@ -233,6 +228,18 @@ module.exports = function(RED) { else { msg.payload = lines; } node.send(msg); } + else if (node.format === "lines") { + var m = { payload: spare, + parts: { + index: count, + count: count+1, + ch: ch, + type: type, + id: msg._msgid + } + }; + node.send(m); + } else if (getout) { // last chunk same size as high water mark - have to send empty extra packet. var m = { parts:{index:count, count:count, ch:ch, type:type, id:msg._msgid} }; node.send(m); diff --git a/test/nodes/core/storage/50-file_spec.js b/test/nodes/core/storage/50-file_spec.js index d3ee3fcb4..6da2b158a 100644 --- a/test/nodes/core/storage/50-file_spec.js +++ b/test/nodes/core/storage/50-file_spec.js @@ -542,20 +542,63 @@ describe('file Nodes', function() { var n2 = helper.getNode("n2"); var c = 0; n2.on("input", function(msg) { - msg.should.have.property('payload'); - msg.payload.should.be.a.String(); - msg.payload.should.have.length(19); - if (c === 0) { - msg.payload.should.equal("File message line 1"); - c++; - } else { - msg.payload.should.equal("File message line 2"); + try { + msg.should.have.property('payload'); + msg.payload.should.be.a.String(); msg.should.have.property('parts'); - msg.parts.should.have.property('index',1); - msg.parts.should.have.property('count',2); + msg.parts.should.have.property('index',c); msg.parts.should.have.property('type','string'); msg.parts.should.have.property('ch','\n'); - done(); + if (c === 0) { + msg.payload.should.equal("File message line 1"); + } + if (c === 1) { + msg.payload.should.equal("File message line 2"); + } + if (c === 2) { + msg.payload.should.equal(""); + done(); + } + c++; + } + catch(e) { + done(e); + } + }); + n1.receive({payload:""}); + }); + }); + + it('should read in a file with empty line and output split lines with parts', function(done) { + var data = ["-", "", "-", ""]; + var line = data.join("\n"); + fs.writeFileSync(fileToTest, line); + var flow = [{id:"fileInNode1", type:"file in", name: "fileInNode", filename:fileToTest, format:"lines", wires:[["n2"]]}, + {id:"n2", type:"helper"}]; + helper.load(fileNode, flow, function() { + var n1 = helper.getNode("fileInNode1"); + var n2 = helper.getNode("n2"); + var c = 0; + n2.on("input", function(msg) { + try { + msg.should.have.property('payload'); + msg.payload.should.equal(data[c]); + msg.should.have.property('parts'); + var parts = msg.parts; + parts.should.have.property('index',c); + parts.should.have.property('type','string'); + parts.should.have.property('ch','\n'); + c++; + if (c === data.length) { + parts.should.have.property('count', data.length); + done(); + } + else { + parts.should.not.have.property('count'); + } + } + catch(e) { + done(e); } }); n1.receive({payload:""});