The Buffer.writeInt32BE() method is an inbuilt application programming interface of class Buffer within Buffer module which 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. Error is thrown if the value is outside the range of signed 32-bit integer.Integer value is interpreted and written as a two’s complement signed integer.
Buffer.writeInt32BE( value, offset )
Parameters: This method accept two parameters as mentioned above and described below:
value: This parameter holds a 32-bit signed integer that need to be written to the buffer.
offset: This parameter holds an integer value i.e. the number of bytes to skip before starting to write into the buffer. The value of offset lies between 0 to buf.length – 4. It is an optional parameter and its default value is 0.
Return Value: This method returns an integer value i.e. the sum of offset plus the number of bytes written.
Below examples illustrate the use of buf.writeInt32BE() method in Node.js:
<Buffer 7b ca f8 92>
<Buffer 7b ca f9 83 7f ff ff ff>
Example 3: This example will display an error message because the offset is greater than the limit i.e. the offset value does not lies within 0 to buf.length – 4.
internal/buffer.js:72 throw new ERR_OUT_OF_RANGE(type || 'offset', ^ RangeError [ERR_OUT_OF_RANGE]: The value of "offset" is out of range. It must be >= 0 and <= 4. Received 5 . . .