Skip to content

Instantly share code, notes, and snippets.

@nsfmc
Created March 25, 2014 19:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nsfmc/9769235 to your computer and use it in GitHub Desktop.
Save nsfmc/9769235 to your computer and use it in GitHub Desktop.
am i the only person that wants to be able to do Buffer("foo", "utf16-be")?
/**
* returns a new buffer with toggled endianness
* @param {Buffer} buff a nodeJS buffer, presumably utf16le/ucs2
* @return {Buffer} a nodeJS buffer, probably utf16be
*/
function toggleEndian(buff){
out = []
for (var i = 0; i < buff.length; i+=2) {
out[i] = buff[i + 1];
out[i + 1] = buff[i];
}
return Buffer(out);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment