NodeJS buf.buffer 是 NodeJS Buffer 模块中 Buffer 类的一个属性。此属性将为您提供一个数组缓冲区对象,从中创建的缓冲区将与数组缓冲区相同。
语法
以下是 NodeJS 缓冲区属性的语法 -
Buffer.buffer
例
在此示例中,将创建一个缓冲区并查看 NodeJS Buffer.buffer 的输出。
const buf = Buffer.from('Hello World');
console.log(buf.buffer);
输出
ArrayBuffer {
[Uint8Contents]: <63 6f 6e 73 74 20 62 75 66 20 3d 20 42 75 66 66 65 72 2e 66 72 6f 6d 28 27
48 65 6c 6c 6f 20 57 6f 72 6c 64 27 29 3b 0d 0a 0d 0a 63 6f 6e 73 6f 6c 65 2e 6c 6f 67 28 62 75 66 2e 62 75 66 66 65 72 29 3b 0d 0a 02 00 00 48 65 6c 6c 6f 20 57 6f 72 6c 64 45 48 02 00 00 08 00 00 00 01 00 00 00 08 07 00 00 ... 8092 more bytes>,
byteLength: 8192 }
[Uint8Contents]: <63 6f 6e 73 74 20 62 75 66 20 3d 20 42 75 66 66 65 72 2e 66 72 6f 6d 28 27
48 65 6c 6c 6f 20 57 6f 72 6c 64 27 29 3b 0d 0a 0d 0a 63 6f 6e 73 6f 6c 65 2e 6c 6f 67 28 62 75 66 2e 62 75 66 66 65 72 29 3b 0d 0a 02 00 00 48 65 6c 6c 6f 20 57 6f 72 6c 64 45 48 02 00 00 08 00 00 00 01 00 00 00 08 07 00 00 ... 8092 more bytes>,
byteLength: 8192 }
例
在这个例子中,让我们创建一个数组缓冲区,然后从中创建一个缓冲区。并比较两者。
const arrofbuff = new ArrayBuffer(16);
const buff = Buffer.from(arrofbuff);
if (buff.buffer === arrofbuff) {
console.log("Buffer and array buffer are equivalent");
}
输出
Buffer and array buffer are equivalent