A file, and every container inside it, is a run of boxes laid one after another. Today you walk a byte range and collect every box in it, advancing past each one by its own size.
Parse a byte range into a flat list of the boxes it contains.
Boxes at one level sit adjacent: parse a header, then jump forward by that
box’s full Size to land exactly on the next box’s first byte. Repeat until you
run out of bytes. The key move is advancing by the whole box size, not just the
header - the payload in between is skipped over wholesale at this level.
Here the ftyp box is 16 bytes, so after reading it you jump to offset 16 and find
the free box (a padding box you can ignore) of size 8, ending at 24. This same
loop parses the top level of a file and, once boxes nest, the children inside any
container. Tomorrow you turn that observation into recursion.
// step through the range, parsing a header then skipping its whole sizefunc parseBoxes(b []byte) []Box {var boxes []Boxpos := 0for pos < len(b) {box := parseHeaderAt(b, pos, len(b))boxes = append(boxes, box)pos += int(box.Size) // advance past the entire box}return boxes}