Skip to content

Function: readInt64AsBigInt() ​

ts
function readInt64AsBigInt(
   cursor, 
   size, 
   signed
): bigint;

Defined in: readInt64AsBigInt.ts:29

Reads an integer field of 4 or 8 bytes as a bigint.

Pass this function as the int64 option of IsoBoxReadConfig. The built-in readers then return every 64-bit integer field as a bigint, with the exact value. A field that is 32 bits in version 0 of its box is a bigint too.

This function needs BigInt and the getBigUint64 method of DataView, and does not test for them. On a runtime without them, a read fails with the error of the runtime. If your code supports such a runtime, test typeof DataView.prototype.getBigUint64 === 'function' before you pass this function. The test is false on a runtime without BigInt too.

Parameters ​

cursor ​

IsoBoxReadCursor<IsoInt64>

The cursor to read the field from.

size ​

4 | 8

The size of the field in bytes.

signed ​

boolean

Whether the field is a signed integer.

Returns ​

bigint

The value of the field.

Example ​

ts
// A moof box that holds a traf box with a version 1 tfdt box.
// baseMediaDecodeTime is 2^53 + 1, which a number cannot hold.
const bytes = new Uint8Array([
	0,
	0,
	0,
	36,
	0x6d,
	0x6f,
	0x6f,
	0x66, // moof
	0,
	0,
	0,
	28,
	0x74,
	0x72,
	0x61,
	0x66, // traf
	0,
	0,
	0,
	20,
	0x74,
	0x66,
	0x64,
	0x74,
	1,
	0,
	0,
	0, // tfdt, version 1
	0,
	0x20,
	0,
	0,
	0,
	0,
	0,
	1, // baseMediaDecodeTime
])
const boxes = readIsoBoxes(bytes, {
	int64: readInt64AsBigInt,
	readers: { tfdt: readTfdt },
})

// The field is a bigint with the exact value.
const tfdt = findIsoBox(boxes, box => isIsoBoxType('tfdt', box))

A Streaming Video Technology Alliance project.