buf.readUIntBE()

buf.readUIntBE(offset, byteLength[, noAssert])
buf.readUIntLE(offset, byteLength[, noAssert])

  • offset {Number} 0 <= offset <= buf.length - byteLength
  • byteLength {Number} 0 < byteLength <= 6
  • noAssert {Boolean} 默认:false
  • 返回:{Number}
从该 Buffer 指定的 offset 位置开始读取 byteLength 字节数,并将结果解释执行为一个无符号的整数值。支持多达48位精度的值。例如: ``` const buf = Buffer.allocUnsafe(6); buf.writeUInt16LE(0x90ab, 0); buf.writeUInt32LE(0x12345678, 2); buf.readUIntLE(0, 6).toString(16); // Specify 6 bytes (48 bits) // Returns: '1234567890ab'

buf.readUIntBE(0, 6).toString(16);
// Returns: ab9078563412

设置 noAssert 为 true ,将跳过对 offset 的验证。这将允许 offset 超出缓冲区的末尾。
原文地址:https://www.cnblogs.com/lalalagq/p/9908662.html