Convert between JS object and Node.js buffer