📜  Node.js Buffer.readDoubleLE() 方法

📅  最后修改于: 2022-05-13 01:56:34.700000             🧑  作者: Mango

Node.js Buffer.readDoubleLE() 方法

Node.js 中的Buffer.readDoubleLE() 方法用于以 Little Endian 格式从给定偏移处的缓冲区读取 64 位双精度。

句法:

Buffer.readDoubleLE( offset )

参数:此方法接受单个参数偏移量,该偏移量保存开始读取之前要跳过的字节数。 offset 的值介于0 <= offset <= buf.length – 8之间。它的默认值为 0。

返回值:它以小端格式返回一个整数值。

下面的例子说明了在 Node.js 中使用 buf.readDoubleLE() 方法:

示例 1:

// Node program to demonstrate the
// Buffer.readDoubleLE() method
  
// Creating a buffer of given size
const buf = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);
  
// Display the result
console.log(buf.readDoubleLE(0));
console.log(buf);

输出:

5.447603722011605e-270

示例 2:

// Node program to demonstrate the
// Buffer.readDoubleBE() method
  
// Creating a buffer of given size
const buf = Buffer.from([11, 22, 33, 44, 55, 66, 77, 88]);
  
// Display the result
console.log("Functions of Buffer.readDoubleLE(int)");
console.log(buf.readDoubleLE(55));
console.log(buf);

输出:

Functions of Buffer.readDoubleLE(int)
internal/buffer.js:72
  throw new ERR_OUT_OF_RANGE(type || 'offset',
  ^

RangeError [ERR_OUT_OF_RANGE]: The value of "offset" is out of range.
It must be >= 0 and <= 0. Received 55
    . . .

注意:以上程序将使用node index.js命令编译运行。

参考: https://nodejs.org/docs/latest-v11.x/api/buffer.html#buffer_buf_readdoublele_offset