📜  Node.js Buffer.buffer 属性

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

Node.js Buffer.buffer 属性

Buffer.buffer属性是buffer模块中Buffer类的内置应用程序接口,用于获取与该buffer对象等价的数组buffer对象。

句法:

const buf.buffer

返回值:该属性返回数组缓冲区的对象。

示例 1:文件名:index.js

Javascript
// Node.js program to demonstrate the
// Buffer.buffer property
  
// Creating a Buffer
const buff = Buffer.from([1, 2, 3, 4, 5]);
  
// Getting the value of array buffer
const value = buff.buffer;
  
// Display the result
console.log("Big Integer :- " + value);


Javascript
// Node.js program to demonstrate the
// Buffer.buffer property
  
// Creating and initializing arraybuffer object
const arrbuff = new ArrayBuffer(16);
  
// Getting buffer object form existing 
// arraybuffer object
const buffer = Buffer.from(arrbuff);
  
// Display the result
if(buffer.buffer === arrbuff)
    console.log("both buffer is equivalent");
else
    console.log("both buffer is not equivalent");


输出:

Big Integer :- [object ArrayBuffer]

示例 2:文件名:index.js

Javascript

// Node.js program to demonstrate the
// Buffer.buffer property
  
// Creating and initializing arraybuffer object
const arrbuff = new ArrayBuffer(16);
  
// Getting buffer object form existing 
// arraybuffer object
const buffer = Buffer.from(arrbuff);
  
// Display the result
if(buffer.buffer === arrbuff)
    console.log("both buffer is equivalent");
else
    console.log("both buffer is not equivalent");

输出:

both buffer is equivalent

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

node index.js

参考: https://nodejs.org/api/buffer.html#buffer_buf_buffer