📜  Node.js Buffer.writeBigUInt64LE() 方法

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

Node.js Buffer.writeBigUInt64LE() 方法

Buffer.writeBigUInt64LE() 方法是 Buffer 模块中 Buffer 类的内置应用程序编程接口,用于将 little endian 64 位 Big 整数值写入指定偏移处的分配缓冲区。

句法:

Buffer.writeBigUInt64LE( value, offset )

参数:

  • value:此参数指定要写入缓冲区的大整数值。它应该是一个有效的 64 位小端大整数值。当 value 不是 this 时,行为是未定义的。
  • offset:它指定在写入之前要跳过的字节数,或者只是表示缓冲区中的索引。 offset 的值是0 <= offset <= Buffer.length – 8 。它的默认值为 0。

    返回值:此方法返回一个无符号整数值,它是偏移量和写入字节数的总和。

    以下示例说明了 Node.js 中 Buffer.writeBigUInt64LE() 方法的使用:

    示例 1:
    文件名:index.js

    // Node.js program to demonstrate the
    // buffer.writeBigUInt64LE() method 
    const buf = Buffer.allocUnsafe(8);
      
    // Writing big integer value into buffer
    // by using writeBigUInt64LE() method
    buf.writeBigUInt64LE(0x01030405060708n, 0);
      
    // display the buffer
    console.log(buf);
    

    使用以下命令运行index.js文件:

    node index.js

    输出:

    
    

    示例 2:
    文件名:index.js

    // Node.js program to demonstrate the
    // buffer.writeBigUInt64LE() method 
    const buf = Buffer.allocUnsafe(8);
      
    // writing big integer value into buffer
    // by using writeBigUInt64LE() method
    buf.writeBigUInt64LE(0xaa03040506efffn, 0);
      
    // Display the buffer
    console.log(buf);
    

    使用以下命令运行index.js文件:

    node index.js

    输出:

    
    

    参考: https://nodejs.org/dist/latest-v12.x/docs/api/buffer.html#buffer_buf_writebiguint64le_value_offset