Skip to content

Node Buffers: How We Fit So Much Junk Inside That Trunk

Matthew McQuain edited this page Nov 21, 2018 · 1 revision

Node Buffer Overview

  • Buffers are the mechanism for reading or manipulating streams of binary data.
  • Buffer class started as part of the Node.js API as a way to allow us to interact with streams of binary data.
  • The Buffer class is like an array of integers, but corresponds to fixed-sized, raw memory.
  • Buffer class is global in scope.
  • Bit = Binary digIT, and to store of piece of data the computer needs to convert that data to its binary representation of 1s and 0s.

Characters

  • Character Sets: defined rules of what number represents each character, such as Unicode or ASCII.
  • Character Encoding: defined rules of how numbers should be represented in binaries, specifically how many bits to use. Eg: UTF-8.
  • When string data is stored in (or extracted out of) a Buffer, a character encoding needs to be specified.

Stream

  • A stream in Node.js is the sequence of data being moved from one point to another over time.
  • Allows us to have a large amount of data to process, but not have to wait for all of our data to be available to us before we start actually processing it. We break the data down in to smaller chunks.

How 2 Buffer

  • We move data to process, read, and make decisions based on it.
  • There is a min/max amount of data that we can process all at once, and if the data arrives to quickly we need to have it wait somewhere till we can process it. The same can be said for the opposite situation of to much processed to fast.
  • The waiting area **IS **the buffer. An actual physical location in our computer (usually in the RAM).
  • This is what the buffering wheel time out thing on YouTube videos is.
  • We can create our own Buffers.

Clone this wiki locally