Open In App
Related Articles

Node.js Buffer Complete Reference

Improve Article
Improve
Save Article
Save
Like Article
Like

Buffers are instances of the Buffer class in Node.js. Buffers are designed to handle binary raw data. Buffers allocate raw memory outside the V8 heap. Buffer class is a global class so it can be used without importing the Buffer module in an application.

Example:

Javascript




<script>
    // Node.js program to demonstrate the
    // Buffer.allocUnsafeSlow() Method
          
    // Creating a buffer
    const buffer = Buffer.allocUnsafe(10);
          
    // Display the buffer containing random values
    console.log("allocUnsafeSlow() Method");
    console.log(buffer);
</script>

Output:

allocUnsafeSlow() Method
<Buffer 01 00 00 00 00 00 00 00 8b ed>

The Complete List of Node.js Buffer module methods are listed below:

Node.js Buffer

Description

Node.js Buffer.copy() MethodBuffer is a temporary memory storage which stores the data when it is being moved from one place to another.
Node.js Buffer.includes() MethodThe Buffer.includes() method checks whether the provided value is present or included in the buffer or not.
Nodejs Buffer.compare() MethodBuffer.compare() method compares the two given buffers.
Node.js Buffer.alloc() MethodThe Buffer.alloc() method is used to create a new buffer object of the specified size. 
Node.js Buffer.equals() MethodThe Buffer.equals() method is used to compare two buffer objects and returns
Node.js Buffer.subarray() MethodThe buffer.subarray() method is an inbuilt application programming interface of the buffer module which is used to crop a part of array
Node.js Buffer.readIntBE() MethodThe Buffer.readIntBE() method is used to read the number of bytes for a buffer at a given offset and interprets the result as a two’s complement signed value.
Node.js Buffer.write() MethodThe Buffer.write() method writes the specified string into a buffer, at the specified position.
Node.js Buffer.readIntLE() MethodThe Buffer.readIntLE() method is used to read a number of bytes from a buffer at a given offset and interprets the result as a two’s complement signed value.
Node.js Buffer.readUInt8() MethodThe Buffer.readUInt8() method is used to read an unsigned 8-bit integer from a Buffer object.
Node.js Buffer.indexOf() MethodBuffer is a temporary memory storage that stores the data when it is being moved from one place to another.
Node.js Buffer.allocUnsafeSlow() MethodBuffer is a temporary memory storage that stores the data when it is being moved from one place to another. It’s like the array of integers
Node.js Buffer.writeUInt32BE() MethodThe Buffer.writeUInt32BE() method is used to write a number to an instance of the Buffer class.
Node.js Buffer.readInt32LE() MethodThis is used to read a 32-bit integer from a buffer object at a given offset and returns the result in Little endian.
Node.js Buffer.readFloatLE() MethodThis is used to read a 32-bit float number from the Buffer class with a specified endian format.
Node.js Buffer.writeIntLE() MethodBuffer is a temporary memory storage that stores the data when it is being moved from one place to another.
Node.js Buffer.isEncoding() MethodThe Buffer.isEncoding() method checks whether the given encoding is supported or not.
Node.js Buffer.swap32() MethodThis is an inbuilt application programming interface of class Buffer within the Buffer module which is used to swap the buffer byte order in-place.
Node.js Buffer.readUInt16BE() MethodThis is an inbuilt application programming interface of class Buffer within the Buffer module which is used to read a 16-bit value from an allocated buffer at a specified offset.
Node.js Buffer.writeUInt16LE() MethodThis is used to write specified bytes in Little Endian format to the buffer object. Here, the value should be a valid unsigned 16-bit integer.
Node.js Buffer.readUInt16LE() MethodThis is used to read an unsigned 16-bit integer from the buffer at the specified offset with a specified little-endian format.
Node.js Buffer.writeFloatBE() MethodThis is used to write big endian 32 bits floating point value to an allocated buffer at the specified offset
Node.js Buffer.writeUIntLE() MethodThis is used to write the specified bytes, using little endian, to a Buffer object. It supports up to 48 bits of accuracy.
Node.js Buffer.writeUInt16BE() MethodThe Buffer.writeUInt16BE() method is used to write specified bytes using Big endian format to the buffer object
Node.js Buffer.readUInt32BE() MethodThis is used to read a 32-bit value from an allocated buffer at a specified offset.
Node.js Buffer.writeFloatLE() MethodThe value to the buffer at the specified offset with the specified little-endian format. 
Node.js Buffer.readInt16LE() MethodThis is used to read 16-bit values from an allocated buffer at a specified offset in Little Endian format.
Node.js Buffer.toString() MethodThe Buffer.toString() method is used to decode buffer data to string according to the specified encoding type. 
Node.js Buffer.writeUInt8() MethodThis is used to write values to buffer at the specified offset.
Node.js Buffer.values() MethodThe Buffer.values() Method is used to create a loop or iterating object which contains the value of each byte of buffer instance.
Node.js Buffer.from() MethodThe Buffer.from() method is used to create a new buffer containing the specified string, array or buffer.
Node.js Buffer.writeUIntBE() MethodBuffer.writeUIntBE() method is used to write the specified bytes using big endian format to a Buffer object.
Node.js Buffer.readInt8() MethodThe Buffer.readUInt8() method is used to read an unsigned 8-bit integer from a Buffer from a with the specific offset.
Node.js Buffer.concat() MethodThe Buffer.concat() method is used to concat all buffer objects in a given array into one buffer object.
Node.js Buffer.fill() MethodThe Buffer.fill() Method puts the data into the buffer instance.
Node.js Buffer.readUIntBE() MethodThis is used to read specified number of byte(s) value from an allocated buffer at a specified offset.
Node.js Buffer.swap16() MethodThis is used to swap the buffer byte order in-place. The swapping is performed by interpreting buffer as an array of 16-bit numbers.
Node.js Buffer.writeDoubleBE() MethodThis is used to writes big endian 64-bits double value to an allocated buffer at the specified offset.
Node.js Buffer.writeUInt32LE() MethodThis  is used to write specified bytes using Little endian format to the buffer object.
Node.js Buffer.isBuffer() MethodThe Buffer.isBuffer() method checks whether the provided object is a buffer or not.
Node.js Buffer.keys() MethodThe Buffer.keys() method is used to return an iterator object, containing the key of every byte in a buffer object.
Node.js Buffer.writeInt32LE() MethodThe Buffer.writeInt32LE() method is used to write specified bytes into the buffer using little-endian format
Node.js Buffer.readUInt32LE() MethodThis  is used to read 32-bit value from an allocated buffer at a specified offset in little endian format.
Node.js Buffer.writeIntBE() MethodIt supports upto 48 bits of accuracy. If the value is other then signed integer then its behavior is undefined.
Node.js Buffer.swap64() MethodThe Buffer.swap64() method is an inbuilt application programming interface of class Buffer
Node.js Buffer.writeInt16BE() MethodThis is used to write integer value to buffer at the specified offset with the big-endian format.
Node.js Buffer.readInt16BE() MethodBuffer module which reads a 16-bit signed integer from the buffer at the specified offset in the big endian format.
Node.js Buffer.entries() MethodThe Buffer.entries() method is used to create and return the iterator of [index, byte] pairs from the contents of the buffer.
Node.js Buffer.readDoubleBE() MethodThe Buffer.readDoubleBE() Method in Node.js is used to read a 64-bit double from the buffer at the given offset with the Big Endian format.
Node.js Buffer.writeDoubleLE() MethodBuffer module that writes a value to the buffer at the specified offset with the specified endian format.
Node.js Buffer.writeInt16LE() MethodThis is used to write a valid signed 16-bit integer to buffer at the specified offset with specified little endian format.
Node.js Buffer.poolSize PropertyThe Buffer.poolSize property is an inbuilt application programming interface of class Buffer
Node.js Buffer.readDoubleLE() MethodThis  is used to read a 64-bit double from the buffer at the given offset with Little Endian format.
Node.js Buffer.byteLength() MethodThis is used to return the length in bytes of the specified buffer object.
Node.js Buffer.readFloatBE() MethodThis  is used to read big endian 32 bits floating-point value to an allocated buffer at the specified offset.
Node.js Buffer.writeInt32BE() Method This is used to write integer value to buffer at the specified offset with the big-endian format, integer value should be a valid signed 32-bit integer. 
Node.js Buffer.writeInt8() MethodThis  is used to writes value to an allocated buffer at the specified offset.
Node.js Buffer.readUIntLE() MethodThis is used to read specified number of byte(s) value from an allocated buffer at a specified offset.
Node.js Buffer.toJSON() MethodThe Buffer.toJSON() method returns the buffer in JSON format.
Node.js Buffer.lastIndexOf() MethodThe Buffer.lastIndexOf() Method checks for a given value in the buffer and return its index where it is present.
Node.js Buffer.byteOffset PropertyThe Buffer.byteOffset property is an inbuilt application programming interface of class Buffer
Node.js Buffer.kMaxLength PropertyThe Buffer.kMaxLength property is an inbuilt application programming interface of class Buffer
Node.js Buffer.buffer PropertyThis is used to get the object of array buffer equivalent to this buffer object.
Node.js Buffer.length PropertyThis  is used to get the length of this buffer object.
Node.js Buffer.writeBigInt64BE() MethodThis  is used to writes big endian 64-bits Big integer value to an allocated buffer at the specified offset.
Node.js Buffer.readBigInt64BE() MethodThis is used to read 64-bit Big integer from a buffer object at a given offset and returns the result in Big endian.
Node.js Buffer.readBigUInt64LE() MethodThis  is used to read unsigned 64 bit integer from a buffer object at a given offset and returns the result in Little endian.
Node.js Buffer.writeBigUInt64LE() Method This is used to writes little endian 64-bits Big integer value to an allocated buffer at the specified offset.
Node.js Buffer.writeBigInt64LE() Method This is used to writes little endian 64-bits Big integer value to an allocated buffer at the specified offset.
Node.js Buffer.readBigInt64LE() MethodThis  is used to read 64 bit Big integer from a buffer object at a given offset and returns the result in Little endian.
Node.js Buffer.writeBigUInt64BE() MethodThis is used to writes big endian 64-bits Big integer value to an allocated buffer at the specified offset.
Node.js Buffer.readBigUInt64BE() MethodThis is used to read unsigned 64 bit integer from a buffer object at a given offset and returns the result in Big endian .

Last Updated : 05 Dec, 2022
Like Article
Save Article
Similar Reads
Related Tutorials