Buffers
A Buffer is a fixed-size chunk of raw bytes outside V8’s heap. Strings are UTF-16 in
JavaScript; buffers are whatever encoding you choose. Most Node APIs hand you buffers
because that’s what the OS handed Node.
const b = Buffer.from('hello', 'utf8');
b.length; // 5
b.toString(); // 'hello'Streams
A stream is an async iterator over chunks. The four flavors: Readable, Writable,
Duplex, Transform. You read from a Readable, write to a Writable, and pipe
connects them.
import { createReadStream, createWriteStream } from 'node:fs';
createReadStream('in.log').pipe(createWriteStream('out.log'));Backpressure
If the consumer is slow, a naive loop fills memory. Streams solve this: write() returns
false when the internal buffer is full, and you pause the producer until 'drain'.
pipe handles this for you.
Placeholder chapter — full worked examples and benchmarks coming soon.
Comments
Comments are disabled in this environment. Set
PUBLIC_GISCUS_REPO,PUBLIC_GISCUS_REPO_ID, andPUBLIC_GISCUS_CATEGORY_IDto enable.