Node.js Buffer.writeIntLE() Method (original) (raw)

Last Updated : 13 Oct, 2021

Buffer is a temporary memory storage which stores the data when it is being moved from one place to another. It is like an array of integers. The Buffer.writeIntLE() method writes the byteLength bytes of values to Buffer using Little Endian format to the Buffer object.Syntax:

Buffer.writeIntLE( value, offset, byteLength )

Parameters: This method accept three parameters as mentioned above and described below:

Return Value: It returns an integer value offset plus the number of bytes written.Example 1:

javascript `

// Node program to demonstrate the
// Buffer.readInt16LE() Method

// Allocating buffer from array var buf = Buffer.from('GeeksForGeeks');

buf.writeIntLE('ee', 0, 5);

// Printing allocated buffer console.log(buf);

console.log(buf.toString());

`

Output:

<Buffer 00 00 00 00 00 46 6f 72 47 65 65 6b 73> ForGeeks

Example 2:

javascript `

// Node program to demonstrate the
// Buffer.readInt16LE() Method

// Allocating buffer from array const buf = Buffer.allocUnsafe(4);

buf.writeIntLE(0xabcdef, 0, 4);

// Printing allocated buffer console.log(buf);

`

Output:

<Buffer ef cd ab 00>

Note: The above program will compile and run by using the node index.js command.Reference: https://nodejs.org/api/buffer.html#buffer_buf_writeintle_value_offset_bytelength