buf.readUInt8([offset])


版本历史
版本变更
v14.9.0, v12.19.0

此函数也可用作 buf.readUint8()

v10.0.0

删除了 noAssert 并且不再隐式强制将偏移量强制转换为 uint32

v0.5.0

新增于: v0.5.0

  • 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.

AltStyle によって変換されたページ (->オリジナル) /