Buffer.prototype.write encoding fixes

Fixes #690 and some other write method parameter handling.
Do you need to call `tonumber(offset)` to make sure its a number or 0 by default?