InterviewSolution
| 1. |
Explain buffer concept in Node.js. Do we need to define any module to use buffer class? |
|
Answer» The buffers module provides a way of handling streams of binary data. Nodejs implements Buffer using Buffer class. Typically, the movement of data is done with the purpose of processing it, or read it, and make decisions based on it. But there is a minimum and a maximum amount of data a process could take over time. So if the rate at which the data arrives is faster than the rate at which the process consumes the data, the excess data need to wait somewhere for its turn to be processed. On the other hand, 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. That “waiting area” is the buffer! It is a small physical location in your computer, usually in the RAM, where data are temporally GATHERED, wait, and are eventually sent out for processing during streaming. Example: An example where you can see buffering in action is when you are trying to read an e-book( of size 500 pages with graphics) in google books. If internet is FAST enough, the speed of stream is fast enough to fill up the buffer and SEND out for further processing, then fill another one and send out for processing, till stream is finished. If your internet connection is slow, Google books display a loading icon, which means gathering more data or expecting more data to arrive. When the buffer is filled up and processed, google books show the page. While displaying the page, more data continues to arrive and wait in the buffer. No. Buffer class is part of Global Modules. |
|