Node.js buffer string serialization

I want to serialize a buffer to string without any overhead ( one character for one byte) and be able to unserialize it into buffer again.

var b = new Buffer (4) ;
var s = b.toString() ;
var b2 = new Buffer (s) 

Produces the same results only for values below 128. I want to use the whole scope of 0-255.

I know I can write it in a loop with String.fromCharCode() in serializing and String.charCodeAt() in deserializing, but I'm looking for some native module implementation if there is any.

You can use the binary encoding, but you should generally try to avoid it because converting a Buffer to a binary string has some extra computational overhead.

Example:

var b = new Buffer(4);
var s = b.toString('binary');
var b2 = new Buffer(s, 'binary');