From 2482d122b8e811d0def39fc0cb004bbb1463ea9e Mon Sep 17 00:00:00 2001 From: Dave Conway-Jones Date: Mon, 26 Jun 2017 23:10:08 +0100 Subject: [PATCH] Let join node auto re-assemble buffers and add test --- nodes/core/logic/17-split.js | 1 + test/nodes/core/logic/17-split_spec.js | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/nodes/core/logic/17-split.js b/nodes/core/logic/17-split.js index 5a913feaf..2fa96b34e 100644 --- a/nodes/core/logic/17-split.js +++ b/nodes/core/logic/17-split.js @@ -394,6 +394,7 @@ module.exports = function(RED) { inflight[partId].arrayLen = arrayLen; } else if (payloadType === 'buffer') { inflight[partId].bufferLen = 0; + inflight[partId].joinChar = joinChar; } } if (node.timer > 0) { diff --git a/test/nodes/core/logic/17-split_spec.js b/test/nodes/core/logic/17-split_spec.js index 4d6602aa4..71bfc0046 100644 --- a/test/nodes/core/logic/17-split_spec.js +++ b/test/nodes/core/logic/17-split_spec.js @@ -297,6 +297,28 @@ describe('JOIN node', function() { }); }); + it('should join bits of buffer back together automatically', function(done) { + var flow = [{id:"n1", type:"join", wires:[["n2"]], joiner:",", build:"buffer", mode:"auto"}, + {id:"n2", type:"helper"}]; + helper.load(joinNode, flow, function() { + var n1 = helper.getNode("n1"); + var n2 = helper.getNode("n2"); + n2.on("input", function(msg) { + try { + msg.should.have.property("payload"); + msg.should.be.a.Buffer; + msg.payload.toString().should.equal("A-B-C-D"); + done(); + } + catch(e) {done(e);} + }); + n1.receive({payload:Buffer.from("A"), parts:{id:1, type:"buffer", ch:Buffer.from("-"), index:0, count:4}}); + n1.receive({payload:Buffer.from("B"), parts:{id:1, type:"buffer", ch:Buffer.from("-"), index:1, count:4}}); + n1.receive({payload:Buffer.from("C"), parts:{id:1, type:"buffer", ch:Buffer.from("-"), index:2, count:4}}); + n1.receive({payload:Buffer.from("D"), parts:{id:1, type:"buffer", ch:Buffer.from("-"), index:3, count:4}}); + }); + }); + it('should join things into an array after a count', function(done) { var flow = [{id:"n1", type:"join", wires:[["n2"]], count:3, joiner:",",mode:"custom"}, {id:"n2", type:"helper"}];