"index out of range" with dynamic array size
See original GitHub issueI add new elements to the data i read in but on save i get the “index out of range” error when i call writeAll(data).
“array(baseType, @length) - array of given type and length, reads/writes to the end of binary if length is not given.” I did not specify length. So i assumed it would be able to still save if i add more entries to the array than there was before - but it only works if i remove or keep the number the same.
file: {
recordNum: "int32",
fieldNum: "int32",
recordSize: "int32",
data: ["array", dataFld"]
}
RangeError: Index out of range
at checkInt (buffer.js:1187:11)
at Buffer.writeInt32LE (buffer.js:1375:5)
I store the jbinary object:
loadedJBinary = binary;
resolve({ data: loadedJBinary.readAll() });
And use it again to write:
loadedJBinary.writeAll(data);
Because i saw no way to use a existing js object to create a new jBinary object to save. But this does not work with the increasing array size.
Nether did i find any way to update the size of arrays before writeall.
Can just hope this project isn’t dead, it’s the only one in existence that i could find that allows use of a C++ like struct approach.
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (2 by maintainers)
Top GitHub Comments
Found a way around the issue. I forgot the file had a header that specified each block size and count so i could calculate new buffer size from it.
I do not know the byte size of a js object (because the null terminated strings are shorter and do not include the 00 bytes - so the string may only be 2 bytes in object but it should be 64 bytes in final data).
I found binary.view.byteLength to get the current length from another issue - but i still lack away to get the value to increase it by. Is there a way to calculate it / get the byte size of a type ( ex. dataFld.byteLength so i can just add x number of that value)?