buf.readUInt8([offset])
从 buf 中指定的 offset 读取一个无符号的 8 位整数。
【Reads an unsigned 8-bit integer from buf at the specified offset.】
该函数也可以通过 readUint8 别名使用。
【This function is also available under the readUint8 alias.】
import { Buffer } from 'node:buffer';
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.const { Buffer } = require('node:buffer');
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.