Buffer.length属性是缓冲区模块中Buffer类的内置应用程序编程接口,用于获取此缓冲区对象的长度。
用法:
const Buffer.length
参数:此属性不接受任何参数。
返回值:此属性返回此缓冲区对象的长度。
范例1: 文件名:index.js
Javascript
// Node.js program to demonstrate the
// Buffer.length property
// Creating and initializing arraybuffer object
const arrbuff = new ArrayBuffer(16);
// Getting buffer object form existing
// arraybuffer object
const buffer = Buffer.from(arrbuff);
// Getting byteoffset of buffer
// by using byoffset api
const length = buffer.length;
// Display the result
console.log("Length is:" + length);
输出:
Length is:16
范例2: 文件名:index.js
Javascript
// Node.js program to demonstrate the
// Buffer.length property
// Creating and initializing arraybuffer object
const arrbuff = new ArrayBuffer(16);
// Getting buffer object form existing
// arraybuffer object
const buffer = Buffer.from(arrbuff);
// Getting byteoffset of buffer
// by using byoffset api
const length = buffer.length;
// Creating and initializing Int8Array object
const buff = new Int8Array(buffer, buffer.byteoffset, length);
// Display the result
console.log("Int8Arry object:- " + buff);
输出:
Int8Arry object:- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
使用以下命令运行index.js文件:
node index.js
参考:https://nodejs.org/dist/latest-v12.x/docs/api/buffer.html#buffer_buf_length
相关用法
- Node.js GM charcoal()用法及代码示例
- Node.js GM blur()用法及代码示例
- Node.js GM sharpen()用法及代码示例
- Node.js GM drawLine()用法及代码示例
- Node.js GM drawArc()用法及代码示例
- Node.js GM drawPolyline()用法及代码示例
- Node.js GM drawBezier()用法及代码示例
- Node.js GM drawCircle()用法及代码示例
- Node.js GM drawEllipse()用法及代码示例
- Node.js GM drawPolygon()用法及代码示例
- Node.js GM drawRectangle()用法及代码示例
注:本文由纯净天空筛选整理自RohitPrasad3大神的英文原创作品 Node.js Buffer.length Property。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。