Skip to content

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:

  1. An ArrayBufferView: the function copies the bytes.
  2. A box with a bytes field, such as a raw box of readIsoBoxes: the function copies the bytes.
  3. A box with a writer in cursor.writers: the function calls the writer.
  4. A box with a type in CONTAINERS: the function writes the header and the boxes field.
  5. Any other box: the function throws.

Parameters ​

cursor ​

IsoBoxWriteCursor

The write cursor.

boxes ​

Iterable<IsoBoxStreamable>

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] })

A Streaming Video Technology Alliance project.