Return number of bytes written closes #629