Node.js Buffer.kMaxLength Property
The Buffer.kMaxLength property is an inbuilt application programming interface of class Buffer within buffer module which is used to set and get the maximum length allowed for single buffer instance.
Syntax:
const Buffer.kMaxLength
Parameters: This property works as a getter and setter so it takes integer value as a parameter sometimes.
Return Value: This property return the maximum length allowed for single buffer instance.
Example 1: Filename: 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 from existing // arraybuffer object const buffer = Buffer.from(arrbuff); // Setting the maximum value // into the buffer buffer.kMaxLength = 23; // Getting the maximum length by using // kMaxLength property const value = buffer.kMaxLength; // Display the result console.log( "kMaxLength is: " + value); |
Output:
kMaxLength is: 23
Example 2: Filename: index.js
If kMaxLength is not initialized
Javascript
// Node.js program to demonstrate the // Buffer.kMaxLength property // If kMaxLength is not initialized // Creating and initializing arraybuffer // object const arrbuff = new ArrayBuffer(16); // Getting buffer object from existing // arraybuffer object const buffer = Buffer.from(arrbuff); // Getting the maximum length by using // kMaxLength property const value = buffer.kMaxLength; // Display the result console.log( "kMaxLength is: " + value); |
Output:
kMaxLength is: undefined
Run index.js file using the following command:
node index.js
Reference: https://nodejs.org/dist/latest-v12.x/docs/api/buffer.html#buffer_buffer_kmaxlength
Please Login to comment...