What is buffer in Node.js ?
Buffers in Node.js: The Buffer class in Node.js is used to perform operations on raw binary data. Generally, Buffer refers to the particular memory location in memory. Buffer and array have some similarities, but the difference is array can be any type, and it can be resizable. Buffers only deal with binary data, and it can not be resizable. Each integer in a buffer represents a byte. console.log() function is used to print the Buffer instance.
Methods to perform the operations on Buffer:
|1||Buffer.alloc(size)||It creates a buffer and allocates size to it.|
|2||Buffer.from(initialization)||It initializes the buffer with given data.|
|3||Buffer.write(data)||It writes the data on the buffer.|
|4||toString()||It read data from the buffer and returned it.|
|5||Buffer.isBuffer(object)||It checks whether the object is a buffer or not.|
|6||Buffer.length||It returns the length of the buffer.|
|7||Buffer.copy(buffer,subsection size)||It copies data from one buffer to another.|
|8||Buffer.slice(start, end=buffer.length)||It returns the subsection of data stored in a buffer.|
|9||Buffer.concat([buffer,buffer])||It concatenates two buffers.|
Run the index.js file using the following command:
Happy Learning true 100 ABC Geek Happy Learning With GFG
Please Login to comment...