Node.js | Buffer.writeUIntLE() Method
The Buffer.writeUIntLE() method is used to write the specified bytes, using little endian, to a Buffer object. It supports up to 48 bits of accuracy. It’s behavior is undefined when you use the value anything other than unsigned integer.
Buffer.writeUIntLE( value, offset, byteLength )
Parameters: This method accept three parameters as mentioned above and described below:
- value: It specifies the number which need to be written to the Buffer object.
- offset: It specifies the number of bytes to skip before starting to write into the buffer. The value of offset lies 0 <= offset <= buf.length – byteLength.
- byteLength: It specifies the number of bytes to write into the buffer. The value of byteLength lies 0 < byteLength <= 6.
Return value: It returns the offset plus the number of bytes written.
Below examples illustrate the use of Buffer.writeUIntLE() Method in Node.js:
<Buffer 74 74 12 12> <Buffer cd ab 74 74 12 12>
Before filling buffer <Buffer 00 00 00 00 00 00 00 00> After filling 6 bytes <Buffer 12 00 28 67 12 cc 00 00> After filling next 2 bytes <Buffer 12 00 28 67 12 cc 12 11>
Note: The above program will compile and run by using the
node index.js command.