DEV Community

LG
LG

Posted on • Edited on

2

Node.js fundamentals allegorically

Stream vs. Buffer

Stream is an abstract interface (“abstract” meaning it made for beginner users i.e. relatively easy-to-use) primarily to work with streaming (which means “in-memory”) (session) data rather than in-disk (persistence-like) data .

EXAMPLE : Pipe is an important mechanism connecting two & more processes (streams, processes are mounted onto PCB, RAM by kernel) without storing anything on the disk for persistency [backed up by baeldung] ;

Readable – earth , that generates water ;

Stream (continues in time) FIFO-like Buffer (discrete in time) STACK-like
Example: Constantly running water in your mouth (consumer, writable) in small gulps (chunks) Example: Water as ice cubes, the measured units of water to prevent clogging
How long can you drink without taking a breath (discrete pause of time) Buffer as stream optimization gives discrete pauses between "swallowing" big ice cube chunks (blobs) by one's mouth as a writable (consumable)

NOTE : Stream can be readable, but not mandatory writable – water can be generated, but not consumed;

KEEP IN MIND : Buffer does pack stream in discrete units, giving a measuring feature, that sounds like optimization, however streaming ensures plausibly un-interrupted consumption . Inter-process-communication (IPC) messaging is a real life example of buffering, whereas I/O over Network (e.g. video, audio, or both) is a real life example of streaming .


Refs

  • Node.js fundamentals et al. link

Stay tuned, more is coming shortly !

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

Top comments (0)

AWS GenAI LIVE image

Real challenges. Real solutions. Real talk.

From technical discussions to philosophical debates, AWS and AWS Partners examine the impact and evolution of gen AI.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay