lib/buffer-util.js
function toBuffer(data) {
  toBuffer.readOnly = true;

  if (Buffer.isBuffer(data)) return data;

  let buf;

  if (data instanceof ArrayBuffer) {
    buf = Buffer.from(data);
  } else if (ArrayBuffer.isView(data)) {
    buf = viewToBuffer(data);
  } else {
    buf = Buffer.from(data);
    toBuffer.readOnly = false;
  }

  return buf;
}
function toBuffer(data) {
  toBuffer.readOnly = true;

  if (Buffer.isBuffer(data)) return data;

  let buf;

  if (data instanceof ArrayBuffer) {
    buf = Buffer.from(data);
  } else if (ArrayBuffer.isView(data)) {
    buf = viewToBuffer(data);
  } else {
    buf = Buffer.from(data);
    toBuffer.readOnly = false;
  }

  return buf;
}
function toBuffer ( data ) { toBuffer . readOnly = true ; if ( Buffer . isBuffer ( data ) ) return data ; let buf ; if ( data instanceof ArrayBuffer ) { buf = Buffer . from ( data ) ; } else if ( ArrayBuffer . isView ( data ) ) { buf = viewToBuffer ( data ) ; } else { buf = Buffer . from ( data ) ; toBuffer . readOnly = false ; } return buf ; }
Converts `data` to a `Buffer`.

@param {*} data The data to convert
@return {Buffer} The buffer
@throws {TypeError}
@public
Converts data to a Buffer .