make write() consistently return an Int byte count. fixes #1701