Skip to content

Instantly share code, notes, and snippets.

@nuintun
Created February 11, 2017 13:23
Show Gist options
  • Select an option

  • Save nuintun/dd829d8595d2373a31290f35ced580cf to your computer and use it in GitHub Desktop.

Select an option

Save nuintun/dd829d8595d2373a31290f35ced580cf to your computer and use it in GitHub Desktop.
过滤utf8 BOM
/**
 * strip utf-8 BOM
 *
 * @param {any} buffer
 * @returns {Buffer}
 */
function stripBOM(buffer) {
  //EF BB BF 239 187 191
  if (buffer[0] === 0xef && buffer[1] === 0xbb && buffer[2] === 0xbf) {
    buffer = buffer.slice(3);
  }

  return buffer;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment