diff --git a/lib/binary_parser.js b/lib/binary_parser.js index ed299ef..79ab5d5 100644 --- a/lib/binary_parser.js +++ b/lib/binary_parser.js @@ -941,7 +941,7 @@ Parser.prototype.generate_encodeArray = function(ctx) { ctx.pushCode("var {0} = 0;", itemCounter); if ( typeof this.options.encodeUntil === "function" || - this.options.readUntil + typeof this.options.readUntil === "function" ) { ctx.pushCode("do {"); } else { diff --git a/test/zz_encoder_bugs.js b/test/zz_encoder_bugs.js index 44d3fa3..21ea353 100644 --- a/test/zz_encoder_bugs.js +++ b/test/zz_encoder_bugs.js @@ -143,5 +143,25 @@ describe("Specific bugs testing", function() { // Missing parms 179 as encodeUntil stops at 178 assert.deepEqual(encoded, Buffer.from("0008AAB1B2FFFF", "hex")); }); + + it("should accept readUntil=eof and no encodeUntil provided", function() { + var parser = Parser.start() + .array("arr", { + type: 'uint8', + readUntil: 'eof' // Read until end of buffer + }); + + var buffer = Buffer.from("01020304050607", "hex"); + var decoded = parser.parse(buffer); + + assert.deepEqual(decoded, { + arr: [ + 1,2,3,4,5,6,7 + ] + }); + + var encoded = parser.encode(decoded); + assert.deepEqual(encoded, Buffer.from("01020304050607", "hex")); + }); }); });