1.

What are streams?

Answer»

Streams are a way handling following:

  1. reading/ writing files
  2. network communications
  3. any kind of end-to-end information exchange.

It is the movement of data from one point to another.

When a program is supposed to read a FILE consisting of single page(three to four lines), it will be initially read into memory from start to FINISH and then starts processing. If the file is an e-book consisting of 500+ pages , then it takes lot of storage SPACE and TIME to be LOADED into memory, before started processing. This is where Streams make a difference.

Using streams, you read it piece by piece , processing its content without keeping it in memory.

The following are the advantages of streams

  1. Memory Efficiency: You don’t load large amounts data before processing it, It just reads a block of data and process it immediately and continues the same till end of the file.
  2. Time Efficiency: It takes way less time to process the data as soon as you have it without having to wait for whole data to be loaded or available.

The following code statement refer to stream module

const stream = require(‘Stream’);


Discussion

No Comment Found