-
Some file formats contain header data and then specify to read a data structure until the end of the file is reached. For example the PNG format contains an 8 byte header, followed by three or more data-chunks which can be of variable type/sizes, which repeat until the end of the file. So far this is my Pattern:
The issue is that the number of chunks is not stored, chunks are read until the end of the file is reached. Using the unsized array syntax:
Throws an error as there is never a zero chunk. Usually the last chunk has a type of How would I express this pattern? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi! Chunk chunks[while($ < std::mem::size())] @ 0x08; This will keep on creating more entries in the |
Beta Was this translation helpful? Give feedback.
Hi!
There's currently no proper function in the standard library sadly but one way to do it is:
This will keep on creating more entries in the
chunks
array until the current offset (denoted with$
) is not smaller than the size of the currently loaded data anymore.