Skip to content

Function: findIsoBox() ​

Call Signature ​

ts
function findIsoBox<T, S>(
   boxes, 
   callback, 
   config?
): S | null;

Defined in: findIsoBox.ts:21

Finds the first box in the tree that satisfies the provided testing function.

This function traverses the entire box structure (including nested boxes) and returns the first box for which the callback returns true.

Type Parameters ​

T ​

T

S ​

S

Parameters ​

boxes ​

Iterable<T>

The boxes to search through

callback ​

(box) => box is S

A function that accepts a box and returns true if it matches

config? ​

TraverseIsoBoxesConfig

Configuration options for traversal

Returns ​

S | null

The first box that satisfies the callback, narrowed to the type S of the type guard, or null if none is found

Example ​

ts
const isoFile = await readFile(new URL('./fixtures/captions.mp4', import.meta.url))
const boxes = readIsoBoxes(isoFile, {
	readers: {
		ftyp: readFtyp,
	},
})

const ftyp = findIsoBox(boxes, box => isIsoBoxType('ftyp', box))

assert.ok(ftyp)
assert.strictEqual(ftyp.type, 'ftyp')
assert.strictEqual(ftyp.majorBrand, 'isom')

Call Signature ​

ts
function findIsoBox<T>(
   boxes, 
   callback, 
   config?
): T | null;

Defined in: findIsoBox.ts:40

Finds the first box in the tree for which a boolean callback returns true.

Use the other overload with a type guard callback to narrow the result.

Type Parameters ​

T ​

T

Parameters ​

boxes ​

Iterable<T>

The boxes to search through

callback ​

(box) => boolean

A function that accepts a box and returns true if it matches

config? ​

TraverseIsoBoxesConfig

Configuration options for traversal

Returns ​

T | null

The first box that satisfies the callback, with the input type T, or null if none is found

A Streaming Video Technology Alliance project.