buf.readUInt8([offset])
从指定 offset 处的 buf 读取无符号 8 位整数。
此函数也可在 readUint8 别名下使用。
import { Buffer } from 'buffer';
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。const { Buffer } = require('buffer');
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.
This function is also available under the readUint8 alias.
import { Buffer } from '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('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.