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()returnsfalsewhen buffered data passeshighWaterMark.- Pause the producer; resume on
'drain'. pipe+pipelinehandle this for you — prefer them over manualwrite.
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, andPUBLIC_GISCUS_CATEGORY_IDto enable.