O'Reilly logo

Node.js in Practice by Alex Young and Marc Harter

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 3. Buffers: Working with bits, bytes, and encodings

This chapter covers

  • Introduction to the Buffer data type
  • Changing data encodings
  • Converting binary files to JSON
  • Creating your own binary protocol

JavaScript has historically had subpar binary support. Typically, parsing binary data would involve various tricks with strings to extract the data you want. Not having a good mechanism to work with raw memory in JavaScript was one of the problems Node core developers had to tackle when the project started getting traction. This was mostly for performance reasons. All of the raw memory accumulated in the Buffer data type.

Buffers are raw allocations of the heap, exposed to JavaScript in an array-like manner. They’re exposed globally ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required