foliojs/restructure

Array with known byte size but unknown length

timkurvers opened this issue · 1 comments

I'm attempting to parse a format that's very similar to the Interchange File Format which has arbitrarily sized chunks.

It seems Array has support for decoding using parent._length, which would allow decoding unknown amounts of chunks based on number of bytes. However, a struct's length seems to default to 0 unless explicitly passed into decode, is that by design?

Hmm, yeah that was some hack I did a while ago for a table in the SFNT/truetype font format, where I knew the byte length of the table, but not the element length. It should probably be exposed with a better API somehow. If I was doing it again, I'd probably have the user pass in the length property they want from the parent (and use utils.resolveLength normally), but have an option that says it is a byte length instead of an element length. That way there isn't a hard coded _length property dependency, you could name it whatever you want.