liveBook · Manning

Chapter 11: Buffers and streams

What you will learn in chapter 11 of Secrets of the JavaScript Ninja, Third Edition

The chapter introduction explains why buffers and streams help JavaScript handle large data efficiently and notes that these APIs are available across modern runtimes.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The chapter introduction explains why buffers and streams help JavaScript handle large data efficiently and notes that these APIs are available across modern runtimes.

Key terms: buffers, raw binary data, primitive types, streams, chunks, RAM, Node.js, Web API, JavaScript runtimes

11.1 Buffers and typed arrays

Introduces buffers as a way to work with raw memory in a language that usually hides low-level details.

Key terms: raw blocks of memory, Node.js, buffer

11.1.1 Using buffers to receive data

The section explains why HTTP request bodies should be received as raw buffers, how incoming chunks can be handled, and why those chunks require care when decoded.

Key terms: Content-Length, Buffer, UTF-8, UTF-16, chunks, async for…of, async iterator, request callbacks, streaming, ArrayBuffer

11.1.2 Accessing buffered bytes with typed arrays

This section explains how typed arrays provide byte-level access to buffers and how they differ from ordinary JavaScript arrays.

Key terms: buffer, typed array, Uint8Array, Node.js Buffer, Array, splice, underlying buffer

11.1.3 Flexible buffer manipulation with DataView

This section explains why DataView is useful for mixed-type buffers and how it reads and writes multi-byte values at specific offsets with predictable byte order.

Key terms: buffer, typed arrays, homogeneous, PNG header, endianness, little-endian, big-endian, DataView, setUint32, getUint32

11.2 Streaming and piping data

This section introduces why streaming is useful and defines a JavaScript stream as a queue of data related to async iterators.

Key terms: streaming, small chunks, Web Workers, stream, queue of data, async iterator

11.2.1 Reading and writing streams

The section explains how to read stream chunks as they arrive, decode text safely across chunk boundaries, and create a ReadableStream that enqueues and closes.

Key terms: for await…of, async iterable, chunk, buffer, UTF-8, TextDecoder, decode(chunk, { stream: true }), toString("utf8"), ReadableStream, start

11.2.2 Piping streams

This section explains how to pipe a readable source through a transform to a writable sink, how chunks flow through that pipeline, and how the pipeline finishes.

Key terms: ReadableStream, TransformStream, WritableStream, source, transform, sink, TextDecoderStream, byte chunks, pipeThrough, 1:1 transformation

11.3 Controlling streams as a consumer

This section explains why a stream consumer may need to control data flow when it cannot process incoming chunks fast enough.

Key terms: consumer, stream, chunks of data, rate of flow

11.3.1 Pull streams

This section explains how pull streams produce data in response to demand, how they compare with push streams, and why buffering and performance still matter.

Key terms: push streams, pull streams, enqueue, consumer, ReadableStream, pull method, for await…of, setTimeout, main thread, push

11.3.2 Controlling buffering with backpressure

This section explains how a stream’s high watermark controls pull-stream buffering, why more buffering can improve throughput, and where backpressure may not be enforced.

Key terms: high watermark, ReadableStream, pull, byte stream, buffering, throughput, sink, source, backpressure, pipes

11.4 Summary

Concepts explained in this chapter

← Chapter 10: Dealing with collections Chapter 12: Wrangling regular expressions →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.