Buffer.kMaxLength属性是缓冲区模块中Buffer类的内置应用程序编程接口,用于设置和获取单个缓冲区实例允许的最大长度。
用法:
const Buffer.kMaxLength
参数:此属性可以用作获取器和设置器,因此有时会使用整数值作为参数。
返回值:此属性返回单个缓冲区实例允许的最大长度。
范例1: 文件名:index.js
Javascript
// Node.js program to demonstrate the
// Buffer.kMaxLength property
// Creating and initializing arraybuffer object
const arrbuff = new ArrayBuffer(16);
// Getting buffer object form existing
// arraybuffer object
const buffer = Buffer.from(arrbuff);
// Setting the the maximum value
// into the buffer
buffer.kMaxLength = 23;
// Getting the maximum length by using
// kMaxLength property
const value = buffer.kMaxLength;
// Disply the result
console.log("kMaxLength is:" + value);
输出:
kMaxLength is:23
范例2: 文件名:index.js
如果未初始化kMaxLength
Javascript
// Node.js program to demonstrate the
// Buffer.kMaxLength property
// If kMaxLengthis is not initialized
// Creating and initializing arraybuffer
// object
const arrbuff = new ArrayBuffer(16);
// Getting buffer object form existing
// arraybuffer object
const buffer = Buffer.from(arrbuff);
// Getting the maximum length by using
// kMaxLength property
const value = buffer.kMaxLength;
// Disply the result
console.log("kMaxLength is:" + value);
输出:
kMaxLengthis is:undefined
使用以下命令运行index.js文件:
node index.js
参考:https://nodejs.org/dist/latest-v12.x/docs/api/buffer.html#buffer_buffer_kmaxlength
相关用法
- 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.kMaxLength Property。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。