Understanding Buffered Data

Buffered data is made up of a series of octets in big-endian or little-endian format. That means they take up considerably less space than text data. Therefore, Node.js provides the Buffer module, which allows you to create, read, write, and manipulate binary data in a buffer structure. The Buffer module is global, so you do not need to use the require() function to access it.

Buffered data is stored in a structure similar to that of an array, but it is stored outside the normal V8 heap in raw memory allocations. Therefore, a buffer cannot be resized.

When converting buffers to and from strings, you need to specify the explicit encoding method to be used. Table 5.1 lists the various encoding methods supported.

Image

Table 5.1 Methods of encoding between strings and binary buffers


Big Endian and Little Endian

Binary data in buffers is stored as a series of octets or a sequence of eight 0s and 1s that can be a hexadecimal value of 0x00 to 0xFF. It can be read as a single byte or as a word containing multiple bytes. Endian defines the ordering of significant bits when defining the word. Big endian stores the least significant word first, and little endian stores the least significant word last. For example, 0x0A 0x0B 0x0C 0x0D would be stored in the buffer as [0x0A, 0x0B, 0x0C, 0x0D] in big endian but as [0x0D, 0x0C, 0x0B, 0x0A] in little endian.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.192.79