Convert to Node.js

The Python version wasn't working out so it has been replaced with a
Node.js implementation. I think it was trying to do some character
encoding changes on a binary string. Anyway, this seems to work.