Skip to content

Function: writeIsoBoxes() ​

ts
function writeIsoBoxes(boxes, config?): Uint8Array<ArrayBuffer>;

Defined in: writeIsoBoxes.ts:32

Writes ISO boxes to one Uint8Array.

The function handles each box by the rules of writeChildBoxes. An ArrayBufferView or a raw box has priority over a writer. A writer has priority over the boxes field of a container.

If boxes is an Array, the function copies each top-level ArrayBufferView and raw box one time, into the result. Every other box goes into the buffer of the write cursor. For any other iterable, the function writes every box into the buffer of the write cursor.

Parameters ​

boxes ​

Iterable<IsoBoxStreamable>

The boxes to write

config? ​

IsoBoxWriteConfig

The optional configuration with the writers. With no writers, the function writes only byte arrays, raw boxes, and containers.

Returns ​

Uint8Array<ArrayBuffer>

The bytes of every box, in a new Uint8Array with the exact size.

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
const isoFile = await readFile(new URL('./fixtures/captions.mp4', import.meta.url))

const boxes = readIsoBoxes(isoFile, {
	readers: {
		ftyp: readFtyp,
	},
})

const bytes = writeIsoBoxes(boxes, {
	writers: {
		ftyp: writeFtyp,
	},
})

deepStrictEqual(bytes, new Uint8Array(isoFile))

A Streaming Video Technology Alliance project.