0% found this document useful (0 votes)
4 views3 pages

Streams and Buffers

Streams are collections of data processed in chunks, suitable for handling large amounts of data that may not fit in memory. There are four types of streams: readable, writable, duplex, and transform, each serving different purposes in data handling. Buffers are used to store and manipulate binary data, essential for processing data transmitted over networks.

Uploaded by

Suresh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Streams and Buffers

Streams are collections of data processed in chunks, suitable for handling large amounts of data that may not fit in memory. There are four types of streams: readable, writable, duplex, and transform, each serving different purposes in data handling. Buffers are used to store and manipulate binary data, essential for processing data transmitted over networks.

Uploaded by

Suresh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Streams:

Streams are collection of data, they wouldn’t be available all at once as they
may not fit into the memory, streams are used when working with the large
amounts of data, we need to process one chunk at a time.
stream-demo.js

Output:

We can also pause the stream & resume, let us use some counters and
timers to do that
Output: You see some more chunks after 3s

Streams 101
There are four types of streams.
1. Readable streams: fs.createReadStream() to read the streams
2. Writable streams: fs.createWriteStream() is to write the streams
3. Duplex streams: Can read and write streams, tcp socket is an example
of Duplex streams
4. Transform streams: When you read & write the streams you want to
modify while reading & writing, example of transform is the
compressing of data streams, like zip files

Buffers
A buffer is way to store and manipulate binary data, usually when the data’s
are passed over the network in the binary form we need Buffer to manipulate
store and manipulate them, it could be binary streams or authorization
headers having base64 data.

You might also like