Function: writeChildBoxes()
ts
function writeChildBoxes(cursor, boxes): void;Defined in: writeChildBoxes.ts:33
Writes boxes at the position of a write cursor, with the writers of the cursor.
The function handles each box in this order:
- An
ArrayBufferView: the function copies the bytes. - A box with a
bytesfield, such as a raw box ofreadIsoBoxes: the function copies the bytes. - A box with a writer in
cursor.writers: the function calls the writer. - A box with a type in
CONTAINERS: the function writes the header and theboxesfield. - Any other box: the function throws.
Parameters
cursor
The write cursor.
boxes
The boxes to write.
Returns
void
Throws
Error if a box has no writer, no bytes field, and a type outside CONTAINERS. The message starts with "No writer found for box type".
Throws
RangeError if a value of a box does not fit its field. Examples are a number outside the range, a missing value of a field that the flags select, and a list that is longer than its count field can state.
Throws
RangeError if a box has more than 2^32 - 1 bytes.
Example
ts
function writeMyBox(
cursor: IsoBoxWriteCursor,
box: { type: 'mybx'; children: MovieFragmentHeaderBox[] },
): void {
const start = beginIsoFullBox(cursor, box.type, 0, 0)
writeChildBoxes(cursor, box.children)
endIsoBox(cursor, start)
}
const cursor = createIsoBoxWriteCursor({ writers: { mfhd: writeMfhd } })
writeMyBox(cursor, { type: 'mybx', children: [MFHD] })