Open In App

Node.js Buffer.writeIntLE() Method

Last Updated : 13 Oct, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

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:

  • value: It holds an integer value number which to be written to the Buffer.
  • offset: It holds an integer value i.e. number of bytes to skip before starting to write into the buffer. The value of offset lies 0 <= offset <= buf.length – byteLength.
  • byteLength: It holds the number of bytes to write into the buffer. The value of byteLength lies 0 < byteLength <= 6.

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

Example 1:




// 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:




// 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


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads