How Buffer and Uint8Array work together
masterThe Buffer constructor returns instances of Uint8Array that have their prototype changed to Buffer.prototype. Because Buffer is a subclass of Uint8Array, the returned instances possess all both Node Buffer methods and standard Uint8Array methods.
Key behaviors:
- Square bracket notation (e.g.,
buf[4]) works and returns a single octet. - The
Uint8Arrayprototype itself remains unmodified. - The implementation is backed by Typed Arrays (
Uint8Array/ArrayBuffer) for high performance.