DEV Community

Vishal Yadav
Vishal Yadav

Posted on

Buffer in node.js

Buffer Stream and binary data in nodejs

  • mechanism for reading or manipulating stream of binary data the buffer class was introduced as part of the Nodejs API to make it possible to interact with ctet stream in the context of things like TCP stream and file system operations
  • The buffer class was introduced as part of the Node.js API to make it possible to manipulate or interact with streams of binary data.

  • if I want to convert the "L" character into the string "L".charCodeAt(0)-->76

  • this can happen because of character sets are already define.

  • One of the definition for character encoding is the UTF-8.

  • this states that character should be encoded in bytes. a byte is set of eight bits

Stream of Data :

  • Stream in Nodejs means that sequence of data being moved from one point to other point over a time. means that you have a huge amount of data to process.
  • if the process is consuming the data faster than it arrives the few data that arrive earlier need to wait for a certain amount of data to arrive before being sent out for processing.
  • and that waiting area is called buffer it is small physical location in your computer , usually in the RAM where data are temporally gathered wait and are eventually sent out for the processing during streaming

  • In whatever the case may be, there is always a waiting place. That is the Buffer to Node.js! Node.js can’t control the speed or time of data arrival, the speed of the stream. It only can decide when it’s time to send out the data. If it’s not yet time, Node.js will put them in the buffer — the “waiting area” — a small location in the RAM, until it’s time to send them out for processing.

Interacting with buffer

Happy Coding

Top comments (0)