Skip to content

Function: readChildBoxes() ​

ts
function readChildBoxes<V>(cursor, count?): ParsedIsoBox<V>[];

Defined in: readChildBoxes.ts:40

Reads the boxes from the position of a cursor to its end.

For each box, the function calls the reader of cursor.readers with the cursor at the first byte after the box header. For a uuid box, the position is the first byte of usertype. After the reader, the function moves the cursor to the end of the box, so a reader can stop before the end of its box. A box with no reader and a type in CONTAINERS gets its child boxes in boxes. Any other box with no reader is a raw box. A uuid box is also a raw box if its reader returns undefined.

The function stops before a truncated box: the data ends inside the box, or the size is below the header size. The position of the cursor is then the first byte of that box. After an error, the position of the cursor is the first byte of the box that failed, and start and end do not change.

Type Parameters ​

V ​

V extends IsoInt64 = number

Parameters ​

cursor ​

IsoBoxReadCursor<V>

The cursor at the first byte of the first box.

count? ​

number

The maximum number of boxes. With no count, the function reads every box to cursor.end. With a count, the function does not read the bytes after the last box of the count.

Returns ​

ParsedIsoBox<V>[]

The boxes.

Throws ​

RangeError if count is negative or NaN.

Throws ​

RangeError if the cursor has the truncated option 'throw' and the function reaches a truncated box. The message has the position of the box and the cause.

Throws ​

RangeError if a reader throws a RangeError.

Throws ​

RangeError if a box is deeper than 128 levels. The message has the box type and the limit.

Example ​

ts
// A cursor at the first child box of a box.
const cursor = createIsoBoxReadCursor(reduceUint8Arrays([MFHD, MDAT]))

const boxes = readChildBoxes(cursor) // a raw mfhd box and a raw mdat box

A Streaming Video Technology Alliance project.