MCPcopy
hub / github.com/stemkoski/stemkoski.github.com / _readUInt16

Function _readUInt16

MathBox/mathbox-core.js:1428–1450  ·  view source on GitHub ↗
(buf, offset, littleEndian, noAssert)

Source from the content-addressed store, hash-verified

1426}
1427
1428function _readUInt16 (buf, offset, littleEndian, noAssert) {
1429 if (!noAssert) {
1430 assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
1431 assert(offset !== undefined && offset !== null, 'missing offset')
1432 assert(offset + 1 < buf.length, 'Trying to read beyond buffer length')
1433 }
1434
1435 var len = buf.length
1436 if (offset >= len)
1437 return
1438
1439 var val
1440 if (littleEndian) {
1441 val = buf[offset]
1442 if (offset + 1 < len)
1443 val |= buf[offset + 1] << 8
1444 } else {
1445 val = buf[offset] << 8
1446 if (offset + 1 < len)
1447 val |= buf[offset + 1]
1448 }
1449 return val
1450}
1451
1452Buffer.prototype.readUInt16LE = function (offset, noAssert) {
1453 return _readUInt16(this, offset, true, noAssert)

Callers 2

mathbox-core.jsFile · 0.70
_readInt16Function · 0.70

Calls 1

assertFunction · 0.70

Tested by

no test coverage detected