code: function toArray(buffer) {
      if(!buffer) buffer = new Buffer(0);
      var view = new Uint8Array(buffer.length);
      for (var i = 0; i < buffer.length; ++i) {
          view[i] = buffer[i];
      }
      return view;
    }
docs: From Buffer to Uint8Array: