Skip to content

Commit 75379a7

Browse files
committed
Fixes keichi#3 Array encoding
1 parent ad27cfe commit 75379a7

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

lib/binary_parser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,7 @@ Parser.prototype.generate_encodeArray = function(ctx) {
941941
ctx.pushCode("var {0} = 0;", itemCounter);
942942
if (
943943
typeof this.options.encodeUntil === "function" ||
944-
this.options.readUntil
944+
typeof this.options.readUntil === "function"
945945
) {
946946
ctx.pushCode("do {");
947947
} else {

test/zz_encoder_bugs.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,5 +143,25 @@ describe("Specific bugs testing", function() {
143143
// Missing parms 179 as encodeUntil stops at 178
144144
assert.deepEqual(encoded, Buffer.from("0008AAB1B2FFFF", "hex"));
145145
});
146+
147+
it("should accept readUntil=eof and no encodeUntil provided", function() {
148+
var parser = Parser.start()
149+
.array("arr", {
150+
type: 'uint8',
151+
readUntil: 'eof' // Read until end of buffer
152+
});
153+
154+
var buffer = Buffer.from("01020304050607", "hex");
155+
var decoded = parser.parse(buffer);
156+
157+
assert.deepEqual(decoded, {
158+
arr: [
159+
1,2,3,4,5,6,7
160+
]
161+
});
162+
163+
var encoded = parser.encode(decoded);
164+
assert.deepEqual(encoded, Buffer.from("01020304050607", "hex"));
165+
});
146166
});
147167
});

0 commit comments

Comments
 (0)