Search lands in PR-5.1 (Pagefind).

Explanation Intermediate

Chapter 11 Updated

Streams & Buffers

Why Node moves bytes in streams, and what backpressure really is.

  • Full 35m
  • Revision 4m
  • Flow 2m

Buffers

  • Fixed-size bytes outside V8’s heap.
  • Encodings are chosen at read-time: utf8, hex, base64, binary.
  • Buffer.alloc(n) zero-fills; Buffer.allocUnsafe(n) doesn’t — cheaper, dirtier.

Streams at a glance

  • Readable — source (file, socket, process.stdin).
  • Writable — sink (process.stdout, socket, file).
  • Duplex — both.
  • Transform — Duplex where output is a function of input.

Backpressure rule

  • write() returns false when buffered data passes highWaterMark.
  • Pause the producer; resume on 'drain'.
  • pipe + pipeline handle this for you — prefer them over manual write.

If you remember nothing else

Streams move bytes lazily. Backpressure is how you don’t OOM.

Comments

Comments are disabled in this environment. Set PUBLIC_GISCUS_REPO, PUBLIC_GISCUS_REPO_ID, and PUBLIC_GISCUS_CATEGORY_ID to enable.