Skip to content

Commit 2482d12

Browse files
author
Dave Conway-Jones
committed
Let join node auto re-assemble buffers
and add test
1 parent 1733c38 commit 2482d12

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

nodes/core/logic/17-split.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ module.exports = function(RED) {
394394
inflight[partId].arrayLen = arrayLen;
395395
} else if (payloadType === 'buffer') {
396396
inflight[partId].bufferLen = 0;
397+
inflight[partId].joinChar = joinChar;
397398
}
398399
}
399400
if (node.timer > 0) {

test/nodes/core/logic/17-split_spec.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,28 @@ describe('JOIN node', function() {
297297
});
298298
});
299299

300+
it('should join bits of buffer back together automatically', function(done) {
301+
var flow = [{id:"n1", type:"join", wires:[["n2"]], joiner:",", build:"buffer", mode:"auto"},
302+
{id:"n2", type:"helper"}];
303+
helper.load(joinNode, flow, function() {
304+
var n1 = helper.getNode("n1");
305+
var n2 = helper.getNode("n2");
306+
n2.on("input", function(msg) {
307+
try {
308+
msg.should.have.property("payload");
309+
msg.should.be.a.Buffer;
310+
msg.payload.toString().should.equal("A-B-C-D");
311+
done();
312+
}
313+
catch(e) {done(e);}
314+
});
315+
n1.receive({payload:Buffer.from("A"), parts:{id:1, type:"buffer", ch:Buffer.from("-"), index:0, count:4}});
316+
n1.receive({payload:Buffer.from("B"), parts:{id:1, type:"buffer", ch:Buffer.from("-"), index:1, count:4}});
317+
n1.receive({payload:Buffer.from("C"), parts:{id:1, type:"buffer", ch:Buffer.from("-"), index:2, count:4}});
318+
n1.receive({payload:Buffer.from("D"), parts:{id:1, type:"buffer", ch:Buffer.from("-"), index:3, count:4}});
319+
});
320+
});
321+
300322
it('should join things into an array after a count', function(done) {
301323
var flow = [{id:"n1", type:"join", wires:[["n2"]], count:3, joiner:",",mode:"custom"},
302324
{id:"n2", type:"helper"}];

0 commit comments

Comments
 (0)