Skip to content

Instantly share code, notes, and snippets.

@aisouard
aisouard / readVariableInt.js
Last active May 5, 2021 09:53
Reading an EBML variable-length integer
/**
* Read an EBML tag header or length and return their respective values into
* single numbers.
*
* @example
* var tagHeader = new Uint8Array([0x1A, 0x45, 0xDF, 0xA3, 0x01, 0x00, 0x00,
* 0x00, 0x00, 0x00, 0x00, 0x1F]);
* var tagId = readVariableInt(tagHeader, 4, 0);
* console.log('The current tag ID is: ', tagId.value, ', skipping ', tagId.size, ' bytes.');
* // The current tag ID is: 172351395, skipping 4 bytes.