Dev Helpers

Node.js / Binary buffers

Allocate a filled buffer

Dev Helpers · January 11, 2026

Allocating a filled buffer makes each initial byte predictable. This matters when preparing binary fixtures or constructing headers.

Worked example

import { Buffer } from "node:buffer";
console.log([...Buffer.alloc(4, 0xab)]);

Result

[ 171, 171, 171, 171 ]

Implementation notes

Buffer size counts bytes. A multibyte string used as a fill pattern may be truncated at a byte boundary.

Try it yourself

Inspect zero, a repeated ASCII byte and a value outside one byte's range.

Open the Node.js example →

Editorial date January 11, 2026 · Published December 6, 2026

Related articles

Safely parse malformed input

Parsing user-provided JSON needs a failure path. Successful parsing alone does not establish that the result has the expected shape.

Checksum bytes with CRC32

CRC32 is useful for detecting accidental changes to a byte sequence. Record the input encoding so different producers compute the same checksum.

Attach details to a mark

Performance marks can carry details about the operation they describe. Small stable identifiers are easier to aggregate than large payloads.