buf.readUInt8([offset])


  • offset <integer> 开始读取之前要跳过的字节数。必须满足 0 <= offset <= buf.length - 1。默认值:0

    ¥offset <integer> Number of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - 1. Default: 0.

  • 返回:<integer>

    ¥Returns: <integer>

从指定 offset 处的 buf 读取无符号 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.