Created
March 25, 2014 19:24
-
-
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")?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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