buf.readUInt8([offset])
从指定 offset
处的 buf
读取无符号 8 位整数。
const buf = Buffer.from([1, -2]);
console.log(buf.readUInt8(0));
// 打印: 1
console.log(buf.readUInt8(1));
// 打印: 254
console.log(buf.readUInt8(2));
// 抛出 ERR_OUT_OF_RANGE。
offset
<integer> Number of bytes to skip before starting to read. Must satisfy0 <= offset <= buf.length - 1
. Default:0
.- Returns: <integer>
Reads an unsigned 8-bit integer from buf
at the specified offset
.
const buf = Buffer.from([1, -2]);
console.log(buf.readUInt8(0));
// Prints: 1
console.log(buf.readUInt8(1));
// Prints: 254
console.log(buf.readUInt8(2));
// Throws ERR_OUT_OF_RANGE.