Node.js Buffer.isBuffer() Method
Buffer is a temporary memory storage that stores the data when it is being moved from one place to another. It is like an array of integers.
The Buffer.isBuffer() method checks whether the provided object is a buffer or not.
Syntax:
Buffer.isBuffer( obj )
Parameters: This method accepts a single parameter obj which needs to be checked if it is a buffer or not.
Return Value: This method returns a Boolean Value, true if the object is buffer, otherwise returns false.
Example 1: The below example illustrates the use of Buffer.isBuffer() Method in Node.js:
javascript
const buffer = Buffer.from( 'GeeksForGeeks' );
console.log(Buffer.isBuffer(buffer));
|
Output
true
Example 2: The below example illustrates the use of Buffer.isBuffer() Method in Node.js:
javascript
const buf1 = "GeeksforGeeks" ;
console.log(Buffer.isBuffer(buf1));
const buf2 = new Buffer(4);
for (let i = 0; i < 4; i++) {
buf2[i] = i + 97;
}
console.log(buf2.toString());
console.log(Buffer.isBuffer(buf2));
|
Output:
false
abcd
true
Note: The above program will compile and run by using the node index.js command.
Reference: https://nodejs.org/api/buffer.html#buffer_class_method_buffer_isbuffer_obj
Last Updated :
11 Apr, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...