Buffer
A Node.js object holding a fixed-length run of raw bytes stored outside the V8 heap; more generally, any memory that holds data on its way somewhere.
In more detail
Buffer is a subclass of Uint8Array, so it works anywhere a typed array does and adds methods such as toString("hex") and Buffer.from(text). Streams also keep internal buffers of chunks waiting to be read or written, limited by highWaterMark.
Related terms
- Uint8Array — A typed array whose elements are single bytes, whole numbers from 0 to 255.
- slab allocator — A memory manager that reserves one large block up front and hands out small pieces of it, avoiding many tiny allocations.
- Buffer.alloc() and Buffer.allocUnsafe() — The two ways to create a new Buffer of a given size: alloc() fills it with zeros, while allocUnsafe() skips that step and may contain old data.
- external memory — Memory that belongs to JavaScript objects but lives outside the V8 heap, such as the bytes inside Buffers and ArrayBuffers.
Taught in
- Node.js Process Architecture: Memory & Heap Spaces — Node.js Internals & Backend Services
- Buffer Fundamentals: Slab Allocator & V8 Memory — Node.js Internals & Backend Services
- Buffer Encodings: UTF-8, Hex, Base64 & Slicing — Node.js Internals & Backend Services
- Binary Data Manipulation: TypedArrays & Endianness — Node.js Internals & Backend Services
- Writable Streams: Drain Events & highWaterMark — Node.js Internals & Backend Services