Recently I had to implement an endpoint for an archaic API in Node.js, which required some binary manipulation.
Giving a quick peak at documentation, you will see that binary encoding should be avoided at all costs and is already deprecated, instead you should rely on buffers.
Here goes a really basic and quick example doing the same thing using encoding and then using buffers.
What you should NOT be doing:
stream.write(utils.pack('N', payload.data.length + 4) + payload.data, 'binary', payload.callback);
Instead you should be doing:
var myb = new Buffer(payload.data.length + 4); myb.writeUInt32BE((payload.data.length + 4), 0); myb.write(payload.data, 4); stream.write(myb, payload.callback);
Realize that when you use a buffer in the write method, encoding does not fallback to utf8 by default.